My answer was applicable in the case of writing a new torch.autograd.Function.
If that’s not your case, you might want to add the retain_graph=True keyword to .backward() in your code.
If you give some more details I’ll be able to give more information.