Hello.
I’m currently working on material behavior using Saint-Venant-Kirchoff (really well explained here 4). My network outputs the displacements.
Here is my problem : How can i get the gradient of the displacement (needed to compute the matrix F in the equations)
I tried several things such as:
here ones is defined by 
ones = torch.ones_like(displacement).to(displacement.device)

displacement.backward(ones)

torch.autograd.grad(displacement, ones)  # Same a above

displacement2 = 1.0 * displacement.clone()  # desperately trying to make it a leaf
displacement2.backward(ones)

and many others failed attemps.
It always raise the same problem. The tensor displacement is not a leaf hence, backward returns None.
My questions here are.
Is there a clean way to compute the gradient ?
How can i force my tensor to be a leaf ?
I’m sure it only a single line of code or just a function call but i didn’t find it in the documentation.
Thank you in advance for your answers.
Alban.