Hi,
What most likely happens is that some elements from the first iteration are re-used in the second in a differentiable manner. So when computing gradients, it tries to backward through the first step again leading to the error you see.
You need to make sure that when you save Tensors and gradient should not flow back, you want to save a detached version with .detach().