Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PIR] A-14 Adapt matmul test_errors #61038

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 21 additions & 35 deletions test/legacy_test/test_matmul_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,48 +221,34 @@ def test_dygraph_without_out(self):


class API_TestMmError(unittest.TestCase):
@test_with_pir_api
def test_errors(self):
with paddle_static_guard():
paddle.enable_static()
with paddle.static.program_guard(
paddle.static.Program(), paddle.static.Program()
):

def test_error1():
with paddle.base.program_guard(
paddle.base.Program(), paddle.base.Program()
):
data1 = paddle.static.data(
name="data1", shape=[10, 2], dtype="float32"
)
data2 = paddle.static.data(
name="data2", shape=[3, 10], dtype="float32"
)
paddle.mm(data1, data2)
data1 = paddle.static.data(
name="data1", shape=[10, 2], dtype="float32"
)
data2 = paddle.static.data(
name="data2", shape=[3, 10], dtype="float32"
)
paddle.mm(data1, data2)

self.assertRaises(ValueError, test_error1)

def test_error2():
with paddle.base.program_guard(
paddle.base.Program(), paddle.base.Program()
):
data1 = paddle.static.data(
name="data1", shape=[-1, 10, 2], dtype="float32"
)
data2 = paddle.static.data(
name="data2", shape=[-1, 2, 10], dtype="float32"
)
paddle.mm(data1, data2)

test_error2()

def test_error3():
with base.program_guard(base.Program(), base.Program()):
data1 = paddle.static.data(
name="data1", shape=[10, 10, 2], dtype="float32"
)
data2 = paddle.static.data(
name="data2", shape=[3, 2, 10], dtype="float32"
)
paddle.mm(data1, data2)

self.assertRaises(ValueError, test_error3)
data3 = paddle.static.data(
name="data3", shape=[10, 10, 2], dtype="float32"
)
data4 = paddle.static.data(
name="data4", shape=[3, 2, 10], dtype="float32"
)
paddle.mm(data3, data4)

self.assertRaises(ValueError, test_error2)


if __name__ == "__main__":
Expand Down