Solved by lucasegidio1 in post #2 
              
              
                I did some research and it seems that 
f, = torch.autograd.grad(e, c, retain_graph=True)

does the job! Sorry, I’m new in pytorch.