# RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation (Meta Learning)

**URL:** <https://discuss.pytorch.org/t/runtimeerror-one-of-the-variables-needed-for-gradient-computation-has-been-modified-by-an-inplace-operation-meta-learning/161783>\
**Category:** autograd\
**Created:** [September 20, 2022, 11:18am UTC](https://discuss.pytorch.org/t/runtimeerror-one-of-the-variables-needed-for-gradient-computation-has-been-modified-by-an-inplace-operation-meta-learning/161783 "2022-09-20T11:18:22Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![hduc-le](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/hduc-le/32/53370_2.png) [@hduc-le](https://discuss.pytorch.org/u/hduc-le)\
**Post date:** [September 21, 2022, 11:37am UTC](https://discuss.pytorch.org/t/runtimeerror-one-of-the-variables-needed-for-gradient-computation-has-been-modified-by-an-inplace-operation-meta-learning/161783/10 "2022-09-21T11:37:29Z")

</div>

Hi @albanD, I was stuck with this problem for a day. I did a google search and saw your comment at [[Solved][Pytorch1.5] RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation - #2 by albanD](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/2). But in my scenario, it has a little bit different, i.e:  
I need to optimize the model parameters over a few iterations by cross-entropy loss and optimizer `optim1`, and finally, take the sum of those losses computed over the iterations to update the model parameters for the last time with optimizer `optim2`. Unfortunately, my code has an error as in my description above. Hope you help me solve it and I appreciate that. Thank you in advance!

---

_[View the full topic](https://discuss.pytorch.org/t/runtimeerror-one-of-the-variables-needed-for-gradient-computation-has-been-modified-by-an-inplace-operation-meta-learning/161783)._
