Returns a copy of input Tensor. It will always have a Tensor copy. In addition, This function is derivable, so gradients will flow back from the output to input. Parameters: x (Tensor): The input Tensor. Alias: ``input``. name(str|None, optional): For detai
(x: paddle.Tensor, name: str | None = None)
| 3690 | |
| 3691 | @param_one_alias(['x', 'input']) |
| 3692 | def clone(x: paddle.Tensor, name: str | None = None) -> paddle.Tensor: |
| 3693 | """ |
| 3694 | Returns a copy of input Tensor. It will always have a Tensor copy. |
| 3695 | |
| 3696 | In addition, This function is derivable, so gradients will flow back from the output to input. |
| 3697 | |
| 3698 | Parameters: |
| 3699 | x (Tensor): The input Tensor. |
| 3700 | Alias: ``input``. |
| 3701 | name(str|None, optional): For details, please refer to :ref:`api_guide_Name`. Generally, no setting is required. Default: None. |
| 3702 | |
| 3703 | Returns: |
| 3704 | Tensor, A Tensor copied from ``input``. |
| 3705 | |
| 3706 | Examples: |
| 3707 | .. code-block:: pycon |
| 3708 | |
| 3709 | >>> import paddle |
| 3710 | >>> import numpy as np |
| 3711 | |
| 3712 | >>> x = paddle.ones([2]) |
| 3713 | >>> x.stop_gradient = False |
| 3714 | >>> x.retain_grads() |
| 3715 | >>> clone_x = paddle.clone(x) |
| 3716 | >>> clone_x.retain_grads() |
| 3717 | |
| 3718 | >>> y = clone_x**3 |
| 3719 | >>> y.backward() |
| 3720 | >>> print(clone_x.grad.numpy()) # type: ignore |
| 3721 | [3. 3.] |
| 3722 | >>> print(x.grad.numpy()) # type: ignore |
| 3723 | [3. 3.] |
| 3724 | """ |
| 3725 | return x.clone() |
| 3726 | |
| 3727 | |
| 3728 | # NOTE(zhiqiu): not public |
no test coverage detected