# How to change SyncBatchNorm

**URL:** <https://discuss.pytorch.org/t/how-to-change-syncbatchnorm/100842>\
**Category:** Uncategorized\
**Created:** [October 28, 2020, 2:07am UTC](https://discuss.pytorch.org/t/how-to-change-syncbatchnorm/100842 "2020-10-28T02:07:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mr.Crab](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/m/ba9def/32.png) [@Mr.Crab](https://discuss.pytorch.org/u/Mr.Crab)\
**Post date:** [October 28, 2020, 2:07am UTC](https://discuss.pytorch.org/t/how-to-change-syncbatchnorm/100842/1 "2020-10-28T02:07:15Z")

</div>

i want to try the model on windows which is not supported to the distrubution. And i change the  
`net = torch.nn.SyncBatchNorm.convert_sync_batchnorm(net)` into  
`net = torch.nn.BatchNorm2d(net)`  
but i got a error which is “TypeError: new(): data must be a sequence (got DeepV3PlusHANet)”.  
And what should i do to run the code on windows, and how to change SyncBatchNorm with BatchNorm2d?

---

<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:** [October 28, 2020, 10:56am UTC](https://discuss.pytorch.org/t/how-to-change-syncbatchnorm/100842/2 "2020-10-28T10:56:42Z")

</div>

If you don’t want to use `SyncBatchNorm` you could just remove the `convert_sync_batchnorm` call and keep the original `nn.BatchNorm*D` layers.  
From the [docs](https://pytorch.org/docs/stable/generated/torch.nn.SyncBatchNorm.html?highlight=syncbatchnorm#torch.nn.SyncBatchNorm):

> Helper function to convert all `BatchNorm*D` layers in the model to [`torch.nn.SyncBatchNorm`](https://pytorch.org/docs/stable/generated/torch.nn.SyncBatchNorm.html?highlight=syncbatchnorm#torch.nn.SyncBatchNorm) layers.

---

<div class="post-metadata">

**Author:** ![Mr.Crab](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/m/ba9def/32.png) [@Mr.Crab](https://discuss.pytorch.org/u/Mr.Crab)\
**Post date:** [October 28, 2020, 12:03pm UTC](https://discuss.pytorch.org/t/how-to-change-syncbatchnorm/100842/3 "2020-10-28T12:03:52Z")

</div>

did i need to remove other code?  
can SyncBatchNorm can replace the BatchNorm2D?

---

<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:** [October 28, 2020, 10:13pm UTC](https://discuss.pytorch.org/t/how-to-change-syncbatchnorm/100842/4 "2020-10-28T22:13:33Z")

</div>

If you see other usages of any `SyncBatchNorm` calls, I would remove them as well.  
Yes, `convert_sync_batchnorm` converts the `nn.BatchNorm*D` layers to their sync-equivalent.  
If you don’t want to use this, just keep the model as it is without calling any `SyncBatchNorm` functions and it will use the standard `nn.BatchNorm*D` layers.

---

<div class="post-metadata">

**Author:** ![Mr.Crab](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/m/ba9def/32.png) [@Mr.Crab](https://discuss.pytorch.org/u/Mr.Crab)\
**Post date:** [October 29, 2020, 12:54am UTC](https://discuss.pytorch.org/t/how-to-change-syncbatchnorm/100842/5 "2020-10-29T00:54:20Z")

</div>

it sitll don’t work, i got the same error after removing the convert\_sync\_batchnorm.

---

<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:** [October 29, 2020, 1:36am UTC](https://discuss.pytorch.org/t/how-to-change-syncbatchnorm/100842/6 "2020-10-29T01:36:54Z")

</div>

Could you post an executable code snippet, so that we could have a look at this error?

---

<div class="post-metadata">

**Author:** ![Mr.Crab](https://discuss.pytorch.org/letter_avatar_proxy/v4/letter/m/ba9def/32.png) [@Mr.Crab](https://discuss.pytorch.org/u/Mr.Crab)\
**Post date:** [October 29, 2020, 1:52am UTC](https://discuss.pytorch.org/t/how-to-change-syncbatchnorm/100842/7 "2020-10-29T01:52:11Z")

</div>

Sorry the code is complex and i couldn’t give you a code snippet. You can get the rar file from this [https://drive.google.com/file/d/1biA7CJnPibJAKS7Liw60JPuKFqpV9il8/view?usp=sharing](https://drive.google.com/file/d/1biA7CJnPibJAKS7Liw60JPuKFqpV9il8/view?usp=sharing), just run the train.py and may be you can get this error.  
i use windows 10 and pytorch 1.4.0. Thank you so much.

---

<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:** [October 29, 2020, 6:46am UTC](https://discuss.pytorch.org/t/how-to-change-syncbatchnorm/100842/8 "2020-10-29T06:46:07Z")

</div>

Could you try to slim down the code and post it here, please?  
Alternatively, could you create a gist on GitHub and post the link here?
