Vector functions in pytorch to apply autograd to them
If I have a tensor x.
Can I define a vector function, say f(x) = (3x, x+2), and obtain its derivative df/dx?
In a nutshell: I want a way to define such a vector function, from which I can get its gradient.

You can do so using torch.autograd.functional.jacobian, providing the function and input:
&gt;&gt;&gt; jacobian(lambda x: (3*x, x+2), inputs=torch.tensor([3.]))

In this case the result is df/dx = (3, 1) for all x.
