- 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
primalis a view of
tensor’s primal and
tensor’s tangent as-is. Neither of these tensors can be dual tensor of level
This function is backward differentiable.
>>> 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.