Trying to update parameters in a loop gives following error: One of the variables needed for gradient computation has been modified by an inplace operation

I’m not familiar with your use case and don’t know how all tensors are calculated.
However, based on the error I guess you might be updating the parameters and trying to reuse an already “stale” forward activation as described in this post.