diff --git a/ppdet/modeling/heads/gfl_head.py b/ppdet/modeling/heads/gfl_head.py index 9c87eecd81ef8bd0be8bb61db385ef844fcff2ff..aa6dc478ba5a0b9f42fb84768066640d0fc5f0a4 100644 --- a/ppdet/modeling/heads/gfl_head.py +++ b/ppdet/modeling/heads/gfl_head.py @@ -388,12 +388,7 @@ class GFLHead(nn.Layer): avg_factor = sum(avg_factor) try: - avg_factor_clone = avg_factor.clone() - tmp_avg_factor = paddle.distributed.all_reduce(avg_factor_clone) - if tmp_avg_factor is not None: - avg_factor = tmp_avg_factor - else: - avg_factor = avg_factor_clone + paddle.distributed.all_reduce(avg_factor) avg_factor = paddle.clip( avg_factor / paddle.distributed.get_world_size(), min=1) except: diff --git a/ppdet/modeling/heads/simota_head.py b/ppdet/modeling/heads/simota_head.py index 77e515bbc9c2770dd371fec28d3fe9a628b4bd3a..e9a786ede369c23162c64767edae7d37a4cf4e00 100644 --- a/ppdet/modeling/heads/simota_head.py +++ b/ppdet/modeling/heads/simota_head.py @@ -179,15 +179,8 @@ class OTAHead(GFLHead): num_level_anchors) num_total_pos = sum(pos_num_l) try: - cloned_num_total_pos = num_total_pos.clone() - reduced_cloned_num_total_pos = paddle.distributed.all_reduce( - cloned_num_total_pos) - if reduced_cloned_num_total_pos is not None: - num_total_pos = reduced_cloned_num_total_pos / paddle.distributed.get_world_size( - ) - else: - num_total_pos = cloned_num_total_pos / paddle.distributed.get_world_size( - ) + paddle.distributed.all_reduce(num_total_pos) + num_total_pos = num_total_pos / paddle.distributed.get_world_size() except: num_total_pos = max(num_total_pos, 1) @@ -262,12 +255,7 @@ class OTAHead(GFLHead): avg_factor = sum(avg_factor) try: - avg_factor_clone = avg_factor.clone() - tmp_avg_factor = paddle.distributed.all_reduce(avg_factor_clone) - if tmp_avg_factor is not None: - avg_factor = tmp_avg_factor - else: - avg_factor = avg_factor_clone + paddle.distributed.all_reduce(avg_factor) avg_factor = paddle.clip( avg_factor / paddle.distributed.get_world_size(), min=1) except: @@ -408,15 +396,8 @@ class OTAVFLHead(OTAHead): num_level_anchors) num_total_pos = sum(pos_num_l) try: - cloned_num_total_pos = num_total_pos.clone() - reduced_cloned_num_total_pos = paddle.distributed.all_reduce( - cloned_num_total_pos) - if reduced_cloned_num_total_pos is not None: - num_total_pos = reduced_cloned_num_total_pos / paddle.distributed.get_world_size( - ) - else: - num_total_pos = cloned_num_total_pos / paddle.distributed.get_world_size( - ) + paddle.distributed.all_reduce(num_total_pos) + num_total_pos = num_total_pos / paddle.distributed.get_world_size() except: num_total_pos = max(num_total_pos, 1) @@ -494,12 +475,7 @@ class OTAVFLHead(OTAHead): avg_factor = sum(avg_factor) try: - avg_factor_clone = avg_factor.clone() - tmp_avg_factor = paddle.distributed.all_reduce(avg_factor_clone) - if tmp_avg_factor is not None: - avg_factor = tmp_avg_factor - else: - avg_factor = avg_factor_clone + paddle.distributed.all_reduce(avg_factor) avg_factor = paddle.clip( avg_factor / paddle.distributed.get_world_size(), min=1) except: