Solved by albanD in post #2 
              
              
                Hi, 
The problem is that M is the same during process 1 and 2. You won’t be able to get 2 different behaviors here. 
If would suggest doing two steps (add the corresponding optimizer zero grad and step of course): 
# Process 1 as usual:
P = M(A)
C = some_func(P)

# Now break the graph and get a new …