未验证 提交 481ee79f 编写于 作者: W wanghuancoder 提交者: GitHub

speed up paddle.add paddle.nn.Linear (#32125)

* modify API nn.Bilinear's doc, test=develop

* speed up paddle.add paddle.nn.Linear, test=develop

* fix bug, test=develop
上级 6c399d94
......@@ -1446,11 +1446,12 @@ def linear(x, weight, bias=None, name=None):
# [2.1077576 2.1077576 2.1077576 2.1077576 ]]
"""
if in_dygraph_mode():
pre_bias = _varbase_creator(dtype=x.dtype)
core.ops.matmul(x, weight, pre_bias, 'transpose_X', False,
'transpose_Y', False, "alpha", 1)
return dygraph_utils._append_bias_in_dygraph(
pre_bias, bias, axis=len(x.shape) - 1)
pre_bias = core.ops.matmul_v2(x, weight)
if bias is None:
return pre_bias
return core.ops.elementwise_add(pre_bias, bias)
else:
helper = LayerHelper('linear', **locals())
dtype = x.dtype
......
......@@ -232,13 +232,11 @@ def add(x, y, name=None):
print(z) # [3., 8., 6. ]
"""
op_type = 'elementwise_add'
axis = -1
if in_dygraph_mode():
return _elementwise_op_in_dygraph(
x, y, axis=axis, op_name=op_type)
return core.ops.elementwise_add(x, y)
return _elementwise_op(LayerHelper(op_type, **locals()))
return _elementwise_op(LayerHelper('elementwise_add', **locals()))
@inplace_apis_in_dygraph_only
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册