From 627eaa0ffd2b1e10dfa0d2509074461d2c8a011e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A7=9C=E6=B0=B8=E4=B9=85?= <34344716+yjjiang11@users.noreply.github.com> Date: Tue, 13 Dec 2022 22:20:37 -0800 Subject: [PATCH] rm unittests eager guard tests part9 histogram2imperative_dataloader (#48825) * rm unittests eager guard tests part9 histogram2imperative_dataloader * rm basic --- .../tests/unittests/test_histogram_op.py | 17 ++- .../unittests/test_imperative_auto_prune.py | 105 +++--------------- .../test_imperative_container_layerdict.py | 15 +-- .../test_imperative_container_layerlist.py | 8 +- ...test_imperative_container_parameterlist.py | 4 - .../test_imperative_container_sequential.py | 15 +-- .../test_imperative_data_loader_base.py | 29 +---- .../test_imperative_data_loader_exception.py | 29 +---- .../test_imperative_data_loader_exit_func.py | 29 +---- .../test_imperative_data_loader_fds_clear.py | 15 +-- .../test_imperative_data_loader_process.py | 15 +-- 11 files changed, 45 insertions(+), 236 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_histogram_op.py b/python/paddle/fluid/tests/unittests/test_histogram_op.py index e9ebf10bc6875..71283aceaa403 100644 --- a/python/paddle/fluid/tests/unittests/test_histogram_op.py +++ b/python/paddle/fluid/tests/unittests/test_histogram_op.py @@ -20,7 +20,6 @@ import paddle import paddle.fluid as fluid from paddle.fluid import Program, program_guard -from paddle.fluid.framework import _test_eager_guard class TestHistogramOpAPI(unittest.TestCase): @@ -59,15 +58,13 @@ def test_dygraph(self): msg='histogram output is wrong, out =' + str(actual.numpy()), ) - with _test_eager_guard(): - inputs_np = np.array([[2, 4, 2], [2, 5, 4]]).astype(np.int64) - inputs = paddle.to_tensor(inputs_np) - actual = paddle.histogram(inputs, bins=5, min=1, max=5) - self.assertTrue( - (actual.numpy() == expected).all(), - msg='histogram output is wrong, out =' - + str(actual.numpy()), - ) + inputs_np = np.array([[2, 4, 2], [2, 5, 4]]).astype(np.int64) + inputs = paddle.to_tensor(inputs_np) + actual = paddle.histogram(inputs, bins=5, min=1, max=5) + self.assertTrue( + (actual.numpy() == expected).all(), + msg='histogram output is wrong, out =' + str(actual.numpy()), + ) class TestHistogramOpError(unittest.TestCase): diff --git a/python/paddle/fluid/tests/unittests/test_imperative_auto_prune.py b/python/paddle/fluid/tests/unittests/test_imperative_auto_prune.py index e4dca329fe7c2..2036ee83e95ad 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_auto_prune.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_auto_prune.py @@ -18,7 +18,6 @@ import paddle import paddle.fluid as fluid -from paddle.fluid.framework import _test_eager_guard from paddle.nn import Embedding from paddle.tensor import random @@ -169,7 +168,7 @@ def embed_linear0(self, x): class TestImperativeAutoPrune(unittest.TestCase): - def func_auto_prune(self): + def test_auto_prune(self): with fluid.dygraph.guard(): case1 = AutoPruneLayer0(input_size=5) value1 = np.arange(25).reshape(5, 5).astype("float32") @@ -181,12 +180,7 @@ def func_auto_prune(self): self.assertIsNotNone(case1.linear2.weight._grad_ivar()) self.assertIsNotNone(case1.linear1.weight._grad_ivar()) - def test_auto_prune(self): - with _test_eager_guard(): - self.func_auto_prune() - self.func_auto_prune() - - def func_auto_prune2(self): + def test_auto_prune2(self): with fluid.dygraph.guard(): case2 = AutoPruneLayer1(input_size=5) value1 = np.arange(25).reshape(5, 5).astype("float32") @@ -199,13 +193,9 @@ def func_auto_prune2(self): self.assertIsNone(case2.linear2.weight._grad_ivar()) self.assertIsNotNone(case2.linear1.weight._grad_ivar()) - def test_auto_prune2(self): - with _test_eager_guard(): - self.func_auto_prune2() - self.func_auto_prune2() - # TODO(jiabin): Support this when we support better split tensor - def func_auto_prune3(self): + def test_auto_prune3(self): + fluid.set_flags({"FLAGS_retain_grad_for_all_tensor": True}) with fluid.dygraph.guard(): case3 = AutoPruneLayer3(input_size=784) value1 = np.arange(784).reshape(1, 784).astype("float32") @@ -216,15 +206,10 @@ def func_auto_prune3(self): loss.backward() self.assertIsNotNone(case3.linear.weight._grad_ivar()) self.assertTrue((part2.gradient() == 0).all()) - - def test_auto_prune3(self): - fluid.set_flags({"FLAGS_retain_grad_for_all_tensor": True}) - with _test_eager_guard(): - self.func_auto_prune3() - self.func_auto_prune3() fluid.set_flags({"FLAGS_retain_grad_for_all_tensor": False}) - def func_auto_prune4(self): + def test_auto_prune4(self): + fluid.set_flags({"FLAGS_retain_grad_for_all_tensor": True}) with fluid.dygraph.guard(): case4 = AutoPruneLayer3(input_size=784) value1 = np.arange(784).reshape(1, 784).astype("float32") @@ -235,15 +220,10 @@ def func_auto_prune4(self): part2.backward() self.assertIsNotNone(case4.linear.weight._grad_ivar()) self.assertTrue((part2.gradient() == 1).all()) - - def test_auto_prune4(self): - fluid.set_flags({"FLAGS_retain_grad_for_all_tensor": True}) - with _test_eager_guard(): - self.func_auto_prune4() - self.func_auto_prune4() fluid.set_flags({"FLAGS_retain_grad_for_all_tensor": False}) - def func_auto_prune5(self): + def test_auto_prune5(self): + fluid.set_flags({"FLAGS_retain_grad_for_all_tensor": True}) with fluid.dygraph.guard(): case4 = AutoPruneLayer3(input_size=784) value1 = np.arange(784).reshape(1, 784).astype("float32") @@ -254,15 +234,9 @@ def func_auto_prune5(self): part1.backward() self.assertIsNotNone(case4.linear.weight._grad_ivar()) self.assertTrue((part2.gradient() == 0).all()) - - def test_auto_prune5(self): - fluid.set_flags({"FLAGS_retain_grad_for_all_tensor": True}) - with _test_eager_guard(): - self.func_auto_prune5() - self.func_auto_prune5() fluid.set_flags({"FLAGS_retain_grad_for_all_tensor": False}) - def func_auto_prune6(self): + def test_auto_prune6(self): with fluid.dygraph.guard(): value0 = np.arange(26).reshape(2, 13).astype("float32") value1 = np.arange(6).reshape(2, 3).astype("float32") @@ -280,12 +254,7 @@ def func_auto_prune6(self): self.assertIsNone(linear.weight.gradient()) self.assertIsNone(out1.gradient()) - def test_auto_prune6(self): - with _test_eager_guard(): - self.func_auto_prune6() - self.func_auto_prune6() - - def func_auto_prune7(self): + def test_auto_prune7(self): with fluid.dygraph.guard(): value0 = np.arange(26).reshape(2, 13).astype("float32") value1 = np.arange(6).reshape(2, 3).astype("float32") @@ -303,12 +272,7 @@ def func_auto_prune7(self): self.assertIsNone(linear.weight.gradient()) self.assertIsNone(out1.gradient()) - def test_auto_prune7(self): - with _test_eager_guard(): - self.func_auto_prune7() - self.func_auto_prune7() - - def func_auto_prune8(self): + def test_auto_prune8(self): with fluid.dygraph.guard(): value0 = np.arange(26).reshape(2, 13).astype("float32") value1 = np.arange(6).reshape(2, 3).astype("float32") @@ -336,12 +300,7 @@ def func_auto_prune8(self): np.array_equal(linear_origin, linear.weight.numpy()) ) - def test_auto_prune8(self): - with _test_eager_guard(): - self.func_auto_prune8() - self.func_auto_prune8() - - def func_auto_prune9(self): + def test_auto_prune9(self): with fluid.dygraph.guard(): value0 = np.arange(26).reshape(2, 13).astype("float32") value1 = np.arange(6).reshape(2, 3).astype("float32") @@ -371,12 +330,7 @@ def func_auto_prune9(self): except ValueError as e: assert type(e) == ValueError - def test_auto_prune9(self): - with _test_eager_guard(): - self.func_auto_prune9() - self.func_auto_prune9() - - def func_auto_prune10(self): + def test_auto_prune10(self): with fluid.dygraph.guard(): value0 = np.arange(26).reshape(2, 13).astype("float32") value1 = np.arange(6).reshape(2, 3).astype("float32") @@ -396,12 +350,7 @@ def func_auto_prune10(self): self.assertIsNone(linear.weight.gradient()) self.assertIsNone(out1.gradient()) - def test_auto_prune10(self): - with _test_eager_guard(): - self.func_auto_prune10() - self.func_auto_prune10() - - def func_auto_prune_with_optimizer(self): + def test_auto_prune_with_optimizer(self): vocab_size = 100 size = 20 batch_size = 16 @@ -451,12 +400,7 @@ def func_auto_prune_with_optimizer(self): assert model.embed1.weight._grad_ivar() is None assert model.linear_1.weight._grad_ivar() is None - def test_auto_prune_with_optimizer(self): - with _test_eager_guard(): - self.func_auto_prune_with_optimizer() - self.func_auto_prune_with_optimizer() - - def func_case2_prune_no_grad_branch(self): + def test_case2_prune_no_grad_branch(self): with fluid.dygraph.guard(): value1 = np.arange(784).reshape(1, 784) value2 = np.arange(1).reshape(1, 1) @@ -468,12 +412,7 @@ def func_case2_prune_no_grad_branch(self): self.assertIsNone(case3.linear2.weight._grad_ivar()) self.assertIsNotNone(case3.linear.weight._grad_ivar()) - def test_case2_prune_no_grad_branch(self): - with _test_eager_guard(): - self.func_case2_prune_no_grad_branch() - self.func_case2_prune_no_grad_branch() - - def func_case3_prune_no_grad_branch2(self): + def test_case3_prune_no_grad_branch2(self): with fluid.dygraph.guard(): value1 = np.arange(1).reshape(1, 1) linear = paddle.nn.Linear(1, 1) @@ -486,23 +425,13 @@ def func_case3_prune_no_grad_branch2(self): loss.backward() self.assertIsNone(linear.weight._grad_ivar()) - def test_case3_prune_no_grad_branch2(self): - with _test_eager_guard(): - self.func_case3_prune_no_grad_branch2() - self.func_case3_prune_no_grad_branch2() - - def func_case4_with_no_grad_op_maker(self): + def test_case4_with_no_grad_op_maker(self): with fluid.dygraph.guard(): out = random.gaussian(shape=[20, 30]) loss = paddle.mean(out) loss.backward() self.assertIsNone(out._grad_ivar()) - def test_case4_with_no_grad_op_maker(self): - with _test_eager_guard(): - self.func_case4_with_no_grad_op_maker() - self.func_case4_with_no_grad_op_maker() - if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_imperative_container_layerdict.py b/python/paddle/fluid/tests/unittests/test_imperative_container_layerdict.py index 0163ffcdaac5e..3a1bb1b4b1065 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_container_layerdict.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_container_layerdict.py @@ -16,11 +16,10 @@ from collections import OrderedDict import paddle -from paddle.fluid.framework import _test_eager_guard class TestLayerDict(unittest.TestCase): - def func_layer_dict(self): + def test_layer_dict(self): layers = OrderedDict( [ ('conv1d', paddle.nn.Conv1D(3, 2, 3)), @@ -92,12 +91,7 @@ def check_layer_dict(): layers_dicts.update(list_format_layers) check_layer_dict() - def test_layer_dict(self): - with _test_eager_guard(): - self.func_layer_dict() - self.func_layer_dict() - - def func_layer_dict_error_inputs(self): + def test_layer_dict_error_inputs(self): layers = [ ('conv1d', paddle.nn.Conv1D(3, 2, 3), "conv1d"), ('conv2d', paddle.nn.Conv2D(3, 2, 3)), @@ -108,11 +102,6 @@ def func_layer_dict_error_inputs(self): self.assertRaises(AssertionError, layers_dicts.update, 1) - def test_layer_dict_error_inputs(self): - with _test_eager_guard(): - self.func_layer_dict_error_inputs() - self.func_layer_dict_error_inputs() - if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_imperative_container_layerlist.py b/python/paddle/fluid/tests/unittests/test_imperative_container_layerlist.py index 0675a67193781..43230a90c5696 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_container_layerlist.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_container_layerlist.py @@ -18,7 +18,6 @@ import paddle import paddle.fluid as fluid -from paddle.fluid.framework import _test_eager_guard class MyLayer(fluid.Layer): @@ -94,15 +93,10 @@ def layer_list(self, use_fluid_api): self.assertListEqual(res11.shape, [5, 4]) res11.backward() - def func_test_layer_list(self): + def test_test_layer_list(self): self.layer_list(True) self.layer_list(False) - def test_layer_list(self): - with _test_eager_guard(): - self.func_test_layer_list() - self.func_test_layer_list() - if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_imperative_container_parameterlist.py b/python/paddle/fluid/tests/unittests/test_imperative_container_parameterlist.py index 763210361fe2f..ee6cbcb7b88be 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_container_parameterlist.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_container_parameterlist.py @@ -19,7 +19,6 @@ import paddle import paddle.fluid as fluid from paddle import _legacy_C_ops -from paddle.fluid.framework import _test_eager_guard class MyLayer(fluid.Layer): @@ -68,9 +67,6 @@ def paramter_list(self, use_fluid_api): loss.backward() def test_paramter_list(self): - with _test_eager_guard(): - self.paramter_list(False) - self.paramter_list(True) self.paramter_list(False) self.paramter_list(True) diff --git a/python/paddle/fluid/tests/unittests/test_imperative_container_sequential.py b/python/paddle/fluid/tests/unittests/test_imperative_container_sequential.py index 57f624e800998..32bdc0d099bf7 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_container_sequential.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_container_sequential.py @@ -18,12 +18,11 @@ import paddle import paddle.fluid as fluid -from paddle.fluid.framework import _test_eager_guard from paddle.nn import Linear class TestImperativeContainerSequential(unittest.TestCase): - def func_sequential(self): + def test_sequential(self): data = np.random.uniform(-1, 1, [5, 10]).astype('float32') with fluid.dygraph.guard(): data = fluid.dygraph.to_variable(data) @@ -57,12 +56,7 @@ def func_sequential(self): loss2 = paddle.mean(res2) loss2.backward() - def test_sequential(self): - with _test_eager_guard(): - self.func_sequential() - self.func_sequential() - - def func_sequential_list_params(self): + def test_sequential_list_params(self): data = np.random.uniform(-1, 1, [5, 10]).astype('float32') with fluid.dygraph.guard(): data = fluid.dygraph.to_variable(data) @@ -96,11 +90,6 @@ def func_sequential_list_params(self): loss2 = paddle.mean(res2) loss2.backward() - def test_sequential_list_params(self): - with _test_eager_guard(): - self.func_sequential_list_params() - self.func_sequential_list_params() - if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_imperative_data_loader_base.py b/python/paddle/fluid/tests/unittests/test_imperative_data_loader_base.py index 5a8b8ca532cec..5e503c51b50c7 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_data_loader_base.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_data_loader_base.py @@ -17,7 +17,6 @@ import numpy as np import paddle.fluid as fluid -from paddle.fluid.framework import _test_eager_guard from paddle.fluid.reader import use_pinned_memory @@ -51,7 +50,7 @@ def iter_loader_data(self, loader): self.assertEqual(label.shape, [self.batch_size, 1]) self.assertEqual(relu.shape, [self.batch_size, 784]) - def func_test_single_process_loader(self): + def test_single_process_loader(self): with fluid.dygraph.guard(): loader = fluid.io.DataLoader.from_generator( capacity=self.capacity, iterable=False, use_multiprocess=False @@ -63,12 +62,7 @@ def func_test_single_process_loader(self): ) self.iter_loader_data(loader) - def test_single_process_loader(self): - with _test_eager_guard(): - self.func_test_single_process_loader() - self.func_test_single_process_loader() - - def func_test_multi_process_loader(self): + def test_multi_process_loader(self): with fluid.dygraph.guard(): loader = fluid.io.DataLoader.from_generator( capacity=self.capacity, use_multiprocess=True @@ -80,12 +74,7 @@ def func_test_multi_process_loader(self): ) self.iter_loader_data(loader) - def test_multi_process_loader(self): - with _test_eager_guard(): - self.func_test_multi_process_loader() - self.func_test_multi_process_loader() - - def func_test_generator_no_places(self): + def test_generator_no_places(self): with fluid.dygraph.guard(): loader = fluid.io.DataLoader.from_generator(capacity=self.capacity) loader.set_sample_generator( @@ -94,12 +83,7 @@ def func_test_generator_no_places(self): ) self.iter_loader_data(loader) - def test_generator_no_places(self): - with _test_eager_guard(): - self.func_test_generator_no_places() - self.func_test_generator_no_places() - - def func_test_set_pin_memory(self): + def test_set_pin_memory(self): with fluid.dygraph.guard(): use_pinned_memory(False) loader = fluid.io.DataLoader.from_generator( @@ -113,11 +97,6 @@ def func_test_set_pin_memory(self): self.iter_loader_data(loader) use_pinned_memory(True) - def test_set_pin_memory(self): - with _test_eager_guard(): - self.func_test_set_pin_memory() - self.func_test_set_pin_memory() - if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_imperative_data_loader_exception.py b/python/paddle/fluid/tests/unittests/test_imperative_data_loader_exception.py index d7f6240c872c1..6986d9d7b50b5 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_data_loader_exception.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_data_loader_exception.py @@ -19,7 +19,6 @@ import paddle.fluid as fluid from paddle.fluid import core -from paddle.fluid.framework import _test_eager_guard def get_random_images_and_labels(image_shape, label_shape): @@ -35,19 +34,14 @@ def setUp(self): self.epoch_num = 1 self.capacity = 5 - def func_test_not_capacity(self): + def test_not_capacity(self): with fluid.dygraph.guard(): with self.assertRaisesRegexp( ValueError, "Please give value to capacity." ): fluid.io.DataLoader.from_generator() - def test_not_capacity(self): - with _test_eager_guard(): - self.func_test_not_capacity() - self.func_test_not_capacity() - - def func_test_single_process_with_thread_expection(self): + def test_single_process_with_thread_expection(self): def error_sample_genarator(batch_num): def __reader__(): for _ in range(batch_num): @@ -71,12 +65,7 @@ def __reader__(): exception = ex self.assertIsNotNone(exception) - def test_single_process_with_thread_expection(self): - with _test_eager_guard(): - self.func_test_single_process_with_thread_expection() - self.func_test_single_process_with_thread_expection() - - def func_test_multi_process_with_process_expection(self): + def test_multi_process_with_process_expection(self): def error_sample_genarator(batch_num): def __reader__(): for _ in range(batch_num): @@ -99,12 +88,7 @@ def __reader__(): exception = ex self.assertIsNotNone(exception) - def test_multi_process_with_process_expection(self): - with _test_eager_guard(): - self.func_test_multi_process_with_process_expection() - self.func_test_multi_process_with_process_expection() - - def func_test_multi_process_with_get_timeout(self): + def test_multi_process_with_get_timeout(self): def slow_batch_generator_creator(batch_size, batch_num): def __reader__(): for _ in range(batch_num): @@ -134,11 +118,6 @@ def __reader__(): exception = ex self.assertIsNotNone(exception) - def test_multi_process_with_get_timeout(self): - with _test_eager_guard(): - self.func_test_multi_process_with_get_timeout() - self.func_test_multi_process_with_get_timeout() - if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_imperative_data_loader_exit_func.py b/python/paddle/fluid/tests/unittests/test_imperative_data_loader_exit_func.py index 6d250676871b8..7dd95299639e4 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_data_loader_exit_func.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_data_loader_exit_func.py @@ -18,7 +18,6 @@ import time import unittest -from paddle.fluid.framework import _test_eager_guard from paddle.fluid.reader import ( CleanupFuncRegistrar, _cleanup, @@ -33,25 +32,20 @@ class TestDygraphDataLoaderCleanUpFunc(unittest.TestCase): def setUp(self): self.capacity = 10 - def func_test_clear_queue_set(self): + def test_clear_queue_set(self): test_queue = queue.Queue(self.capacity) multiprocess_queue_set.add(test_queue) for i in range(0, self.capacity): test_queue.put(i) _cleanup() - def test_clear_queue_set(self): - with _test_eager_guard(): - self.func_test_clear_queue_set() - self.func_test_clear_queue_set() - class TestRegisterExitFunc(unittest.TestCase): # This function does not need to be implemented in this case def none_func(self): pass - def func_test_not_callable_func(self): + def test_not_callable_func(self): exception = None try: CleanupFuncRegistrar.register(5) @@ -60,22 +54,12 @@ def func_test_not_callable_func(self): exception = ex self.assertIsNotNone(exception) - def test_not_callable_func(self): - with _test_eager_guard(): - self.func_test_not_callable_func() - self.func_test_not_callable_func() - - def func_test_old_handler_for_sigint(self): + def test_old_handler_for_sigint(self): CleanupFuncRegistrar.register( function=self.none_func, signals=[signal.SIGINT] ) - def test_old_handler_for_sigint(self): - with _test_eager_guard(): - self.func_test_old_handler_for_sigint() - self.func_test_old_handler_for_sigint() - - def func_test_signal_wrapper_by_sigchld(self): + def test_signal_wrapper_by_sigchld(self): # This function does not need to be implemented in this case def __test_process__(): pass @@ -93,11 +77,6 @@ def __test_process__(): exception = ex self.assertIsNotNone(exception) - def test_signal_wrapper_by_sigchld(self): - with _test_eager_guard(): - self.func_test_signal_wrapper_by_sigchld() - self.func_test_signal_wrapper_by_sigchld() - if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_imperative_data_loader_fds_clear.py b/python/paddle/fluid/tests/unittests/test_imperative_data_loader_fds_clear.py index 2bff5c9e3384b..d46df51de160b 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_data_loader_fds_clear.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_data_loader_fds_clear.py @@ -17,7 +17,6 @@ import numpy as np import paddle.fluid as fluid -from paddle.fluid.framework import _test_eager_guard from paddle.io import DataLoader, Dataset @@ -79,29 +78,19 @@ def run_one_epoch_with_break(self, loader): if step_id == 30: break - def func_test_data_loader_break(self): + def test_data_loader_break(self): with fluid.dygraph.guard(): loader = self.prepare_data_loader() for _ in range(self.epoch_num): self.run_one_epoch_with_break(loader) break - def test_data_loader_break(self): - with _test_eager_guard(): - self.func_test_data_loader_break() - self.func_test_data_loader_break() - - def func_test_data_loader_continue_break(self): + def test_data_loader_continue_break(self): with fluid.dygraph.guard(): loader = self.prepare_data_loader() for _ in range(self.epoch_num): self.run_one_epoch_with_break(loader) - def test_data_loader_continue_break(self): - with _test_eager_guard(): - self.func_test_data_loader_continue_break() - self.func_test_data_loader_continue_break() - class TestMultiProcessDataLoaderMmapFdsClear(TestDygraphDataLoaderMmapFdsClear): def prepare_data_loader(self): diff --git a/python/paddle/fluid/tests/unittests/test_imperative_data_loader_process.py b/python/paddle/fluid/tests/unittests/test_imperative_data_loader_process.py index 5cbb84c2f2c8b..a44c930f39605 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_data_loader_process.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_data_loader_process.py @@ -19,7 +19,6 @@ import numpy as np import paddle.fluid as fluid -from paddle.fluid.framework import _test_eager_guard from paddle.fluid.reader import _reader_process_loop @@ -49,7 +48,7 @@ def setUp(self): self.epoch_num = 2 self.capacity = 2 - def func_test_reader_process_loop(self): + def test_reader_process_loop(self): # This unittest's memory mapped files needs to be cleaned manually def __clear_process__(util_queue): while True: @@ -80,12 +79,7 @@ def __clear_process__(util_queue): ) clear_process.start() - def test_reader_process_loop(self): - with _test_eager_guard(): - self.func_test_reader_process_loop() - self.func_test_reader_process_loop() - - def func_test_reader_process_loop_simple_none(self): + def test_reader_process_loop_simple_none(self): def none_sample_genarator(batch_num): def __reader__(): for _ in range(batch_num): @@ -108,11 +102,6 @@ def __reader__(): exception = ex self.assertIsNotNone(exception) - def test_reader_process_loop_simple_none(self): - with _test_eager_guard(): - self.func_test_reader_process_loop_simple_none() - self.func_test_reader_process_loop_simple_none() - if __name__ == '__main__': unittest.main()