未验证 提交 0aee4300 编写于 作者: S songyouwei 提交者: GitHub

Linear use mul op (#22662)

* Linear use mul op
test=develop

* fix unittest
test=develop
上级 df144e21
......@@ -923,14 +923,13 @@ class Linear(layers.Layer):
def forward(self, input):
attrs = {
"transpose_X": False,
"transpose_Y": False,
"alpha": 1,
"x_num_col_dims": len(input.shape) - 1,
"y_num_col_dims": 1,
}
inputs = {"X": [input], "Y": [self.weight]}
if in_dygraph_mode():
outs = core.ops.matmul(inputs, attrs)
outs = core.ops.mul(inputs, attrs)
pre_bias = outs['Out'][0]
pre_act = dygraph_utils._append_bias_in_dygraph(
......@@ -941,7 +940,7 @@ class Linear(layers.Layer):
tmp = self._helper.create_variable_for_type_inference(self._dtype)
self._helper.append_op(
type="matmul", inputs=inputs, outputs={"Out": tmp}, attrs=attrs)
type="mul", inputs=inputs, outputs={"Out": tmp}, attrs=attrs)
if self.bias:
pre_activation = self._helper.create_variable_for_type_inference(
dtype=self._dtype)
......
......@@ -148,7 +148,7 @@ class TestImperativeOptimizerBase(unittest.TestCase):
img = fluid.layers.data(
name='pixel', shape=[1, 28, 28], dtype='float32')
label = fluid.layers.data(name='label', shape=[1], dtype='int64')
img = fluid.layers.reshape(img, shape=[batch_size, -1])
img = fluid.layers.reshape(img, shape=[batch_size, 784])
cost = mlp(img)
avg_loss = fluid.layers.reduce_mean(cost)
optimizer.minimize(avg_loss)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册