# How does batch normalization work with multiple GPUs

**URL:** <https://discuss.pytorch.org/t/how-does-batch-normalization-work-with-multiple-gpus/10366>\
**Category:** Uncategorized\
**Created:** [November 25, 2017, 12:01am UTC](https://discuss.pytorch.org/t/how-does-batch-normalization-work-with-multiple-gpus/10366 "2017-11-25T00:01:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![weedwind](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/weedwind/32/2384_2.png) [@weedwind](https://discuss.pytorch.org/u/weedwind)\
**Post date:** [November 25, 2017, 12:01am UTC](https://discuss.pytorch.org/t/how-does-batch-normalization-work-with-multiple-gpus/10366/1 "2017-11-25T00:01:01Z")

</div>

I am going to use 2 GPUs to do data parallel training, and the model has batch normalization. I am wondering how pytorch handle BN with 2 GPUs. Does each GPU estimate the mean and variance separately? Suppose at test time, I will only use one GPU, then which mean and variance will pytorch use?

---

<div class="post-metadata">

**Author:** ![Mata\_Fu](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/mata_fu/32/9814_2.png) [@Mata\_Fu](https://discuss.pytorch.org/u/Mata_Fu)\
**Post date:** [October 1, 2018, 12:04pm UTC](https://discuss.pytorch.org/t/how-does-batch-normalization-work-with-multiple-gpus/10366/2 "2018-10-01T12:04:41Z")

</div>

Do you have the answer right now?

---

<div class="post-metadata">

**Author:** ![Andrew\_Paint](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/andrew_paint/32/13989_2.png) [@Andrew\_Paint](https://discuss.pytorch.org/u/Andrew_Paint)\
**Post date:** [August 27, 2019, 10:14am UTC](https://discuss.pytorch.org/t/how-does-batch-normalization-work-with-multiple-gpus/10366/3 "2019-08-27T10:14:03Z")

</div>

According to the document of PyTorch, the batch norm performs over mini-batch, namely, per GPU

---

<div class="post-metadata">

**Author:** ![liyz15](https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/liyz15/32/15232_2.png) [@liyz15](https://discuss.pytorch.org/u/liyz15)\
**Post date:** [August 27, 2019, 1:39pm UTC](https://discuss.pytorch.org/t/how-does-batch-normalization-work-with-multiple-gpus/10366/4 "2019-08-27T13:39:51Z")

</div>

See [https://pytorch.org/docs/stable/nn.html#torch.nn.SyncBatchNorm](https://pytorch.org/docs/stable/nn.html#torch.nn.SyncBatchNorm), with DistributedDataParallel and SyncBatchNorm then BN can be performed on multiple GPUs.
