albanD:

This often happens if you modified the weights inplace between the forward and the backward. This would lead to wrong gradients and is not allowed.


Correct me if I understand is wrong. I used back to minimize the loss.



 Lening_Li:

 # compute the loss
                loss = self.entire_l(trajs)
                loss.backward(retain_graph=True)



Then I used forward to get values for other purposes.



 Lening_Li:

                # compute the expectation of h of g
                e_v = self.e_vio(trajs)



Do you mean this is giving me trouble? If it does, can you clarify why it would give me trouble because I did not let optimizer to make a step. Further, can you suggest how would I fix that? Sorry, I am new to Pytorch.