diff --git a/python/paddle/nn/functional/common.py b/python/paddle/nn/functional/common.py index 65b9c6771c4f190e74b5228d5233d504d5b3fc09..e7e36ca7a3a1a7822432f391c93d26342ec9af30 100644 --- a/python/paddle/nn/functional/common.py +++ b/python/paddle/nn/functional/common.py @@ -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 diff --git a/python/paddle/tensor/math.py b/python/paddle/tensor/math.py index 23addcb7e3f4e354a0331f79e8dd7986adcb8832..2f69946c52139be5c65bf5b2c38d0d17c9b58103 100755 --- a/python/paddle/tensor/math.py +++ b/python/paddle/tensor/math.py @@ -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