Solved by albanD in post #2 
              
              
                Hi, 
Is the training loop the one here? 
Given that it happens not at the first backward it can be: 

An optimizer.step() modified a weight that was already used by a forward and you call backward after:

out = model(inp)
opt_model.step() # Modifies the model's weights inplace
out.sum().backward() #…