coballe:

The code runs with
enc_pred = rollout.detach()



You most likely don’t want that as this is the same as not including this part into the loss function!
The error you see does come from an inplace op that is causing issue.
From your code sample, a possible reason is that optimizer.step() modifies the weights inplace. But the original values are needed for the gradient computation, so if you try to backward again, it will fail with this error.