Vector functions in pytorch to apply autograd to them
Solution 1:
You can do so using torch.autograd.functional.jacobian
, providing the function and input:
>>> jacobian(lambda x: (3*x, x+2), inputs=torch.tensor([3.]))
In this case the result is df/dx = (3, 1)
for all x
.