# Clone and detach in v0.4.0

**URL:** <https://discuss.pytorch.org/t/clone-and-detach-in-v0-4-0/16861>\
**Category:** Uncategorized\
**Created:** [April 24, 2018, 2:20am UTC](https://discuss.pytorch.org/t/clone-and-detach-in-v0-4-0/16861 "2018-04-24T02:20:02Z")\
**Posts on this page:** 1\
**Showing post:** 33

<div class="post-metadata">

**Author:** ![pinocchio](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/pinocchio/32/22093_2.png) [@pinocchio](https://discuss.pytorch.org/u/pinocchio)\
**Post date:** [June 16, 2020, 9:17pm UTC](https://discuss.pytorch.org/t/clone-and-detach-in-v0-4-0/16861/33 "2020-06-16T21:17:35Z")

</div>

> [@albanD](#):
>
> What happens though is that the forward pass needs to save some Tensor values to be able to compute the backward pass. If you modify one of these saved Tensors before running the backward, then in that case, you will get an error. Because the original value was needed to compute the right gradients and it does not exist anymore (was modified inplace).

Yes that is exactly what I expected! So if I have a new intermediate tensor and I try to act on it with any in-place operation that should throw an error, right?

Well I think I found a counter example. It doesn’t hold for `.clone()`:

```auto
def clone_playground():
    import torch

    a = torch.tensor([1,2,3.], requires_grad=True)
    a_clone = a.clone()
    print(f'a is a_clone = {a is a_clone}')
    print(f'a == a_clone = {a == a_clone}')
    print(f'a = {a}')
    print(f'a_clone = {a_clone}')
    #a_clone.fill_(2)
    a_clone.mul_(2)
    print(f'a = {a}')
    print(f'a_clone = {a_clone}')
    a_clone.sum().backward()

```

output:

```auto
a is a_clone = False
a == a_clone = tensor([True, True, True])
a = tensor([1., 2., 3.], requires_grad=True)
a_clone = tensor([1., 2., 3.], grad_fn=<CloneBackward>)
a = tensor([1., 2., 3.], requires_grad=True)
a_clone = tensor([2., 4., 6.], grad_fn=<MulBackward0>)

```

why is `.clone` special? If it’s added to the autograd graph it should be just like any other op.

---

_[View the full topic](https://discuss.pytorch.org/t/clone-and-detach-in-v0-4-0/16861)._
