# 'model.eval()' vs 'with torch.no\_grad()'

**URL:** <https://discuss.pytorch.org/t/model-eval-vs-with-torch-no-grad/19615>\
**Category:** Uncategorized\
**Created:** [June 13, 2018, 8:52am UTC](https://discuss.pytorch.org/t/model-eval-vs-with-torch-no-grad/19615 "2018-06-13T08:52:41Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![michaelklachko](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/michaelklachko/32/541_2.png) [@michaelklachko](https://discuss.pytorch.org/u/michaelklachko)\
**Post date:** [August 16, 2018, 4:07pm UTC](https://discuss.pytorch.org/t/model-eval-vs-with-torch-no-grad/19615/10 "2018-08-16T16:07:15Z")

</div>

So why is torch.no\_grad() is not enabled by default inside model.eval() function? Is there a situation where we want to compute some gradients when in evaluation mode? Even if that’s the case, it seems like no\_grad() method should be made an optional argument to eval(), and set to True by default.

---

_[View the full topic](https://discuss.pytorch.org/t/model-eval-vs-with-torch-no-grad/19615)._
