Table of Contents
Shortcuts

# torch.autograd.forward_ad.make_dual

torch.autograd.forward_ad.make_dual(tensor, tangent, *, level=None)

  Associates a tensor value with a forward gradient, the tangent, to create a “dual tensor”, which is used to compute forward AD gradients. The result is a new tensor aliased to `tensor` with `tangent` embedded as an attribute as-is if it has the same storage layout or copied otherwise. The tangent attribute can be recovered with `unpack_dual()`.

  This function is backward differentiable.

  Given a function f whose jacobian is J, it allows one to compute the Jacobian-vector product (jvp) between J and a given vector v as follows.

  Example:

      >>> with dual_level():
      ...     inp = make_dual(x, v)
      ...     out = f(inp)
      ...     y, jvp = unpack_dual(out)

  Please see the forward-mode AD tutorial for detailed steps on how to use this API.

## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

## Resources

Find development resources and get your questions answered

View Resources

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.