Hi,
Why are you using a custom Function here?
If you just want the autograd to compute the gradients for you, just put that in a regular python function.
You should only use a custom Function if you use code that is not handled by the autograd or you want something that is not the gradient.