diff --git a/test/deprecated/legacy_test/test_imperative_selected_rows_to_lod_tensor.py b/test/deprecated/legacy_test/test_imperative_selected_rows_to_lod_tensor.py index 4a85230af3934..f9a9c6c087125 100644 --- a/test/deprecated/legacy_test/test_imperative_selected_rows_to_lod_tensor.py +++ b/test/deprecated/legacy_test/test_imperative_selected_rows_to_lod_tensor.py @@ -92,7 +92,8 @@ def test_simple_net(self): if not core.is_compiled_with_rocm(): dtype_list.append("float64") for dtype in dtype_list: - self.simple_net_float(is_sparse, dtype) + with paddle.pir_utils.OldIrGuard(): + self.simple_net_float(is_sparse, dtype) def simple_net_float(self, is_sparse, dtype): places = [base.CPUPlace()] diff --git a/test/deprecated/legacy_test/test_memory_reuse_exclude_feed_var.py b/test/deprecated/legacy_test/test_memory_reuse_exclude_feed_var.py index 9dcf713d52572..a212391407abb 100644 --- a/test/deprecated/legacy_test/test_memory_reuse_exclude_feed_var.py +++ b/test/deprecated/legacy_test/test_memory_reuse_exclude_feed_var.py @@ -65,7 +65,8 @@ def test_main(self): with base.program_guard(base.Program(), base.Program()): with base.unique_name.guard(): with base.scope_guard(base.Scope()): - self.main_impl(p) + with paddle.pir_utils.OldIrGuard(): + self.main_impl(p) if __name__ == '__main__': diff --git a/test/deprecated/legacy_test/test_multiprocess_reader_exception.py b/test/deprecated/legacy_test/test_multiprocess_reader_exception.py index e885cffcb4fb0..2c35f5e6ea677 100644 --- a/test/deprecated/legacy_test/test_multiprocess_reader_exception.py +++ b/test/deprecated/legacy_test/test_multiprocess_reader_exception.py @@ -117,7 +117,8 @@ def test_main(self): for iterable in [False, True]: try: with base.scope_guard(base.Scope()): - self.main_impl(p, iterable) + with paddle.pir_utils.OldIrGuard(): + self.main_impl(p, iterable) self.assertTrue(not self.raise_exception) except ReaderException: diff --git a/test/deprecated/legacy_test/test_pass_builder.py b/test/deprecated/legacy_test/test_pass_builder.py index 7205c1b4ca52f..54c54f39c100d 100644 --- a/test/deprecated/legacy_test/test_pass_builder.py +++ b/test/deprecated/legacy_test/test_pass_builder.py @@ -108,17 +108,18 @@ def test_parallel_testing_with_new_strategy(self): pass_builder.remove_pass(len(pass_builder.all_passes()) - 1) self.assertEqual(origin_len + 1, len(pass_builder.all_passes())) with tempfile.TemporaryDirectory(prefix="dot_path_") as tmpdir: - graph_viz_path = os.path.join(tmpdir, 'test_viz_pass.dot') - viz_pass.set("graph_viz_path", graph_viz_path) + with paddle.pir_utils.OldIrGuard(): + graph_viz_path = os.path.join(tmpdir, 'test_viz_pass.dot') + viz_pass.set("graph_viz_path", graph_viz_path) - self.check_network_convergence( - use_cuda=core.is_compiled_with_cuda(), - build_strategy=build_strategy, - ) - try: - os.stat(graph_viz_path) - except OSError: - self.assertFalse(True) + self.check_network_convergence( + use_cuda=core.is_compiled_with_cuda(), + build_strategy=build_strategy, + ) + try: + os.stat(graph_viz_path) + except OSError: + self.assertFalse(True) if __name__ == '__main__': diff --git a/test/deprecated/legacy_test/test_psroi_pool_op.py b/test/deprecated/legacy_test/test_psroi_pool_op.py index f0becb25d3a94..15497d33a022c 100644 --- a/test/deprecated/legacy_test/test_psroi_pool_op.py +++ b/test/deprecated/legacy_test/test_psroi_pool_op.py @@ -375,7 +375,7 @@ def test_function_in_static(self): out = paddle.vision.ops.psroi_pool( self.x_placeholder, self.boxes_placeholder, - self.boxes_num, + paddle.to_tensor(self.boxes_num), output_size, ) expect_out = calc_psroi_pool( @@ -392,7 +392,7 @@ def test_function_in_static(self): (out_res,) = exe.run( paddle.static.default_main_program(), feed={'x': self.x, 'boxes': boxes_lod_data}, - fetch_list=[out.name], + fetch_list=[out], ) np.testing.assert_allclose(out_res, expect_out, rtol=1e-05) diff --git a/test/deprecated/legacy_test/test_slice_scatter.py b/test/deprecated/legacy_test/test_slice_scatter.py index bb46ddffb9b94..e319dd0318987 100644 --- a/test/deprecated/legacy_test/test_slice_scatter.py +++ b/test/deprecated/legacy_test/test_slice_scatter.py @@ -170,29 +170,38 @@ def init_dtype(self): class TestSliceScatterApiInt16(TestSliceScatterApi): def init_dtype(self): - # old ir `set_value` not support this dtype - if paddle.framework.in_dynamic_or_pir_mode(): - self.dtype = 'int16' - else: - self.dtype = 'float64' + self.dtype = 'int16' + + @test_with_pir_api + def test_api_static(self): + pass + + def test_api_dygraph(self): + super().test_api_dygraph() class TestSliceScatterApiInt8(TestSliceScatterApi): def init_dtype(self): - # old ir `set_value` not support this dtype - if paddle.framework.in_dynamic_or_pir_mode(): - self.dtype = 'int8' - else: - self.dtype = 'float64' + self.dtype = 'int8' + + @test_with_pir_api + def test_api_static(self): + pass + + def test_api_dygraph(self): + super().test_api_dygraph() class TestSliceScatterApiUint8(TestSliceScatterApi): def init_dtype(self): - # old ir `set_value` not support this dtype - if paddle.framework.in_dynamic_or_pir_mode(): - self.dtype = 'uint8' - else: - self.dtype = 'float64' + self.dtype = 'uint8' + + @test_with_pir_api + def test_api_static(self): + pass + + def test_api_dygraph(self): + super().test_api_dygraph() class TestSliceScatterApiBool(TestSliceScatterApi): @@ -202,11 +211,7 @@ def init_dtype(self): class TestSliceScatterApiBfloat16(TestSliceScatterApi): def init_dtype(self): - # old ir `set_value` not support this dtype - if paddle.framework.in_dynamic_or_pir_mode(): - self.dtype = 'bfloat16' - else: - self.dtype = 'float64' + self.dtype = 'bfloat16' class TestSliceScatterApiFloat16(TestSliceScatterApi): diff --git a/test/deprecated/legacy_test/test_tdm_child_op.py b/test/deprecated/legacy_test/test_tdm_child_op.py index 274795f01d5e1..5e67f334b226c 100644 --- a/test/deprecated/legacy_test/test_tdm_child_op.py +++ b/test/deprecated/legacy_test/test_tdm_child_op.py @@ -149,44 +149,45 @@ def config(self): class TestTDMChildShape(unittest.TestCase): def test_shape(self): with paddle_static_guard(): - x = paddle.static.data( - name='x', shape=[-1, 1], dtype='int32', lod_level=1 - ) - tdm_tree_info = create_tdm_tree() - tree_info_np = np.array(tdm_tree_info).astype('int32') - - child, leaf_mask = tdm_child( - x=x, - node_nums=26, - child_nums=2, - param_attr=base.ParamAttr( - initializer=paddle.nn.initializer.Assign(tree_info_np) - ), - ) - - place = base.CPUPlace() - exe = base.Executor(place=place) - exe.run(base.default_startup_program()) - - feed = { - 'x': np.array( - [ - [1], - [2], - [3], - [4], - [5], - [6], - [7], - [8], - [9], - [10], - [11], - [12], - ] - ).astype('int32') - } - exe.run(feed=feed) + with paddle.pir_utils.OldIrGuard(): + x = paddle.static.data( + name='x', shape=[-1, 1], dtype='int32', lod_level=1 + ) + tdm_tree_info = create_tdm_tree() + tree_info_np = np.array(tdm_tree_info).astype('int32') + + child, leaf_mask = tdm_child( + x=x, + node_nums=26, + child_nums=2, + param_attr=base.ParamAttr( + initializer=paddle.nn.initializer.Assign(tree_info_np) + ), + ) + + place = base.CPUPlace() + exe = base.Executor(place=place) + exe.run(base.default_startup_program()) + + feed = { + 'x': np.array( + [ + [1], + [2], + [3], + [4], + [5], + [6], + [7], + [8], + [9], + [10], + [11], + [12], + ] + ).astype('int32') + } + exe.run(feed=feed) if __name__ == "__main__":