From 8785537c22c9388ea844ad412c9222ec473decad Mon Sep 17 00:00:00 2001 From: Zhang Zheng <32410583+ZzSean@users.noreply.github.com> Date: Thu, 10 Nov 2022 14:31:42 +0800 Subject: [PATCH] Remove unnecessary operations of GroupNorm in eager mode (#47791) --- python/paddle/nn/layer/norm.py | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/python/paddle/nn/layer/norm.py b/python/paddle/nn/layer/norm.py index b101c5791a..01fd204cab 100644 --- a/python/paddle/nn/layer/norm.py +++ b/python/paddle/nn/layer/norm.py @@ -35,7 +35,6 @@ from ...framework import get_default_dtype from ..initializer import Constant from ...framework import ParamAttr from ...fluid.data_feeder import check_variable_and_dtype -from ...fluid import dygraph_utils from ..functional import batch_norm, layer_norm, instance_norm @@ -413,15 +412,8 @@ class GroupNorm(Layer): ) def forward(self, input): - mean_out = self._helper.create_variable_for_type_inference( - dtype=input.dtype, stop_gradient=True - ) - variance_out = self._helper.create_variable_for_type_inference( - dtype=input.dtype, stop_gradient=True - ) - if in_dygraph_mode(): - pre_act = _C_ops.group_norm( + return _C_ops.group_norm( input, self.weight, self.bias, @@ -430,11 +422,14 @@ class GroupNorm(Layer): self._data_format, ) - return dygraph_utils._append_activation_in_dygraph( - pre_act, act=None - ) + mean_out = self._helper.create_variable_for_type_inference( + dtype=input.dtype, stop_gradient=True + ) + variance_out = self._helper.create_variable_for_type_inference( + dtype=input.dtype, stop_gradient=True + ) - elif _in_legacy_dygraph(): + if _in_legacy_dygraph(): pre_act, _, _ = _legacy_C_ops.group_norm( input, self.weight, @@ -446,9 +441,7 @@ class GroupNorm(Layer): 'groups', self._num_groups, ) - return dygraph_utils._append_activation_in_dygraph( - pre_act, act=None - ) + return pre_act inputs = {'X': input} if self.bias is not None: -- GitLab