From a67783b7dcb942d8856ff85269310aeec9f5003b Mon Sep 17 00:00:00 2001 From: enkilee Date: Tue, 23 Jan 2024 09:45:04 +0800 Subject: [PATCH 1/5] fix --- test/legacy_test/test_matmul_op.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/test/legacy_test/test_matmul_op.py b/test/legacy_test/test_matmul_op.py index aec83676e39328..d3d25a3b3c443a 100644 --- a/test/legacy_test/test_matmul_op.py +++ b/test/legacy_test/test_matmul_op.py @@ -221,12 +221,13 @@ def test_dygraph_without_out(self): class API_TestMmError(unittest.TestCase): + @test_with_pir_api def test_errors(self): with paddle_static_guard(): def test_error1(): - with paddle.base.program_guard( - paddle.base.Program(), paddle.base.Program() + with paddle.static.program_guard( + paddle.static.Program(), paddle.static.Program() ): data1 = paddle.static.data( name="data1", shape=[10, 2], dtype="float32" @@ -239,8 +240,8 @@ def test_error1(): self.assertRaises(ValueError, test_error1) def test_error2(): - with paddle.base.program_guard( - paddle.base.Program(), paddle.base.Program() + with paddle.static.program_guard( + paddle.static.Program(), paddle.static.Program() ): data1 = paddle.static.data( name="data1", shape=[-1, 10, 2], dtype="float32" @@ -253,7 +254,9 @@ def test_error2(): test_error2() def test_error3(): - with base.program_guard(base.Program(), base.Program()): + with paddle.static.program_guard( + paddle.static.Program(), paddle.static.Program() + ): data1 = paddle.static.data( name="data1", shape=[10, 10, 2], dtype="float32" ) From 20c04b2bcc9c30aeccb07880ef0ffee49ed2c2a4 Mon Sep 17 00:00:00 2001 From: enkilee Date: Wed, 24 Jan 2024 12:37:38 +0800 Subject: [PATCH 2/5] fix --- test/legacy_test/test_matmul_op.py | 56 +++++++++++++----------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/test/legacy_test/test_matmul_op.py b/test/legacy_test/test_matmul_op.py index d3d25a3b3c443a..5cd08c7106cc0e 100644 --- a/test/legacy_test/test_matmul_op.py +++ b/test/legacy_test/test_matmul_op.py @@ -223,47 +223,41 @@ 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.static.program_guard( - paddle.static.Program(), paddle.static.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.static.program_guard( - paddle.static.Program(), paddle.static.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) + 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 paddle.static.program_guard( - paddle.static.Program(), paddle.static.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) + 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) From fd9e8c0caf11f3aec2cfb842da659ef5524817ad Mon Sep 17 00:00:00 2001 From: enkilee Date: Wed, 24 Jan 2024 13:37:11 +0800 Subject: [PATCH 3/5] fix --- test/legacy_test/test_matmul_op.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/legacy_test/test_matmul_op.py b/test/legacy_test/test_matmul_op.py index 5cd08c7106cc0e..b19a92d75e08ad 100644 --- a/test/legacy_test/test_matmul_op.py +++ b/test/legacy_test/test_matmul_op.py @@ -240,24 +240,24 @@ def test_error1(): self.assertRaises(ValueError, test_error1) def test_error2(): - data1 = paddle.static.data( - name="data1", shape=[-1, 10, 2], dtype="float32" + data3 = paddle.static.data( + name="data3", shape=[-1, 10, 2], dtype="float32" ) - data2 = paddle.static.data( - name="data2", shape=[-1, 2, 10], dtype="float32" + data4 = paddle.static.data( + name="data4", shape=[-1, 2, 10], dtype="float32" ) - paddle.mm(data1, data2) + paddle.mm(data3, data4) test_error2() def test_error3(): - data1 = paddle.static.data( - name="data1", shape=[10, 10, 2], dtype="float32" + data5 = paddle.static.data( + name="data5", shape=[10, 10, 2], dtype="float32" ) - data2 = paddle.static.data( - name="data2", shape=[3, 2, 10], dtype="float32" + data6 = paddle.static.data( + name="data6", shape=[3, 2, 10], dtype="float32" ) - paddle.mm(data1, data2) + paddle.mm(data5, data6) self.assertRaises(ValueError, test_error3) From 3c389cee5d89dc91f083f4734d9afd361c13e6f5 Mon Sep 17 00:00:00 2001 From: enkilee Date: Thu, 25 Jan 2024 09:23:30 +0800 Subject: [PATCH 4/5] fix --- test/legacy_test/test_matmul_op.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/legacy_test/test_matmul_op.py b/test/legacy_test/test_matmul_op.py index b19a92d75e08ad..2d14aa0733a407 100644 --- a/test/legacy_test/test_matmul_op.py +++ b/test/legacy_test/test_matmul_op.py @@ -248,7 +248,7 @@ def test_error2(): ) paddle.mm(data3, data4) - test_error2() + self.assertRaises(ValueError, test_error2) def test_error3(): data5 = paddle.static.data( From c043c3d00cb7dcfc7aa503b02997b17f91a1903b Mon Sep 17 00:00:00 2001 From: enkilee Date: Thu, 25 Jan 2024 10:16:12 +0800 Subject: [PATCH 5/5] fix --- test/legacy_test/test_matmul_op.py | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/test/legacy_test/test_matmul_op.py b/test/legacy_test/test_matmul_op.py index 2d14aa0733a407..bf2d8d0ee95669 100644 --- a/test/legacy_test/test_matmul_op.py +++ b/test/legacy_test/test_matmul_op.py @@ -241,26 +241,15 @@ def test_error1(): def test_error2(): data3 = paddle.static.data( - name="data3", shape=[-1, 10, 2], dtype="float32" + name="data3", shape=[10, 10, 2], dtype="float32" ) data4 = paddle.static.data( - name="data4", shape=[-1, 2, 10], dtype="float32" + name="data4", shape=[3, 2, 10], dtype="float32" ) paddle.mm(data3, data4) self.assertRaises(ValueError, test_error2) - def test_error3(): - data5 = paddle.static.data( - name="data5", shape=[10, 10, 2], dtype="float32" - ) - data6 = paddle.static.data( - name="data6", shape=[3, 2, 10], dtype="float32" - ) - paddle.mm(data5, data6) - - self.assertRaises(ValueError, test_error3) - if __name__ == "__main__": unittest.main()