From 33abfbe6da4cc4fb50a14c56398317c2f3590606 Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Fri, 8 Apr 2022 18:01:45 +0800 Subject: [PATCH] [Eager] Remove elementwise add in conv (#41515) * remove elementwise add in conv * use reshape --- python/paddle/nn/functional/conv.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/python/paddle/nn/functional/conv.py b/python/paddle/nn/functional/conv.py index 086ae789194..84aadbbac64 100644 --- a/python/paddle/nn/functional/conv.py +++ b/python/paddle/nn/functional/conv.py @@ -127,8 +127,12 @@ def _conv_nd(x, x, weight, stride, padding, padding_algorithm, groups, dilation, data_format, False, -1, False) if bias is not None: - out = nn.elementwise_add(pre_bias, bias, axis=channel_dim) - return out + channel_dim = channel_dim + len( + x.shape) if channel_dim < 0 else channel_dim + tmp_bias = _C_ops.final_state_reshape( + bias, bias.shape + + [1 for i in range(len(x.shape) - channel_dim - 1)]) + return _C_ops.final_state_add(pre_bias, tmp_bias) else: return pre_bias if in_dynamic_mode(): -- GitLab