jvp
- paddle.incubate.autograd. jvp ( func: Callable[..., _OutputT], xs: Tensor, v: TensorOrTensors | None = None ) tuple[_OutputT, Tensor] [source]
- paddle.incubate.autograd. jvp ( func: Callable[..., _OutputT], xs: Sequence[Tensor], v: TensorOrTensors | None = None ) tuple[_OutputT, tuple[Tensor, ...]]
-
Computes the Jacobian-Vector product for a function at the given inputs and a vector in the tangent space induced by the inputs.
Warning
This API is in beta, the signatures could be changed in future version.
- Parameters
-
func (Callable) – The
functakes as input a Tensor or a Sequence of Tensors and returns a Tensor or a Sequence of Tensors.xs (Tensor|Sequence[Tensor]) – Used as positional arguments to evaluate
func. Thexsis accepted as one Tensor or a Sequence of Tensors.v (Tensor|Sequence[Tensor]|None, Optional) – The tangent vector involved in the JVP computation. The
vmatches the size and shape ofxs. Default value is None and in this case is equivalent to all ones the same size ofxs.
- Returns
-
func_out(Tensor|tuple[Tensor]): The output of
func(xs).jvp(Tensor|tuple[Tensor]): The jvp result.
- Return type
-
output(tuple)
Examples
>>> import paddle >>> def func(x): ... return paddle.matmul(x, x) ... >>> x = paddle.ones(shape=[2, 2], dtype='float32') >>> _, jvp_result = paddle.incubate.autograd.jvp(func, x) >>> print(jvp_result) Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=False, [[4., 4.], [4., 4.]]) >>> v = paddle.to_tensor([[1.0, 0.0], [0.0, 0.0]]) >>> _, jvp_result = paddle.incubate.autograd.jvp(func, x, v) >>> print(jvp_result) Tensor(shape=[2, 2], dtype=float32, place=Place(gpu:0), stop_gradient=False, [[2., 1.], [1., 0.]])
