# 'shuffle' in dataloader

**URL:** <https://discuss.pytorch.org/t/shuffle-in-dataloader/82335>\
**Category:** vision\
**Created:** [May 21, 2020, 3:28pm UTC](https://discuss.pytorch.org/t/shuffle-in-dataloader/82335 "2020-05-21T15:28:02Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![Nikronic](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/nikronic/32/71873_2.png) [@Nikronic](https://discuss.pytorch.org/u/Nikronic)\
**Post date:** [May 23, 2020, 6:05am UTC](https://discuss.pytorch.org/t/shuffle-in-dataloader/82335/10 "2020-05-23T06:05:35Z")

</div>

You are welcome!  
I do not know definition of your model, but I get you are using `BatchNorm` and maybe `Dropout`. This layers act differently during `eval` and `train` mode. For instance, if `model.train` is used, then mean/variance in `BatchNorm` will be updated even on validation set, for every batch, you will have different parameters for all `BatchNorm` which is not desirable as we looking to update mean/variance in `BatchNorm` only in training step not testing or validation. That is, after training, in validaiton step, each time a different `BatchNorm` is being used which has been updated based on previous batch in validation step. So, overall loss will not be same.

> [@What does model.eval() do for batchnorm layer?](https://discuss.pytorch.org/t/what-does-model-eval-do-for-batchnorm-layer/7146):
>
> Hi Everyone, When doing predictions using a model trained with batchnorm, we should set the model to evaluation model. I have a question that how does the evaluation model affect barchnorm operation? What does evaluation model really do for batchnorm operations? Does the model ignore batchnorm?

> [@'model.eval()' vs 'with torch.no\_grad()'](https://discuss.pytorch.org/t/model-eval-vs-with-torch-no-grad/19615):
>
> When i test my model, do I have to use model.eval() even though I am using 'with torch.no\_grad() ?

bests

---

_[View the full topic](https://discuss.pytorch.org/t/shuffle-in-dataloader/82335)._
