# 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:** 12

<div class="post-metadata">

**Author:** ![soulitzer](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/s/839c29/32.png) [@soulitzer](https://discuss.pytorch.org/u/soulitzer)\
**Post date:** [October 1, 2022, 5:05am 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/12 "2022-10-01T05:05:30Z")

</div>

Hi @hduc-le, there is a new context manager [allow\_mutation\_on\_saved\_mode.py · GitHub](https://gist.github.com/soulitzer/91fd975b60b90209aab9c7be634312dc) is designed to get rid of these “variables needed for gradient computation has been modified” errors. I have tried it on your colab and it no longer runs into the error. Let me know how it works for you.

The usage is

```auto
with allow_mutation_on_saved_tensors():
  # all the code in your training loop
  ...

```

---

_[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)._
