diff --git a/test/legacy_test/test_batch_norm_op.py b/test/legacy_test/test_batch_norm_op.py index 6db07fc33cca91..342d590afc3ae3 100644 --- a/test/legacy_test/test_batch_norm_op.py +++ b/test/legacy_test/test_batch_norm_op.py @@ -942,8 +942,11 @@ 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 a1301bcd2242ba..3eed30e2df6811 100644 --- a/test/legacy_test/test_bicubic_interp_op.py +++ b/test/legacy_test/test_bicubic_interp_op.py @@ -19,8 +19,8 @@ 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 def cubic_1(x, a): @@ -363,8 +363,11 @@ 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 64b93aa96eaf84..ab053c3dc64e1f 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 @@ -251,9 +251,12 @@ def initTestCase(self): 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(): @@ -424,12 +427,16 @@ 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") - 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 af98343f24c531..37ef304015f33e 100644 --- a/test/legacy_test/test_conv2d_op.py +++ b/test/legacy_test/test_conv2d_op.py @@ -20,7 +20,8 @@ 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 def conv2d_forward_naive( @@ -726,8 +727,11 @@ 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 d3d371c8e8ab0f..12c19386e107ad 100644 --- a/test/legacy_test/test_dot_op.py +++ b/test/legacy_test/test_dot_op.py @@ -19,7 +19,8 @@ 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 class DotOp(OpTest): @@ -131,8 +132,11 @@ def test_check_grad_ignore_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_gather_op.py b/test/legacy_test/test_gather_op.py index 6b68013924865f..6c6523d422c6f8 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,8 +568,11 @@ 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()): + 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') @@ -586,6 +590,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 78601c77ecf069..ca76f401bc950c 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 d7f8b4050caf66..648106a3b5aa30 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() diff --git a/test/legacy_test/test_solve_op.py b/test/legacy_test/test_solve_op.py index e2f886c681162c..927a8278f9ae28 100644 --- a/test/legacy_test/test_solve_op.py +++ b/test/legacy_test/test_solve_op.py @@ -24,7 +24,7 @@ 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 # 2D normal case @@ -258,8 +258,11 @@ 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()