From 737fbdbac66bb4bba3b054ecde3aa44df249a984 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: Sun, 11 Dec 2022 23:10:16 -0800 Subject: [PATCH] rm unittests eager guard tests part5 dataloader2dygraph_mnist (#48816) --- .../unittests/test_dataloader_dataset.py | 22 +++---------------- .../tests/unittests/test_deform_conv2d.py | 9 -------- .../unittests/test_deformable_conv_op.py | 9 -------- .../tests/unittests/test_determinant_op.py | 5 ----- .../fluid/tests/unittests/test_diag_v2.py | 5 ----- .../fluid/tests/unittests/test_diagonal_op.py | 16 +++++--------- .../fluid/tests/unittests/test_diff_op.py | 7 ------ .../fluid/tests/unittests/test_digamma_op.py | 12 ---------- .../fluid/tests/unittests/test_dist_base.py | 11 ---------- .../unittests/test_dygraph_mnist_fp16.py | 3 --- 10 files changed, 8 insertions(+), 91 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_dataloader_dataset.py b/python/paddle/fluid/tests/unittests/test_dataloader_dataset.py index b174fd67b5..a0f14d1b93 100644 --- a/python/paddle/fluid/tests/unittests/test_dataloader_dataset.py +++ b/python/paddle/fluid/tests/unittests/test_dataloader_dataset.py @@ -17,12 +17,11 @@ import unittest import paddle import paddle.vision.transforms as transforms -from paddle.fluid.framework import _test_eager_guard from paddle.io import Dataset class TestDatasetAbstract(unittest.TestCase): - def func_test_main(self): + def test_main(self): dataset = Dataset() try: d = dataset[0] @@ -36,11 +35,6 @@ class TestDatasetAbstract(unittest.TestCase): except NotImplementedError: pass - def test_main(self): - with _test_eager_guard(): - self.func_test_main() - self.func_test_main() - class TestDatasetWithDiffOutputPlace(unittest.TestCase): def get_dataloader(self, num_workers): @@ -68,7 +62,7 @@ class TestDatasetWithDiffOutputPlace(unittest.TestCase): self.assertTrue(label.place.is_cpu_place()) break - def func_test_single_process(self): + def test_single_process(self): self.run_check_on_cpu() if paddle.is_compiled_with_cuda(): # Get (image, label) tuple from MNIST dataset @@ -80,12 +74,7 @@ class TestDatasetWithDiffOutputPlace(unittest.TestCase): self.assertTrue(label.place.is_cuda_pinned_place()) break - def test_single_process(self): - with _test_eager_guard(): - self.func_test_single_process() - self.func_test_single_process() - - def func_test_multi_process(self): + def test_multi_process(self): # DataLoader with multi-process mode is not supported on MacOs and Windows currently if sys.platform != 'darwin' and sys.platform != 'win32': self.run_check_on_cpu() @@ -99,11 +88,6 @@ class TestDatasetWithDiffOutputPlace(unittest.TestCase): self.assertTrue(label.place.is_cuda_pinned_place()) break - def test_multi_process(self): - with _test_eager_guard(): - self.func_test_multi_process() - self.func_test_multi_process() - if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_deform_conv2d.py b/python/paddle/fluid/tests/unittests/test_deform_conv2d.py index 304fbcf80a..7a5093f872 100644 --- a/python/paddle/fluid/tests/unittests/test_deform_conv2d.py +++ b/python/paddle/fluid/tests/unittests/test_deform_conv2d.py @@ -19,7 +19,6 @@ import numpy as np import paddle import paddle.nn.initializer as I -from paddle.fluid.framework import _test_eager_guard class TestDeformConv2D(TestCase): @@ -233,10 +232,6 @@ class TestDeformConv2D(TestCase): self.place = paddle.CUDAPlace(0) self._test_identity() - def test_identity_with_eager_guard(self): - with _test_eager_guard(): - self.test_identity() - class TestDeformConv2DFunctional(TestCase): batch_size = 4 @@ -544,10 +539,6 @@ class TestDeformConv2DFunctional(TestCase): self.place = paddle.CUDAPlace(0) self._test_identity() - def test_identity_with_eager_guard(self): - with _test_eager_guard(): - self.test_identity() - # testcases for DeformConv2D class TestDeformConv2DWithPadding(TestDeformConv2D): diff --git a/python/paddle/fluid/tests/unittests/test_deformable_conv_op.py b/python/paddle/fluid/tests/unittests/test_deformable_conv_op.py index 273eeeda28..e3bc04d414 100644 --- a/python/paddle/fluid/tests/unittests/test_deformable_conv_op.py +++ b/python/paddle/fluid/tests/unittests/test_deformable_conv_op.py @@ -18,7 +18,6 @@ import numpy as np from op_test import OpTest import paddle -from paddle.fluid.framework import _test_eager_guard paddle.enable_static() @@ -442,10 +441,6 @@ class TestModulatedDeformableConvInvalidInput(unittest.TestCase): self.assertRaises(ValueError, test_invalid_filter) - def test_error_with_eager_guard(self): - with _test_eager_guard(): - self.test_error() - class TestDeformConv2DAPI(unittest.TestCase): def test_api(self): @@ -484,10 +479,6 @@ class TestDeformConv2DAPI(unittest.TestCase): test_deform_conv2d_v2() - def test_api_with_eager_guard(self): - with _test_eager_guard(): - self.test_api() - if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_determinant_op.py b/python/paddle/fluid/tests/unittests/test_determinant_op.py index 7eff966e60..3ee4946762 100644 --- a/python/paddle/fluid/tests/unittests/test_determinant_op.py +++ b/python/paddle/fluid/tests/unittests/test_determinant_op.py @@ -18,7 +18,6 @@ import numpy as np from op_test import OpTest import paddle -from paddle.fluid.framework import _test_eager_guard paddle.enable_static() @@ -87,10 +86,6 @@ class TestDeterminantAPI(unittest.TestCase): np.testing.assert_allclose(out.numpy(), out_ref, rtol=0.001) paddle.enable_static() - def test_eager(self): - with _test_eager_guard(): - self.test_api_dygraph() - class TestSlogDeterminantOp(OpTest): def setUp(self): diff --git a/python/paddle/fluid/tests/unittests/test_diag_v2.py b/python/paddle/fluid/tests/unittests/test_diag_v2.py index 9c96661f6c..fefdf613fc 100644 --- a/python/paddle/fluid/tests/unittests/test_diag_v2.py +++ b/python/paddle/fluid/tests/unittests/test_diag_v2.py @@ -20,7 +20,6 @@ from op_test import OpTest import paddle import paddle.fluid as fluid from paddle.fluid import Program, program_guard -from paddle.fluid.framework import _test_eager_guard class TestDiagV2Op(OpTest): @@ -281,8 +280,6 @@ class TestDiagV2API(unittest.TestCase): def test_cpu(self): paddle.disable_static(place=paddle.fluid.CPUPlace()) self.run_imperative() - with _test_eager_guard(): - self.run_imperative() paddle.enable_static() @@ -295,8 +292,6 @@ class TestDiagV2API(unittest.TestCase): paddle.disable_static(place=paddle.fluid.CUDAPlace(0)) self.run_imperative() - with _test_eager_guard(): - self.run_imperative() paddle.enable_static() with fluid.program_guard(fluid.Program()): diff --git a/python/paddle/fluid/tests/unittests/test_diagonal_op.py b/python/paddle/fluid/tests/unittests/test_diagonal_op.py index cb35a3fce5..e8666ed514 100644 --- a/python/paddle/fluid/tests/unittests/test_diagonal_op.py +++ b/python/paddle/fluid/tests/unittests/test_diagonal_op.py @@ -18,7 +18,6 @@ import numpy as np from op_test import OpTest import paddle -from paddle.fluid.framework import _test_eager_guard paddle.enable_static() @@ -157,12 +156,11 @@ class TestDiagonalAPI(unittest.TestCase): def test_api_eager(self): paddle.disable_static(self.place) - with _test_eager_guard(): - x_tensor = paddle.to_tensor(self.x) - out = paddle.diagonal(x_tensor) - out2 = paddle.diagonal(x_tensor, offset=0, axis1=2, axis2=1) - out3 = paddle.diagonal(x_tensor, offset=1, axis1=0, axis2=1) - out4 = paddle.diagonal(x_tensor, offset=0, axis1=1, axis2=2) + x_tensor = paddle.to_tensor(self.x) + out = paddle.diagonal(x_tensor) + out2 = paddle.diagonal(x_tensor, offset=0, axis1=2, axis2=1) + out3 = paddle.diagonal(x_tensor, offset=1, axis1=0, axis2=1) + out4 = paddle.diagonal(x_tensor, offset=0, axis1=1, axis2=2) out_ref = np.diagonal(self.x) np.testing.assert_allclose(out.numpy(), out_ref, rtol=1e-08) out2_ref = np.diagonal(self.x, offset=0, axis1=2, axis2=1) @@ -174,10 +172,6 @@ class TestDiagonalAPI(unittest.TestCase): paddle.enable_static() - def test_api_eager_dygraph(self): - with _test_eager_guard(): - self.test_api_dygraph() - if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_diff_op.py b/python/paddle/fluid/tests/unittests/test_diff_op.py index 7df3f779ff..b89f7759a7 100644 --- a/python/paddle/fluid/tests/unittests/test_diff_op.py +++ b/python/paddle/fluid/tests/unittests/test_diff_op.py @@ -19,7 +19,6 @@ import numpy as np import paddle import paddle.fluid as fluid import paddle.fluid.core as core -from paddle.fluid.framework import _test_eager_guard class TestDiffOp(unittest.TestCase): @@ -75,9 +74,6 @@ class TestDiffOp(unittest.TestCase): self.assertTrue((out.numpy() == self.output).all(), True) def test_dygraph(self): - with _test_eager_guard(): - self.setUp() - self.func_dygraph() self.setUp() self.func_dygraph() @@ -145,9 +141,6 @@ class TestDiffOp(unittest.TestCase): raise RuntimeError("Check Diff Gradient Failed") def test_grad(self): - with _test_eager_guard(): - self.setUp() - self.func_grad() self.setUp() self.func_grad() diff --git a/python/paddle/fluid/tests/unittests/test_digamma_op.py b/python/paddle/fluid/tests/unittests/test_digamma_op.py index 3f876085df..10f0a420ed 100644 --- a/python/paddle/fluid/tests/unittests/test_digamma_op.py +++ b/python/paddle/fluid/tests/unittests/test_digamma_op.py @@ -21,7 +21,6 @@ from scipy.special import psi import paddle import paddle.fluid as fluid import paddle.static as static -from paddle.fluid.framework import _test_eager_guard class TestDigammaOp(OpTest): @@ -95,10 +94,6 @@ class TestDigammaAPI(unittest.TestCase): res = paddle.digamma(input_t).numpy() np.testing.assert_allclose(res, sc_res, rtol=1e-05) - def test_in_eager_dynamic_mode(self): - with _test_eager_guard(): - self.test_in_dynamic_mode() - def test_name_argument(self): with static.program_guard(static.Program()): x = static.data(name="x", shape=self._shape, dtype=self.dtypes[0]) @@ -119,13 +114,6 @@ class TestDigammaAPI(unittest.TestCase): input_t = paddle.to_tensor(input) res = paddle.digamma(input_t) - with self.assertRaises(RuntimeError): - with fluid.dygraph.guard(): - with _test_eager_guard(): - input = np.random.random(self._shape).astype("int32") - input_t = paddle.to_tensor(input) - res = paddle.digamma(input_t) - if __name__ == "__main__": unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_dist_base.py b/python/paddle/fluid/tests/unittests/test_dist_base.py index 57071583f1..a83c820652 100755 --- a/python/paddle/fluid/tests/unittests/test_dist_base.py +++ b/python/paddle/fluid/tests/unittests/test_dist_base.py @@ -30,7 +30,6 @@ import paddle.fluid as fluid import paddle.fluid.dygraph as dygraph import paddle.fluid.incubate.fleet.base.role_maker as role_maker from paddle.fluid import compiler -from paddle.fluid.framework import _test_eager_guard from paddle.fluid.incubate.fleet.collective import DistributedStrategy, fleet RUN_STEP = 5 @@ -1718,16 +1717,6 @@ class TestDistBase(unittest.TestCase): log_name="", ): if self._dygraph and (self._gloo_mode or self._nccl2_mode): - need_envs.update({"FLAGS_enable_eager_mode": "1"}) - with _test_eager_guard(): - self.check_with_place_func( - model_file=model_file, - delta=delta, - check_error_log=check_error_log, - need_envs=need_envs, - log_name=log_name, - ) - need_envs.update({"FLAGS_enable_eager_mode": "0"}) self.check_with_place_func( model_file=model_file, delta=delta, diff --git a/python/paddle/fluid/tests/unittests/test_dygraph_mnist_fp16.py b/python/paddle/fluid/tests/unittests/test_dygraph_mnist_fp16.py index 862b386802..9c0388d128 100644 --- a/python/paddle/fluid/tests/unittests/test_dygraph_mnist_fp16.py +++ b/python/paddle/fluid/tests/unittests/test_dygraph_mnist_fp16.py @@ -18,7 +18,6 @@ import numpy as np import paddle import paddle.fluid as fluid -from paddle.fluid.framework import _test_eager_guard from paddle.nn import Linear @@ -136,8 +135,6 @@ class TestMnist(unittest.TestCase): print(loss.numpy()) def test_mnist_fp16(self): - with _test_eager_guard(): - self.func_mnist_fp16() self.func_mnist_fp16() -- GitLab