RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [200]] is at version 2; expected version 1 instead. Hint: enable anomaly detection to find the operation that failed to comput

Hi Mahmoud!

For some suggestions about how to debug such inplace-modification errors,
see this post:

As discussed in the linked post, these backward (retain_graph=True) calls
often cause inplace-modification errors, so you should make a particular point
of looking at them while debugging your issue.

Best.

K. Frank