From 7b3f8885be5283a32191e585705ebacb02f6cbb5 Mon Sep 17 00:00:00 2001 From: Zhan Rongrui <2742392377@qq.com> Date: Mon, 29 Jan 2024 07:52:40 +0000 Subject: [PATCH 1/3] add --- test/legacy_test/test_clip_op.py | 2 ++ test/legacy_test/test_dot_op.py | 2 ++ test/legacy_test/test_gather_op.py | 3 +++ test/legacy_test/test_min_op.py | 1 + test/legacy_test/test_prod_op.py | 1 + 5 files changed, 9 insertions(+) diff --git a/test/legacy_test/test_clip_op.py b/test/legacy_test/test_clip_op.py index 64b93aa96eaf8..27c991885fecb 100644 --- a/test/legacy_test/test_clip_op.py +++ b/test/legacy_test/test_clip_op.py @@ -251,6 +251,7 @@ def initTestCase(self): class TestClipOpError(unittest.TestCase): + @test_with_pir_api def test_errors(self): paddle.enable_static() with program_guard(Program(), Program()): @@ -424,6 +425,7 @@ def test_clip_dygraph_default_max(self): np.testing.assert_allclose(out2.numpy(), egr_out2.numpy(), rtol=1e-05) np.testing.assert_allclose(out3.numpy(), egr_out3.numpy(), rtol=1e-05) + @test_with_pir_api def test_errors(self): paddle.enable_static() x1 = paddle.static.data(name='x1', shape=[1], dtype="int16") diff --git a/test/legacy_test/test_dot_op.py b/test/legacy_test/test_dot_op.py index 3b1a216add6da..9ee3ba39abb1f 100644 --- a/test/legacy_test/test_dot_op.py +++ b/test/legacy_test/test_dot_op.py @@ -20,6 +20,7 @@ import paddle from paddle import base from paddle.base import Program, core, program_guard +from paddle.pir_utils import test_with_pir_api class DotOp(OpTest): @@ -131,6 +132,7 @@ def test_check_grad_ingore_y(self): class TestDotOpError(unittest.TestCase): + @test_with_pir_api def test_errors(self): with program_guard(Program(), Program()): # the input dtype of elementwise_mul must be float16 or float32 or float64 or int32 or int64 diff --git a/test/legacy_test/test_gather_op.py b/test/legacy_test/test_gather_op.py index f37af3a62ddb9..fdad9297e88b5 100644 --- a/test/legacy_test/test_gather_op.py +++ b/test/legacy_test/test_gather_op.py @@ -535,6 +535,7 @@ def test_static_graph(): class TestGathertError(unittest.TestCase): + @test_with_pir_api def test_error1(self): with paddle.static.program_guard( paddle.static.Program(), paddle.static.Program() @@ -567,6 +568,7 @@ def test_axis_dtype1(): self.assertRaises(TypeError, test_axis_dtype1) + @test_with_pir_api def test_error2(self): with base.program_guard(base.Program(), base.Program()): shape = [8, 9, 6] @@ -586,6 +588,7 @@ def test_index_type(): self.assertRaises(TypeError, test_index_type) + @test_with_pir_api def test_error3(self): with paddle.static.program_guard( paddle.static.Program(), paddle.static.Program() diff --git a/test/legacy_test/test_min_op.py b/test/legacy_test/test_min_op.py index 78601c77ecf06..ca76f401bc950 100644 --- a/test/legacy_test/test_min_op.py +++ b/test/legacy_test/test_min_op.py @@ -64,6 +64,7 @@ def test_api(self): (res,) = exe.run(feed={"data": input_data}, fetch_list=[result_min]) self.assertEqual((res == np.min(input_data, axis=(0, 1))).all(), True) + @test_with_pir_api def test_errors(self): paddle.enable_static() diff --git a/test/legacy_test/test_prod_op.py b/test/legacy_test/test_prod_op.py index d7f8b4050caf6..648106a3b5aa3 100644 --- a/test/legacy_test/test_prod_op.py +++ b/test/legacy_test/test_prod_op.py @@ -151,6 +151,7 @@ def test_gpu(self): class TestProdOpError(unittest.TestCase): + @test_with_pir_api def test_error(self): with paddle.static.program_guard( paddle.static.Program(), paddle.static.Program() From 23a2de6b19561c18d34d7579faade3e0e613ad26 Mon Sep 17 00:00:00 2001 From: Zhan Rongrui <2742392377@qq.com> Date: Mon, 29 Jan 2024 08:10:28 +0000 Subject: [PATCH 2/3] add --- test/legacy_test/test_batch_norm_op.py | 2 ++ test/legacy_test/test_bicubic_interp_op.py | 2 ++ test/legacy_test/test_conv2d_op.py | 2 ++ test/legacy_test/test_eig_op.py | 4 ++++ test/legacy_test/test_eigvals_op.py | 2 ++ test/legacy_test/test_solve_op.py | 2 ++ 6 files changed, 14 insertions(+) diff --git a/test/legacy_test/test_batch_norm_op.py b/test/legacy_test/test_batch_norm_op.py index 60207076c55db..f51c3e41b7eea 100644 --- a/test/legacy_test/test_batch_norm_op.py +++ b/test/legacy_test/test_batch_norm_op.py @@ -921,6 +921,7 @@ def init_test_case(self): class TestBatchNormOpError(unittest.TestCase): + @test_with_pir_api def test_errors(self): with program_guard(Program(), Program()): # the input of batch_norm must be Variable. @@ -942,6 +943,7 @@ def test_errors(self): class TestDygraphBatchNormAPIError(unittest.TestCase): + @test_with_pir_api def test_errors(self): with program_guard(Program(), Program()): batch_norm = paddle.nn.BatchNorm(10) diff --git a/test/legacy_test/test_bicubic_interp_op.py b/test/legacy_test/test_bicubic_interp_op.py index a1301bcd2242b..6cfc687cdfb23 100644 --- a/test/legacy_test/test_bicubic_interp_op.py +++ b/test/legacy_test/test_bicubic_interp_op.py @@ -21,6 +21,7 @@ from paddle import base from paddle.base import Program, program_guard from paddle.nn.functional import interpolate +from paddle.pir_utils import test_with_pir_api def cubic_1(x, a): @@ -363,6 +364,7 @@ def test_case(self): class TestBicubicOpError(unittest.TestCase): + @test_with_pir_api def test_errors(self): with program_guard(Program(), Program()): # the input of interpoalte must be Variable. diff --git a/test/legacy_test/test_conv2d_op.py b/test/legacy_test/test_conv2d_op.py index e601e8c7bc681..3a703224e8e71 100644 --- a/test/legacy_test/test_conv2d_op.py +++ b/test/legacy_test/test_conv2d_op.py @@ -21,6 +21,7 @@ import paddle from paddle import base from paddle.base import Program, core, program_guard +from paddle.pir_utils import test_with_pir_api def conv2d_forward_naive( @@ -726,6 +727,7 @@ def init_kernel_type(self): class TestConv2DOpError(unittest.TestCase): + @test_with_pir_api def test_errors(self): with program_guard(Program(), Program()): diff --git a/test/legacy_test/test_eig_op.py b/test/legacy_test/test_eig_op.py index c6b57258fc820..1e66084d84274 100644 --- a/test/legacy_test/test_eig_op.py +++ b/test/legacy_test/test_eig_op.py @@ -20,6 +20,7 @@ import paddle from paddle import base from paddle.base import core +from paddle.pir_utils import test_with_pir_api # cast output to complex for numpy.linalg.eig @@ -348,6 +349,7 @@ def test_check_grad(self): class TestEigWrongDimsError(unittest.TestCase): + @test_with_pir_api def test_error(self): paddle.device.set_device("cpu") paddle.disable_static() @@ -357,6 +359,7 @@ def test_error(self): class TestEigNotSquareError(unittest.TestCase): + @test_with_pir_api def test_error(self): paddle.device.set_device("cpu") paddle.disable_static() @@ -366,6 +369,7 @@ def test_error(self): class TestEigUnsupportedDtypeError(unittest.TestCase): + @test_with_pir_api def test_error(self): paddle.device.set_device("cpu") paddle.disable_static() diff --git a/test/legacy_test/test_eigvals_op.py b/test/legacy_test/test_eigvals_op.py index c54a4070be3a4..b2153b7be973e 100644 --- a/test/legacy_test/test_eigvals_op.py +++ b/test/legacy_test/test_eigvals_op.py @@ -19,6 +19,7 @@ import paddle from paddle.base import core +from paddle.pir_utils import test_with_pir_api np.set_printoptions(threshold=np.inf) @@ -324,6 +325,7 @@ def test_cases(self): self.run_dygraph(place) self.run_static(place) + @test_with_pir_api def test_error(self): paddle.disable_static() x = paddle.to_tensor([1]) diff --git a/test/legacy_test/test_solve_op.py b/test/legacy_test/test_solve_op.py index 040cf1a80fa06..71d743bb17470 100644 --- a/test/legacy_test/test_solve_op.py +++ b/test/legacy_test/test_solve_op.py @@ -25,6 +25,7 @@ from paddle import base from paddle.base import Program, program_guard +from paddle.pir_utils import test_with_pir_api # 2D normal case @@ -258,6 +259,7 @@ def test_check_grad_normal(self): class TestSolveOpError(unittest.TestCase): + @test_with_pir_api def test_errors(self): with program_guard(Program(), Program()): # The input type of solve_op must be Variable. From 025e4e6804dc4163bedee884493fe42e61e35f9c Mon Sep 17 00:00:00 2001 From: 0x45f Date: Sun, 4 Feb 2024 06:58:37 +0000 Subject: [PATCH 3/3] Fix uts --- test/legacy_test/test_batch_norm_op.py | 5 +++-- test/legacy_test/test_bicubic_interp_op.py | 5 +++-- test/legacy_test/test_clip_op.py | 17 +++++++++++------ test/legacy_test/test_conv2d_op.py | 6 ++++-- test/legacy_test/test_dot_op.py | 6 ++++-- test/legacy_test/test_eig_op.py | 4 ---- test/legacy_test/test_eigvals_op.py | 2 -- test/legacy_test/test_gather_op.py | 4 +++- test/legacy_test/test_solve_op.py | 5 +++-- 9 files changed, 31 insertions(+), 23 deletions(-) diff --git a/test/legacy_test/test_batch_norm_op.py b/test/legacy_test/test_batch_norm_op.py index 873d59f45564e..342d590afc3ae 100644 --- a/test/legacy_test/test_batch_norm_op.py +++ b/test/legacy_test/test_batch_norm_op.py @@ -921,7 +921,6 @@ def init_test_case(self): class TestBatchNormOpError(unittest.TestCase): - @test_with_pir_api def test_errors(self): with program_guard(Program(), Program()): # the input of batch_norm must be Variable. @@ -945,7 +944,9 @@ def test_errors(self): class TestDygraphBatchNormAPIError(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() + ): batch_norm = paddle.nn.BatchNorm(10) # the input of BatchNorm must be Variable. x1 = base.create_lod_tensor( diff --git a/test/legacy_test/test_bicubic_interp_op.py b/test/legacy_test/test_bicubic_interp_op.py index 6cfc687cdfb23..3eed30e2df681 100644 --- a/test/legacy_test/test_bicubic_interp_op.py +++ b/test/legacy_test/test_bicubic_interp_op.py @@ -19,7 +19,6 @@ import paddle from paddle import base -from paddle.base import Program, program_guard from paddle.nn.functional import interpolate from paddle.pir_utils import test_with_pir_api @@ -366,7 +365,9 @@ def test_case(self): class TestBicubicOpError(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() + ): # the input of interpoalte must be Variable. x1 = base.create_lod_tensor( np.array([-1, 3, 5, 5]), [[1, 1, 1, 1]], base.CPUPlace() diff --git a/test/legacy_test/test_clip_op.py b/test/legacy_test/test_clip_op.py index 27c991885fecb..ab053c3dc64e1 100644 --- a/test/legacy_test/test_clip_op.py +++ b/test/legacy_test/test_clip_op.py @@ -19,7 +19,7 @@ import paddle from paddle import base -from paddle.base import Program, core, program_guard +from paddle.base import core from paddle.pir_utils import test_with_pir_api @@ -254,7 +254,9 @@ class TestClipOpError(unittest.TestCase): @test_with_pir_api def test_errors(self): paddle.enable_static() - with program_guard(Program(), Program()): + with paddle.static.program_guard( + paddle.static.Program(), paddle.static.Program() + ): input_data = np.random.random((2, 4)).astype("float32") def test_Variable(): @@ -428,10 +430,13 @@ def test_clip_dygraph_default_max(self): @test_with_pir_api def test_errors(self): paddle.enable_static() - x1 = paddle.static.data(name='x1', shape=[1], dtype="int16") - x2 = paddle.static.data(name='x2', shape=[1], dtype="int8") - self.assertRaises(TypeError, paddle.clip, x=x1, min=0.2, max=0.8) - self.assertRaises(TypeError, paddle.clip, x=x2, min=0.2, max=0.8) + with paddle.static.program_guard( + paddle.static.Program(), paddle.static.Program() + ): + x1 = paddle.static.data(name='x1', shape=[1], dtype="int16") + x2 = paddle.static.data(name='x2', shape=[1], dtype="int8") + self.assertRaises(TypeError, paddle.clip, x=x1, min=0.2, max=0.8) + self.assertRaises(TypeError, paddle.clip, x=x2, min=0.2, max=0.8) paddle.disable_static() diff --git a/test/legacy_test/test_conv2d_op.py b/test/legacy_test/test_conv2d_op.py index 3a703224e8e71..41a9ff399c297 100644 --- a/test/legacy_test/test_conv2d_op.py +++ b/test/legacy_test/test_conv2d_op.py @@ -20,7 +20,7 @@ import paddle from paddle import base -from paddle.base import Program, core, program_guard +from paddle.base import core from paddle.pir_utils import test_with_pir_api @@ -729,7 +729,9 @@ def init_kernel_type(self): class TestConv2DOpError(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() + ): def test_Variable(): # the input of conv2d must be Variable. diff --git a/test/legacy_test/test_dot_op.py b/test/legacy_test/test_dot_op.py index c8fb7d9d40638..e0fa62c8a9530 100644 --- a/test/legacy_test/test_dot_op.py +++ b/test/legacy_test/test_dot_op.py @@ -19,7 +19,7 @@ import paddle from paddle import base -from paddle.base import Program, core, program_guard +from paddle.base import core from paddle.pir_utils import test_with_pir_api @@ -134,7 +134,9 @@ def test_check_grad_ingore_y(self): class TestDotOpError(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() + ): # the input dtype of elementwise_mul must be float16 or float32 or float64 or int32 or int64 # float16 only can be set on GPU place x1 = paddle.static.data(name='x1', shape=[-1, 120], dtype="uint8") diff --git a/test/legacy_test/test_eig_op.py b/test/legacy_test/test_eig_op.py index 0e6b676a7b388..515148d52f6d4 100644 --- a/test/legacy_test/test_eig_op.py +++ b/test/legacy_test/test_eig_op.py @@ -20,7 +20,6 @@ import paddle from paddle import base from paddle.base import core -from paddle.pir_utils import test_with_pir_api # cast output to complex for numpy.linalg.eig @@ -349,7 +348,6 @@ def test_check_grad(self): class TestEigWrongDimsError(unittest.TestCase): - @test_with_pir_api def test_error(self): paddle.device.set_device("cpu") paddle.disable_static() @@ -359,7 +357,6 @@ def test_error(self): class TestEigNotSquareError(unittest.TestCase): - @test_with_pir_api def test_error(self): paddle.device.set_device("cpu") paddle.disable_static() @@ -369,7 +366,6 @@ def test_error(self): class TestEigUnsupportedDtypeError(unittest.TestCase): - @test_with_pir_api def test_error(self): paddle.device.set_device("cpu") paddle.disable_static() diff --git a/test/legacy_test/test_eigvals_op.py b/test/legacy_test/test_eigvals_op.py index b2153b7be973e..c54a4070be3a4 100644 --- a/test/legacy_test/test_eigvals_op.py +++ b/test/legacy_test/test_eigvals_op.py @@ -19,7 +19,6 @@ import paddle from paddle.base import core -from paddle.pir_utils import test_with_pir_api np.set_printoptions(threshold=np.inf) @@ -325,7 +324,6 @@ def test_cases(self): self.run_dygraph(place) self.run_static(place) - @test_with_pir_api def test_error(self): paddle.disable_static() x = paddle.to_tensor([1]) diff --git a/test/legacy_test/test_gather_op.py b/test/legacy_test/test_gather_op.py index 6aa1199bdad35..6c6523d422c6f 100644 --- a/test/legacy_test/test_gather_op.py +++ b/test/legacy_test/test_gather_op.py @@ -570,7 +570,9 @@ def test_axis_dtype1(): @test_with_pir_api def test_error2(self): - with base.program_guard(base.Program(), base.Program()): + with paddle.static.program_guard( + paddle.static.Program(), paddle.static.Program() + ): shape = [8, 9, 6] x = paddle.static.data(shape=shape, dtype='int8', name='x') index = paddle.static.data(shape=shape, dtype='int32', name='mask') diff --git a/test/legacy_test/test_solve_op.py b/test/legacy_test/test_solve_op.py index 80674c0f77dbe..927a8278f9ae2 100644 --- a/test/legacy_test/test_solve_op.py +++ b/test/legacy_test/test_solve_op.py @@ -24,7 +24,6 @@ from op_test import OpTest from paddle import base -from paddle.base import Program, program_guard from paddle.pir_utils import test_with_pir_api @@ -261,7 +260,9 @@ def test_check_grad_normal(self): class TestSolveOpError(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() + ): # The input type of solve_op must be Variable. x1 = base.create_lod_tensor( np.array([[-1]]), [[1]], base.CPUPlace()