From 89696c7bacdabfbcc9351d5e752672522a4d0878 Mon Sep 17 00:00:00 2001 From: gaotingquan Date: Tue, 15 Nov 2022 03:28:34 +0000 Subject: [PATCH] fix error that sync bn should not be used on cpu --- ppcls/arch/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ppcls/arch/__init__.py b/ppcls/arch/__init__.py index 213bef9d..0ce446ca 100644 --- a/ppcls/arch/__init__.py +++ b/ppcls/arch/__init__.py @@ -39,7 +39,11 @@ def build_model(config, mode="train"): mod = importlib.import_module(__name__) arch = getattr(mod, model_type)(**arch_config) if use_sync_bn: - arch = nn.SyncBatchNorm.convert_sync_batchnorm(arch) + if config["Global"]["device"] == "gpu": + arch = nn.SyncBatchNorm.convert_sync_batchnorm(arch) + else: + msg = "SyncBatchNorm can only be used on GPU device. The releated setting has been ignored." + logger.warning(msg) if isinstance(arch, TheseusLayer): prune_model(config, arch) -- GitLab