Table of Contents
Shortcuts

# torch.autograd.forward_ad.unpack_dual

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

  Unpacks a “dual tensor” to get both its Tensor value and its forward AD gradient. The result is a namedtuple `(primal, tangent)` where `primal` is a view of `tensor`’s primal and `tangent` is `tensor`’s tangent as-is. Neither of these tensors can be dual tensor of level `level`.

  This function is backward differentiable.

  Example:

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

  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.