Hello Everyone,
From the documentation of pytorch, I come to understand that torch.autograd.grad(Y, X, G) computes the following:  sum of partial derivative of ‘Y’ wrt ‘X’ multiplied by G.
I would like to do the following instead:
sum of (partial derivative of ‘Y’ wrt ‘X’)^2 multiplied by G.
Is this possible to do in pytorch? Do we have to override the torch.autograd.grad? Or is there another way?
A crude way may be to do torch.autograd.grad(Y[i,j], X, grad_outputs=torch.ones_like(Y[i,j]) ), then square each entry of the this result and multiply with G. But that is too much computationally expensive.