pytorch Gradient with respect to 3D input
I want to construct sobolev network for 3D input regression
In TensorFlow, the gradients of neural network model can be computed using tf.gradient like:
dfdx,dfdy,dfdz = tf.gradients(pred,[x,y,z])

Let M be a torch neural network with 5 layers.
If X is a set of (x,y,z)  (3dim data)
and M.forward(X)  is a 1 dim output
How can I compute like gradient of M.forward(X) with respect to X?  Something like:
tf.gradient(M.forward(X),X)


If you want to compute gradient of this function for  example

y_i = 5*(x_i + 1)²
Create tensor of size 2x1 filled with 1's that requires gradient

x = torch.ones(2, requires_grad=True)

Simple linear equation with x tensor created
y = 5 * (x + 1) ** 2

Let take o as multiple dimension equation
o = 1/2 *sum(y_i)
in python
o = (1/2) * torch.sum(y)

you can compute grad with
o.backward()
x.grad

you can get more information here https://www.deeplearningwizard.com/deep_learning/practical_pytorch/pytorch_gradients/
