From a5fd888d8614cf66b3c43edc6c4c75d85ca646ae Mon Sep 17 00:00:00 2001 From: Jiahao Zhang Date: Mon, 31 Aug 2026 00:17:45 +0800 Subject: [PATCH 1/5] Fix SyncBatchNorm training state --- mmengine/model/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/mmengine/model/utils.py b/mmengine/model/utils.py index c78ea3134d..59a4f47841 100644 --- a/mmengine/model/utils.py +++ b/mmengine/model/utils.py @@ -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(): From bfb3e4707b14ac4827b11cec0076b50d53fec71a Mon Sep 17 00:00:00 2001 From: Jiahao Zhang Date: Mon, 31 Aug 2026 00:17:55 +0800 Subject: [PATCH 2/5] Test SyncBatchNorm training state --- .../test_convert_sync_batchnorm_training.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 tests/test_model/test_convert_sync_batchnorm_training.py diff --git a/tests/test_model/test_convert_sync_batchnorm_training.py b/tests/test_model/test_convert_sync_batchnorm_training.py new file mode 100644 index 0000000000..ba806bc97c --- /dev/null +++ b/tests/test_model/test_convert_sync_batchnorm_training.py @@ -0,0 +1,13 @@ +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 sync_bn.training is False From f6eaad16a4d6cdab767f60c304197d3fb43a2299 Mon Sep 17 00:00:00 2001 From: Marchematics Date: Tue, 1 Sep 2026 04:09:15 +0800 Subject: [PATCH 3/5] Fix duplicate mock in checkpoint test Signed-off-by: Marchematics --- tests/test_hooks/test_checkpoint_hook.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_hooks/test_checkpoint_hook.py b/tests/test_hooks/test_checkpoint_hook.py index 13914341f7..b078a25fcb 100644 --- a/tests/test_hooks/test_checkpoint_hook.py +++ b/tests/test_hooks/test_checkpoint_hook.py @@ -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, \ From fc2e73ecf6c0bdabd7c8b902a2472743a43b8063 Mon Sep 17 00:00:00 2001 From: Jiahao Zhang Date: Mon, 31 Aug 2026 03:17:43 +0800 Subject: [PATCH 4/5] Fix test license header --- tests/test_model/test_convert_sync_batchnorm_training.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_model/test_convert_sync_batchnorm_training.py b/tests/test_model/test_convert_sync_batchnorm_training.py index ba806bc97c..7c16322f2a 100644 --- a/tests/test_model/test_convert_sync_batchnorm_training.py +++ b/tests/test_model/test_convert_sync_batchnorm_training.py @@ -1,3 +1,4 @@ +# Copyright (c) OpenMMLab. All rights reserved. import torch.nn as nn from mmengine.model import convert_sync_batchnorm From 8b1dbfb1a2fe1485483b957bb34c9549b860ebf3 Mon Sep 17 00:00:00 2001 From: Jiahao Zhang Date: Mon, 31 Aug 2026 11:07:23 +0800 Subject: [PATCH 5/5] Fix lint --- tests/test_model/test_convert_sync_batchnorm_training.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_model/test_convert_sync_batchnorm_training.py b/tests/test_model/test_convert_sync_batchnorm_training.py index 7c16322f2a..ef7fbf16c0 100644 --- a/tests/test_model/test_convert_sync_batchnorm_training.py +++ b/tests/test_model/test_convert_sync_batchnorm_training.py @@ -11,4 +11,4 @@ def test_convert_sync_batchnorm_keeps_training_state(): sync_bn = convert_sync_batchnorm(bn) assert isinstance(sync_bn, nn.SyncBatchNorm) - assert sync_bn.training is False + assert not sync_bn.training