Hi,
So you have x = \phi(X) and what you want is dx/dX (the derivative of the \phi function).
So using pytorch word, your output is x and the input wrt to which you want the gradient is X.
So the leaf that will get the gradient is X: X = torch.tensor(current_pos, requires_grad=True) where current_pos is a python number, or a numpy array, or anything else.
Then you want to get the output using only pytorch’s ops (otherwise the autograd won’t work): x = phi_func(X).
If you did this right and all ops in your function phi are differentiable, then you should get an output x that requires gradients.
Now You can backward to get the gradient: x.backward() or autograd.grad(x, X).
Note that autograd is doing automatic differentiation and so is computing a vector Jacobian product. So if your output is not scalar, you will need to provide this vector that will be multiplied with the Jacobian.