# Changing in place operation

**URL:** <https://discuss.pytorch.org/t/changing-in-place-operation/71903>\
**Category:** autograd\
**Created:** [March 3, 2020, 7:50pm UTC](https://discuss.pytorch.org/t/changing-in-place-operation/71903 "2020-03-03T19:50:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![azeeshan](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/a/b3f665/32.png) [@azeeshan](https://discuss.pytorch.org/u/azeeshan)\
**Post date:** [March 3, 2020, 7:50pm UTC](https://discuss.pytorch.org/t/changing-in-place-operation/71903/1 "2020-03-03T19:50:33Z")

</div>

Hi,

I am getting an error: `RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation: [torch.FloatTensor [1, 5]], which is output 0 of SoftmaxBackward, is at version 1; expected version 0 instead.`

My operation on the tensor of dimensions (1,5) is this:

```auto
probs = net(*input_var)
probs[-1] = 0.
probs = probs/torch.sum(probs)

```

To remove the in place operation, I replaced it with:

```auto
probs = net(*input_var)
probs_new = probs.clone()
probs_new[-1] = 0.
probs_new = probs_new/torch.sum(probs_new)

```

But this still gives the error. What is the correct way to avoid the in place operation?

---

<div class="post-metadata">

**Author:** ![albanD](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/alband/32/215_2.png) [@albanD](https://discuss.pytorch.org/u/albanD)\
**Post date:** [March 3, 2020, 7:53pm UTC](https://discuss.pytorch.org/t/changing-in-place-operation/71903/2 "2020-03-03T19:53:03Z")

</div>

Hi,

Do you get the exact same error? Is it still an output of Softmax?  
maybe something inside your net changes the output of the Softmax inplace before returning it?

---

<div class="post-metadata">

**Author:** ![azeeshan](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/a/b3f665/32.png) [@azeeshan](https://discuss.pytorch.org/u/azeeshan)\
**Post date:** [March 3, 2020, 8:29pm UTC](https://discuss.pytorch.org/t/changing-in-place-operation/71903/3 "2020-03-03T20:29:24Z")

</div>

Seems like I forgot to do the same at one more place that piece of code was used. It works now. Thanks.
