From ff5fdc0b67a87995340bbdcc3cabab1826aba9de Mon Sep 17 00:00:00 2001 From: Jiabin Yang Date: Wed, 22 May 2019 15:05:33 +0800 Subject: [PATCH] test=develop, fix con2d with no bias (#17516) * test=develop, fix con2d with no bias * test=develop, fix conv_2d with no bias will have null shape --- python/paddle/fluid/dygraph/nn.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/python/paddle/fluid/dygraph/nn.py b/python/paddle/fluid/dygraph/nn.py index 40804015b9c..f02e8b55722 100644 --- a/python/paddle/fluid/dygraph/nn.py +++ b/python/paddle/fluid/dygraph/nn.py @@ -229,15 +229,17 @@ class Conv2D(layers.Layer): 'use_mkldnn': False, }) - pre_act = self._helper.create_variable_for_type_inference( - dtype=self._dtype) - - self._helper.append_op( - type='elementwise_add', - inputs={'X': [pre_bias], - 'Y': [self._bias_param]}, - outputs={'Out': [pre_act]}, - attrs={'axis': 1}) + if self._bias_param is not None: + pre_act = self._helper.create_variable_for_type_inference( + dtype=self._dtype) + self._helper.append_op( + type='elementwise_add', + inputs={'X': [pre_bias], + 'Y': [self._bias_param]}, + outputs={'Out': [pre_act]}, + attrs={'axis': 1}) + else: + pre_act = pre_bias # Currently, we don't support inplace in dygraph mode return self._helper.append_activation(pre_act, act=self._act) -- GitLab