# Why do we need to set the gradients manually to zero in pytorch?

**URL:** <https://discuss.pytorch.org/t/why-do-we-need-to-set-the-gradients-manually-to-zero-in-pytorch/4903>\
**Category:** Uncategorized\
**Created:** [July 14, 2017, 5:31pm UTC](https://discuss.pytorch.org/t/why-do-we-need-to-set-the-gradients-manually-to-zero-in-pytorch/4903 "2017-07-14T17:31:53Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![hughperkins](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/hughperkins/32/915_2.png) [@hughperkins](https://discuss.pytorch.org/u/hughperkins)\
**Post date:** [July 15, 2017, 12:19am UTC](https://discuss.pytorch.org/t/why-do-we-need-to-set-the-gradients-manually-to-zero-in-pytorch/4903/8 "2017-07-15T00:19:02Z")

</div>

(like, it seems like we could have an option in backward to not zero out the gradients, like `backward(preserve_grads=True)`, but by default, seems like zeroing out the gradients could be the default action)

---

_[View the full topic](https://discuss.pytorch.org/t/why-do-we-need-to-set-the-gradients-manually-to-zero-in-pytorch/4903)._
