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