# Difference between batch\_input and "for loop"

**URL:** <https://discuss.pytorch.org/t/difference-between-batch-input-and-for-loop/18680>\
**Category:** Uncategorized\
**Created:** [May 25, 2018, 2:39pm UTC](https://discuss.pytorch.org/t/difference-between-batch-input-and-for-loop/18680 "2018-05-25T14:39:57Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![ptrblck](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/ptrblck/32/1823_2.png) [@ptrblck](https://discuss.pytorch.org/u/ptrblck)\
**Post date:** [August 8, 2021, 6:25am UTC](https://discuss.pytorch.org/t/difference-between-batch-input-and-for-loop/18680/10 "2021-08-08T06:25:48Z")

</div>

You can add the losses inplace as long as no errors are raised, but would accumulate the computation graphs. [This post](https://discuss.pytorch.org/t/why-do-we-need-to-set-the-gradients-manually-to-zero-in-pytorch/4903/20) explains it in more detail.

The losses wouldn’t be equal, since you are scaling `loss2` by `len(x)` in each iteration.

---

_[View the full topic](https://discuss.pytorch.org/t/difference-between-batch-input-and-for-loop/18680)._
