clone¶
Documentation¶
-
treetensor.torch.
clone
(input, *args, **kwargs)[source]¶ In
treetensor
, you can create a clone of the original tree withtreetensor.torch.clone()
.Examples:
>>> import torch >>> import treetensor.torch as ttorch >>> ttorch.clone(torch.tensor([[1, 2], [3, 4]])) tensor([[1, 2], [3, 4]]) >>> ttorch.clone(ttorch.tensor({ ... 'a': [[1, 2], [3, 4]], ... 'b': {'x': [[5], [6], [7]]}, ... })) <Tensor 0x7f2a820ba5e0> ├── a --> tensor([[1, 2], │ [3, 4]]) └── b --> <Tensor 0x7f2a820aaf70> └── x --> tensor([[5], [6], [7]])
Torch Version Related
This documentation is based on torch.clone in torch v1.9.0+cu102. Its arguments’ arrangements depend on the version of pytorch you installed.
If some arguments listed here are not working properly, please check your pytorch’s version with the following command and find its documentation.
1 | python -c 'import torch;print(torch.__version__)' |
The arguments and keyword arguments supported in torch v1.9.0+cu102 is listed below.
Description From Torch v1.9.0+cu102¶
-
torch.
clone
(input, *, memory_format=torch.preserve_format) → Tensor¶ Returns a copy of
input
.Note
This function is differentiable, so gradients will flow back from the result of this operation to
input
. To create a tensor without an autograd relationship toinput
seedetach()
.- Args:
input (Tensor): the input tensor.
- Keyword args:
- memory_format (
torch.memory_format
, optional): the desired memory format of returned tensor. Default:
torch.preserve_format
.
- memory_format (