# Model.zero\_grad() or optimizer.zero\_grad()?

**URL:** <https://discuss.pytorch.org/t/model-zero-grad-or-optimizer-zero-grad/28426>\
**Category:** Uncategorized\
**Created:** [October 31, 2018, 8:50am UTC](https://discuss.pytorch.org/t/model-zero-grad-or-optimizer-zero-grad/28426 "2018-10-31T08:50:56Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![ritchieng](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ritchieng/32/7321_2.png) [@ritchieng](https://discuss.pytorch.org/u/ritchieng)\
**Post date:** [October 31, 2018, 9:40am UTC](https://discuss.pytorch.org/t/model-zero-grad-or-optimizer-zero-grad/28426/5 "2018-10-31T09:40:44Z")

</div>

Same; whether you use SGD, Adam, RMSProp etc.

Typically I use `optimizer.zero_grad()`.

---

_[View the full topic](https://discuss.pytorch.org/t/model-zero-grad-or-optimizer-zero-grad/28426)._
