[pytorch1.10.0]one of the variables needed for gradient computation has been modified by an inplace operation

Don’t worry about your behavior as it’s perfectly fine. I would still like to request a smaller code snippet which I could directly copy/paste to my environment to debug the issue, which would save some time.

Generally, you should make sure that explicit inplace operations are not used anymore. If these were already removed, try to add a .clone() call to intermediate tensors to narrow down which operation manipulates the tensors inplace.
Also, take a look at this post which might be helpful, but might also be unrelated to your issue.