# Inplace operation Error for simple addition and Subtraction operations

**URL:** <https://discuss.pytorch.org/t/inplace-operation-error-for-simple-addition-and-subtraction-operations/149962>\
**Category:** autograd\
**Created:** [April 24, 2022, 8:12pm UTC](https://discuss.pytorch.org/t/inplace-operation-error-for-simple-addition-and-subtraction-operations/149962 "2022-04-24T20:12:27Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Zheng\_An\_Zhu](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/zheng_an_zhu/32/48727_2.png) [@Zheng\_An\_Zhu](https://discuss.pytorch.org/u/Zheng_An_Zhu)\
**Post date:** [April 26, 2022, 8:57am UTC](https://discuss.pytorch.org/t/inplace-operation-error-for-simple-addition-and-subtraction-operations/149962/3 "2022-04-26T08:57:39Z")

</div>

I add a copy model to deal with `p_scores` forward process and it works to me in your two layers network.  
I have no idea about why original code works in single fc layer, sorry.

New version (related by [here](https://discuss.pytorch.org/t/solved-pytorch1-5-runtimeerror-one-of-the-variables-needed-for-gradient-computation-has-been-modified-by-an-inplace-operation/90256/22)):

```auto
mlp_new = deepcopy(mlp)
p_scores=mlp_new.forward(pbag[0])

```

---

_[View the full topic](https://discuss.pytorch.org/t/inplace-operation-error-for-simple-addition-and-subtraction-operations/149962)._
