Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def GeneratePythonCFunction(fwd_api_name, forward_inputs_position_map,
get_eager_tensor_str += f" auto& {name} = GetTensorFromArgs(\"{fwd_api_name}\", \"{name}\", args, {pos}, false);\n"
dygraph_function_call_list[pos] = f"{name}"

parse_attributes_str = " paddle::framework::AttributeMap attrs;\n"
parse_attributes_str = ""
# Get Attributes
for name, atype, _, pos in forward_attrs_list:
parsing_function = FindParsingFunctionFromAttributeType(atype)
Expand Down
41 changes: 28 additions & 13 deletions python/paddle/fluid/tests/unittests/test_matmul_v2_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import paddle
import paddle.fluid as fluid
import paddle.fluid.framework as framework
from paddle.fluid.framework import _test_eager_guard


def reference_matmul(X, Y, transpose_X=False, transpose_Y=False):
Expand Down Expand Up @@ -88,13 +89,14 @@ def setUp(self):
self.outputs = {'Out': result}

def test_check_output(self):
self.check_output()
self.check_output(check_eager=True)

def test_check_grad(self):
if core.is_compiled_with_rocm():
self.check_grad(['X', 'Y'], 'Out', max_relative_error=1e-2)
self.check_grad(
['X', 'Y'], 'Out', max_relative_error=1e-2, check_eager=True)
else:
self.check_grad(['X', 'Y'], 'Out')
self.check_grad(['X', 'Y'], 'Out', check_eager=True)


class TestMatMuklOp2(TestMatMulV2Op):
Expand Down Expand Up @@ -327,15 +329,17 @@ def test_check_output(self):
if core.is_compiled_with_cuda():
place = core.CUDAPlace(0)
if core.is_float16_supported(place):
self.check_output_with_place(place, atol=atol)
self.check_output_with_place(
place, atol=atol, check_eager=True)

def test_check_grad(self):
place = core.CUDAPlace(0)
if core.is_float16_supported(place):
self.check_grad_with_place(
place, ['X', 'Y'],
'Out',
max_relative_error=max_relative_error)
max_relative_error=max_relative_error,
check_eager=True)

cls_name = "{0}_{1}".format(parent.__name__, "Fp16")
TestMatMulOpFp16Case.__name__ = cls_name
Expand Down Expand Up @@ -407,6 +411,11 @@ def test_dygraph_fp16(self):
y = paddle.to_tensor(input_y)
result = paddle.matmul(x, y)

def test_api_eager_dygraph(self):
with _test_eager_guard():
self.test_dygraph()
self.test_dygraph_fp16()


class TestComplexMatMulOp(OpTest):
def setUp(self):
Expand Down Expand Up @@ -441,30 +450,33 @@ def init_grad_input_output(self):
self.grad_y = np.matmul(np.conj(self.x).T, self.grad_out)

def test_check_output(self):
self.check_output()
self.check_output(check_eager=True)

def test_check_grad_normal(self):
self.check_grad(
['X', 'Y'],
'Out',
user_defined_grads=[self.grad_x, self.grad_y],
user_defined_grad_outputs=[self.grad_out])
user_defined_grad_outputs=[self.grad_out],
check_eager=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why check_eager is false here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't supported Type Promotion at Dygraph level yet, so I turned of eager mode test for "test_check_grad_normal" and "test_check_grad_ignore_y" for now.


def test_check_grad_ingore_x(self):
self.check_grad(
['Y'],
'Out',
no_grad_set=set("X"),
user_defined_grads=[self.grad_y],
user_defined_grad_outputs=[self.grad_out])
user_defined_grad_outputs=[self.grad_out],
check_eager=True)

def test_check_grad_ingore_y(self):
self.check_grad(
['X'],
'Out',
no_grad_set=set('Y'),
user_defined_grads=[self.grad_x],
user_defined_grad_outputs=[self.grad_out])
user_defined_grad_outputs=[self.grad_out],
check_eager=False)


class TestComplexMatMulOpBroadcast(OpTest):
Expand Down Expand Up @@ -502,30 +514,33 @@ def init_grad_input_output(self):
axis=0)

def test_check_output(self):
self.check_output()
self.check_output(check_eager=True)

def test_check_grad_normal(self):
self.check_grad(
['X', 'Y'],
'Out',
user_defined_grads=[self.grad_x, self.grad_y],
user_defined_grad_outputs=[self.grad_out])
user_defined_grad_outputs=[self.grad_out],
check_eager=True)

def test_check_grad_ingore_x(self):
self.check_grad(
['Y'],
'Out',
no_grad_set=set("X"),
user_defined_grads=[self.grad_y],
user_defined_grad_outputs=[self.grad_out])
user_defined_grad_outputs=[self.grad_out],
check_eager=True)

def test_check_grad_ingore_y(self):
self.check_grad(
['X'],
'Out',
no_grad_set=set('Y'),
user_defined_grads=[self.grad_x],
user_defined_grad_outputs=[self.grad_out])
user_defined_grad_outputs=[self.grad_out],
check_eager=True)


class TestMatMulTypePromotion(TestComplexMatMulOp):
Expand Down