# Exclude a variable from a change through a computation

**URL:** <https://discuss.pytorch.org/t/exclude-a-variable-from-a-change-through-a-computation/55543>\
**Category:** autograd\
**Created:** [September 9, 2019, 1:08pm UTC](https://discuss.pytorch.org/t/exclude-a-variable-from-a-change-through-a-computation/55543 "2019-09-09T13:08:21Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![JanoschMenke](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/janoschmenke/32/15781_2.png) [@JanoschMenke](https://discuss.pytorch.org/u/JanoschMenke)\
**Post date:** [September 9, 2019, 2:20pm UTC](https://discuss.pytorch.org/t/exclude-a-variable-from-a-change-through-a-computation/55543/4 "2019-09-09T14:20:01Z")

</div>

Hi, thanks for the quick reply. It worked! yey.

However, I dont understand why.

In this post  
the difference between clone and detach is explained as follows:

> [@Clone and detach in v0.4.0](https://discuss.pytorch.org/t/clone-and-detach-in-v0-4-0/16861/2):
>
> We’ll provide a migration guide when 0.4.0 is officially released. Here are the answers to your questions: tensor.detach() creates a tensor that shares storage with tensor that does not require grad. tensor.clone()creates a copy of tensor that imitates the original tensor's requires\_grad field. You should use detach() when attempting to remove a tensor from a computation graph, and clone as a way to copy the tensor while still keeping the copy as a part of the computation graph it came from. …

> You should use `detach()` when attempting to remove a tensor from a computation graph, and `clone` as a way to copy the tensor while still keeping the copy as a part of the computation graph it came from.

Maybe I am confusing the computatoinal graph and the memory adress. In my case I would like to remoe the `grads` object form my graph or not?

---

_[View the full topic](https://discuss.pytorch.org/t/exclude-a-variable-from-a-change-through-a-computation/55543)._
