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) – For details, please refer to Name. Generally, no setting is required. Default: None.

Returns

Tensor, 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]