I’m not sure how your use case works exactly, but



 Haozhi:

However, this will cost error because computational graph is destroyed when backward is called.


to keep the computation graph (and the intermediate tensors) alive, you could use backward(retain_graph=True).