"different", "same", "error". Default: "error"
Returns:
      Returns a function that takes in the same inputs as "func" and
      returns the Jacobian of "func" with respect to the arg(s) at
      "argnums". If "has_aux is True", then the returned function
      instead returns a "(jacobian, aux)" tuple where "jacobian" is
      the Jacobian and "aux" is auxiliary objects returned by "func".
Note:
 You may see this API error out with "forward-mode AD not
 implemented for operator X". If so, please file a bug report and
 we will prioritize it. An alternative is to use "jacrev()", which
 has better operator coverage.

A basic usage with a pointwise, unary operation will give a
   diagonal array as the Jacobian



from torch.func import jacfwd
x = torch.randn(5)
jacobian = jacfwd(torch.sin)(x)
expected = torch.diag(torch.cos(x))
assert torch.allclose(jacobian, expected)



"jacfwd()" can be composed with vmap to produce batched Jacobians: