The problem is that in your loop, precisions (and other) are both used and written to.
This means that the next iteration depends on the operations from the previous iteration (and thus all the ones before).
If you only want backprop to compute gradients for the current iteration, you want to do something similar to what we do in rnn: At the beginning of each iteration, .detach() all the things that happen to have gradients from previous iterations but shouldn’t. In your case, the 4 lines you have above, at the beginning of each iteration.