From 4d0efee4f4d0927a5e1126b0d311a68d1c824d0c Mon Sep 17 00:00:00 2001 From: songyouwei Date: Fri, 10 Apr 2020 16:21:24 +0800 Subject: [PATCH] Linear revert to matmul op (#23654) test=develop --- python/paddle/fluid/dygraph/nn.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/python/paddle/fluid/dygraph/nn.py b/python/paddle/fluid/dygraph/nn.py index a5d504c79a..7e0209b464 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) -- GitLab