From f767a3a34014db0ef37a79d6546e2a733eab2136 Mon Sep 17 00:00:00 2001 From: duanyanhui <45005871+YanhuiDua@users.noreply.github.com> Date: Tue, 16 May 2023 16:57:21 +0800 Subject: [PATCH] fix syn_bn for npu (#8247) --- ppdet/engine/trainer.py | 6 ++---- ppdet/modeling/heads/sparsercnn_head.py | 5 ++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ppdet/engine/trainer.py b/ppdet/engine/trainer.py index 0378e00ec..2a2fc766d 100644 --- a/ppdet/engine/trainer.py +++ b/ppdet/engine/trainer.py @@ -429,10 +429,8 @@ class Trainer(object): model = self.model if self.cfg.get('to_static', False): model = apply_to_static(self.cfg, model) - sync_bn = ( - getattr(self.cfg, 'norm_type', None) == 'sync_bn' and - (self.cfg.use_gpu or self.cfg.use_npu or self.cfg.use_mlu) and - self._nranks > 1) + sync_bn = (getattr(self.cfg, 'norm_type', None) == 'sync_bn' and + (self.cfg.use_gpu or self.cfg.use_mlu) and self._nranks > 1) if sync_bn: model = paddle.nn.SyncBatchNorm.convert_sync_batchnorm(model) diff --git a/ppdet/modeling/heads/sparsercnn_head.py b/ppdet/modeling/heads/sparsercnn_head.py index 801ff04fb..0534cf4ad 100644 --- a/ppdet/modeling/heads/sparsercnn_head.py +++ b/ppdet/modeling/heads/sparsercnn_head.py @@ -317,12 +317,15 @@ class SparseRCNNHead(nn.Layer): pooler_scales = [1.0 / 4.0, 1.0 / 8.0, 1.0 / 16.0, 1.0 / 32.0] end_level = 3 + aligned = True + if paddle.device.is_compiled_with_custom_device('npu'): + aligned = False box_pooler = RoIAlign( resolution=pooler_resolution, spatial_scale=pooler_scales, sampling_ratio=sampling_ratio, end_level=end_level, - aligned=True) + aligned=aligned) return box_pooler def forward(self, features, input_whwh): -- GitLab