From 640a7f6702ebaa9dd43f7bd5ad4d348cb7301fb8 Mon Sep 17 00:00:00 2001 From: Zhan Rongrui <2742392377@qq.com> Date: Tue, 27 Feb 2024 04:09:39 +0000 Subject: [PATCH 1/3] add --- test/legacy_test/test_activation_op.py | 37 +++++++++++++++----------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/test/legacy_test/test_activation_op.py b/test/legacy_test/test_activation_op.py index 485c770dd96df1..d21defb216ba49 100644 --- a/test/legacy_test/test_activation_op.py +++ b/test/legacy_test/test_activation_op.py @@ -40,9 +40,12 @@ def dynamic_guard(): class TestSqrtOpError(unittest.TestCase): + @test_with_pir_api def test_errors(self): with static_guard(): - with program_guard(Program(), Program()): + with paddle.static.program_guard( + paddle.static.Program(), paddle.static.Program() + ): # The input type of sqrt op must be Variable or numpy.ndarray. in1 = 1 self.assertRaises(TypeError, paddle.sqrt, in1) @@ -643,6 +646,7 @@ def test_dygraph_api(self): np.testing.assert_allclose(out_ref, r.numpy(), rtol=1e-05) paddle.enable_static() + @test_with_pir_api def test_errors(self): with static_guard(): with paddle.static.program_guard(paddle.static.Program()): @@ -890,6 +894,7 @@ def test_dygraph_api(self): for r in [out1, out2, out3]: np.testing.assert_allclose(out_ref, r.numpy(), rtol=1e-05) + @test_with_pir_api def test_errors(self): with static_guard(): with paddle.static.program_guard(paddle.static.Program()): @@ -2702,22 +2707,22 @@ def test_dygraph_api(self): for r in [out1, out2]: np.testing.assert_allclose(out_ref, r.numpy(), rtol=1e-05) + @test_with_pir_api def test_errors(self): with static_guard(): - with static_guard(): - with paddle.static.program_guard(paddle.static.Program()): - # The input type must be Variable. - self.assertRaises(TypeError, self.relu, 1) - # The input dtype must be float16, float32, float64. - x_int32 = paddle.static.data( - name='x_int32', shape=[10, 12], dtype='int32' - ) - self.assertRaises(TypeError, self.relu, x_int32) - # support the input dtype is float16 - x_fp16 = paddle.static.data( - name='x_fp16', shape=[10, 12], dtype='float16' - ) - self.relu(x_fp16) + with paddle.static.program_guard(paddle.static.Program()): + # The input type must be Variable. + self.assertRaises(TypeError, self.relu, 1) + # The input dtype must be float16, float32, float64. + x_int32 = paddle.static.data( + name='x_int32', shape=[10, 12], dtype='int32' + ) + self.assertRaises(TypeError, self.relu, x_int32) + # support the input dtype is float16 + x_fp16 = paddle.static.data( + name='x_fp16', shape=[10, 12], dtype='float16' + ) + self.relu(x_fp16) class TestReluInplaceAPI(TestReluAPI): @@ -2846,6 +2851,7 @@ def test_dygraph_api(self): for r in [out1, out2]: np.testing.assert_allclose(out_ref, r.numpy(), rtol=1e-05) + @test_with_pir_api def test_errors(self): with static_guard(): with paddle.static.program_guard(paddle.static.Program()): @@ -3029,6 +3035,7 @@ def test_dygraph_api(self): for r in [out1, out2]: np.testing.assert_allclose(out_ref, r.numpy(), rtol=1e-05) + @test_with_pir_api def test_errors(self): with static_guard(): with paddle.static.program_guard(paddle.static.Program()): From 344e053eae12cd914eb13102e025f07cca531e15 Mon Sep 17 00:00:00 2001 From: Zhan Rongrui <2742392377@qq.com> Date: Tue, 27 Feb 2024 06:49:07 +0000 Subject: [PATCH 2/3] add full_like --- test/legacy_test/test_full_like_op.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/legacy_test/test_full_like_op.py b/test/legacy_test/test_full_like_op.py index 9f327b0b0107ae..81322bd431c310 100644 --- a/test/legacy_test/test_full_like_op.py +++ b/test/legacy_test/test_full_like_op.py @@ -23,7 +23,6 @@ from paddle.base.framework import convert_np_dtype_to_dtype_ from paddle.framework import in_pir_mode from paddle.pir_utils import test_with_pir_api -from paddle.static import Program, program_guard def fill_any_like_wrapper(x, value, out_dtype=None, name=None): @@ -98,8 +97,11 @@ def test_full_like_fill_inf(self): class TestFullOpError(unittest.TestCase): + @test_with_pir_api def test_errors(self): - with program_guard(Program(), Program()): + with paddle.static.program_guard( + paddle.static.Program(), paddle.static.Program() + ): # for ci coverage input_data = paddle.static.data( From 2b2202a20144e52f81a16154051b6c1121654eac Mon Sep 17 00:00:00 2001 From: Zhan Rongrui <2742392377@qq.com> Date: Tue, 27 Feb 2024 06:51:48 +0000 Subject: [PATCH 3/3] add --- test/legacy_test/test_activation_op.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/legacy_test/test_activation_op.py b/test/legacy_test/test_activation_op.py index d21defb216ba49..b3a4fe8e7863c6 100644 --- a/test/legacy_test/test_activation_op.py +++ b/test/legacy_test/test_activation_op.py @@ -2710,7 +2710,9 @@ def test_dygraph_api(self): @test_with_pir_api def test_errors(self): with static_guard(): - with paddle.static.program_guard(paddle.static.Program()): + with paddle.static.program_guard( + paddle.static.Program(), paddle.static.Program() + ): # The input type must be Variable. self.assertRaises(TypeError, self.relu, 1) # The input dtype must be float16, float32, float64.