Hi,
You can check the release note for 1.5. In particular the part about fixing the inplace detection code for the optimizer.step() functions for the builtin optimizers.
The issue you have is that the optimizer.step() modifies the weights inplace. But if these weights are needed to compute the backward later, you’ll see the error you see right now.
I am not sure why you do the optimizer.step() at the beginning of the loop in your code, but you should move it to just after the backward if possible. (or at least not between the forward and the backward).