diff --git a/python/paddle/fluid/dygraph/nn.py b/python/paddle/fluid/dygraph/nn.py index a5d504c79aa1ad6eb57b2a106ef234853df87f9a..7e0209b464a42ab99d0754b239bddafbbcb3276c 100644 --- a/python/paddle/fluid/dygraph/nn.py +++ b/python/paddle/fluid/dygraph/nn.py @@ -936,9 +936,8 @@ class Linear(layers.Layer): def forward(self, input): if in_dygraph_mode(): - pre_bias = core.ops.mul(input, self.weight, 'x_num_col_dims', - len(input.shape) - 1, 'y_num_col_dims', 1) - + pre_bias = core.ops.matmul(input, self.weight, 'transpose_X', False, + 'transpose_Y', False, "alpha", 1) pre_act = dygraph_utils._append_bias_in_dygraph( pre_bias, self.bias, axis=len(input.shape) - 1) @@ -949,14 +948,15 @@ class Linear(layers.Layer): ['float16', 'float32', 'float64'], "Linear") attrs = { - "x_num_col_dims": len(input.shape) - 1, - "y_num_col_dims": 1, + "transpose_X": False, + "transpose_Y": False, + "alpha": 1, } inputs = {"X": [input], "Y": [self.weight]} tmp = self._helper.create_variable_for_type_inference(self._dtype) self._helper.append_op( - type="mul", inputs=inputs, outputs={"Out": tmp}, attrs=attrs) + type="matmul", inputs=inputs, outputs={"Out": tmp}, attrs=attrs) if self.bias: pre_activation = self._helper.create_variable_for_type_inference( dtype=self._dtype)