2 FOR loops, having RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation

Hi, I think I have found the problem. After I use the backward, I use the network’s forward to get some other values.

Which may cause the weights to change (I am not sure). Basically, my steps are the following:

  1. backwork, updates the weights
  2. forward, may change the weights (not sure)
    Is there a way to avoid this?
    Thanks,