# Clamping leaf tensor without using .data

**URL:** <https://discuss.pytorch.org/t/clamping-leaf-tensor-without-using-data/97162>\
**Category:** Uncategorized\
**Created:** [September 22, 2020, 7:07pm UTC](https://discuss.pytorch.org/t/clamping-leaf-tensor-without-using-data/97162 "2020-09-22T19:07:54Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![dejanbatanjac](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/d/77aa72/32.png) [@dejanbatanjac](https://discuss.pytorch.org/u/dejanbatanjac)\
**Post date:** [September 22, 2020, 7:27pm UTC](https://discuss.pytorch.org/t/clamping-leaf-tensor-without-using-data/97162/4 "2020-09-22T19:27:06Z")

</div>

I would cite @albanD in here since this is still relevant for PyTorch 4,0 and later.

> [@Clone and detach in v0.4.0](https://discuss.pytorch.org/t/clone-and-detach-in-v0-4-0/16861/21):
>
> Hi, Yes, .detach() gives a new Tensor that is a view of the original one. So any inplace modification of one will affect the other. You should use .clone() if you want a Tensor with the same content backed with new memory. And .detach().clone() if you want a new Tensor backward with new memory and that does not share the autograd history of the original one.

---

_[View the full topic](https://discuss.pytorch.org/t/clamping-leaf-tensor-without-using-data/97162)._
