# Why is "accumulating" the default mode of .gradient?

**URL:** <https://discuss.pytorch.org/t/why-is-accumulating-the-default-mode-of-gradient/21967>\
**Category:** autograd\
**Created:** [July 30, 2018, 3:59am UTC](https://discuss.pytorch.org/t/why-is-accumulating-the-default-mode-of-gradient/21967 "2018-07-30T03:59:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aerinykim](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/aerinykim/32/5158_2.png) [@aerinykim](https://discuss.pytorch.org/u/aerinykim)\
**Post date:** [July 30, 2018, 3:59am UTC](https://discuss.pytorch.org/t/why-is-accumulating-the-default-mode-of-gradient/21967/1 "2018-07-30T03:59:21Z")

</div>

Why didn’t you guys just make it overwrite? Is there any specific reason for that?

---

<div class="post-metadata">

**Author:** ![John\_Smith](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/j/d78d45/32.png) [@John\_Smith](https://discuss.pytorch.org/u/John_Smith)\
**Post date:** [July 30, 2018, 6:16am UTC](https://discuss.pytorch.org/t/why-is-accumulating-the-default-mode-of-gradient/21967/2 "2018-07-30T06:16:15Z")

</div>

One possible reason I can think of is one variable may contribute to multiple losses and in the backward pass, the gradients should be accumulated from all losses.

---

<div class="post-metadata">

**Author:** ![viraat](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/viraat/32/5861_2.png) [@viraat](https://discuss.pytorch.org/u/viraat)\
**Post date:** [July 30, 2018, 10:02am UTC](https://discuss.pytorch.org/t/why-is-accumulating-the-default-mode-of-gradient/21967/3 "2018-07-30T10:02:16Z")

</div>

Hi Aerin! Nice to see you here 🙂

I found this post with an answer by @albanD - [Why do we need to set the gradients manually to zero in pytorch?](https://discuss.pytorch.org/t/why-do-we-need-to-set-the-gradients-manually-to-zero-in-pytorch/4903/9?u=viraat)  
It explains the decision to accumulate gradients when `.backward()` is performed. I assume the same argument applies for `.gradient()`.
