-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Add revert_sync_batchnorm #1253
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1253 +/- ##
==========================================
+ Coverage 68.20% 68.90% +0.69%
==========================================
Files 160 162 +2
Lines 10607 10775 +168
Branches 1938 1978 +40
==========================================
+ Hits 7234 7424 +190
+ Misses 2992 2962 -30
- Partials 381 389 +8
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Please also consider/check/test MMSyncBN |
@ZwwWayne It seems |
So it is also necessary to convert it if it is used in the config for training? |
@ZwwWayne A model with |
It was written a long time ago when PyTorch does not provide SyncBN. It also supports some corner case that currently is not supported in PyTorch. |
@ZwwWayne Do we have any examples using MMSyncBN? |
Simply change the SyncBN in the norm_cfg to MMSyncBN should work |
I suggest implementing a function to simply modify the config to change SyncBN/MMSyncBN back to BN. It works for both SyncBN and MMSyncBN and meets the demands that this PR wants to achieve. It is a little bit late to convert the model back after building SyncBN layer. |
@ZwwWayne Done |
Motivation
A model that uses SyncBN cannot support CPU inference. SyncBN can also cause some other issues during inference. We introduce
revert_sync_batchnorm
from @kapily's work (pytorch/pytorch#41081 (comment)), which can convert SyncBN in any model to BN.Modification
Added
revert_sync_batchnorm
tommcv/cnn/utils/sync_bn.py
and its unittest.BC-breaking (Optional)
No, but there could be a potential minor risk -
PyTorch provides an implementation of convert_sync_batchnorm which converts BatchNorm1D, BatchNorm2D and BatchNorm3D to SyncBatchNorm. However, it doesn't provide an inverse function for that. The reason is SyncBatchNorm neither has a strict input dimension checking nor stores the expected input dimension, whereas BatchNormxD strictly validates the input dimension (and this is the only difference between BatchNorm1D, 2D, and 3D). Therefore, if one converts BNxD to SyncBN using PyTorch's implementation and then converts it back to BN using this implementation, the input dimension check is no longer retained.