torch.autograd.forward_ad.unpack_dual¶
- torch.autograd.forward_ad.unpack_dual(tensor, *, level=None)[source][source]¶
Unpack a “dual tensor” to get both its Tensor value and its forward AD gradient.
The result is a namedtuple
(primal, tangent)
whereprimal
is a view oftensor
’s primal andtangent
istensor
’s tangent as-is. Neither of these tensors can be dual tensor of levellevel
.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.