Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mmengine/model/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def convert_sync_batchnorm(module: nn.Module,
module_output.running_mean = module.running_mean
module_output.running_var = module.running_var
module_output.num_batches_tracked = module.num_batches_tracked
module_output.training = module.training
if hasattr(module, 'qconfig'):
module_output.qconfig = module.qconfig
for name, child in module.named_children():
Expand Down
1 change: 0 additions & 1 deletion tests/test_hooks/test_checkpoint_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ def test_after_val_epoch(self):
petrel_client = MagicMock()
for by_epoch, cfg in [(True, self.epoch_based_cfg),
(False, self.iter_based_cfg)]:
isfile = MagicMock(return_value=True)
self.clear_work_dir()
with patch.dict(sys.modules, {'petrel_client': petrel_client}), \
patch('mmengine.fileio.backends.PetrelBackend.put') as put_mock, \
Expand Down
14 changes: 14 additions & 0 deletions tests/test_model/test_convert_sync_batchnorm_training.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) OpenMMLab. All rights reserved.
import torch.nn as nn

from mmengine.model import convert_sync_batchnorm


def test_convert_sync_batchnorm_keeps_training_state():
bn = nn.BatchNorm2d(4)
bn.eval()

sync_bn = convert_sync_batchnorm(bn)

assert isinstance(sync_bn, nn.SyncBatchNorm)
assert not sync_bn.training