inigo-val:

I think it is because the gradients of the network are being used to calculate the loss functions after they have already been updated.


Yes, this would be most likely the issue. The error might be raised, e.g. if you are using different forward passes, calculate the gradients of one loss w.r.t. the parameters, update the parameters via optimizer.step(), and try to call backward() on the second loss.
Since the parameters were already updated, the gradient calculation would be wrong and thus the error is raised.
Based on your code it seems that L_llike is computed by all three models (enc, dec, disc), so I guess freezing the parameters might not work, if some earlier model might need the gradient calculation.