clone

paddle. clone ( x, name=None ) [source]

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.

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to Name.

Returns: A Tensor copied from input .

Examples

import paddle

x = paddle.ones([2])
x.stop_gradient = False
clone_x = paddle.clone(x)

y = clone_x**3
y.backward()
print(clone_x.grad)          # [3]
print(x.grad)                # [3]