From d808f160ae965a63697e7eebda70f5dda5aea009 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: Wed, 14 Dec 2022 17:04:09 -0800 Subject: [PATCH] rm eager guard tests part3_1 (#49059) --- .../fluid/tests/unittests/test_cast_op.py | 20 ++++++++---------- .../fluid/tests/unittests/test_clip_op.py | 21 +++++++------------ .../fluid/tests/unittests/test_complex_abs.py | 5 ----- .../tests/unittests/test_complex_cast.py | 7 ------- .../test_complex_elementwise_layers.py | 7 ------- .../tests/unittests/test_complex_getitem.py | 10 --------- 6 files changed, 16 insertions(+), 54 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/test_cast_op.py b/python/paddle/fluid/tests/unittests/test_cast_op.py index 96ad3246f41b6..bb88d1cc53505 100644 --- a/python/paddle/fluid/tests/unittests/test_cast_op.py +++ b/python/paddle/fluid/tests/unittests/test_cast_op.py @@ -24,7 +24,6 @@ import paddle.fluid.core as core import paddle.fluid.layers as layers from paddle.fluid import Program, program_guard -from paddle.fluid.framework import _test_eager_guard class TestCastOpFp32ToFp64(OpTest): @@ -122,16 +121,15 @@ def test_errors(self): class TestCastOpEager(unittest.TestCase): def test_eager(self): with paddle.fluid.dygraph.base.guard(): - with _test_eager_guard(): - x = paddle.ones([2, 2], dtype="float16") - x.stop_gradient = False - out = paddle.cast(x, "float32") - np.testing.assert_array_equal( - out, np.ones([2, 2]).astype('float32') - ) - out.backward() - np.testing.assert_array_equal(x.gradient(), x.numpy()) - self.assertTrue(x.gradient().dtype == np.float16) + x = paddle.ones([2, 2], dtype="float16") + x.stop_gradient = False + out = paddle.cast(x, "float32") + np.testing.assert_array_equal( + out, np.ones([2, 2]).astype('float32') + ) + out.backward() + np.testing.assert_array_equal(x.gradient(), x.numpy()) + self.assertTrue(x.gradient().dtype == np.float16) class TestCastDoubleGradCheck(unittest.TestCase): diff --git a/python/paddle/fluid/tests/unittests/test_clip_op.py b/python/paddle/fluid/tests/unittests/test_clip_op.py index e6056c5012481..a25edccb97a4e 100644 --- a/python/paddle/fluid/tests/unittests/test_clip_op.py +++ b/python/paddle/fluid/tests/unittests/test_clip_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 TestClipOp(OpTest): @@ -231,7 +230,7 @@ def test_clip(self): ) paddle.disable_static() - def func_clip_dygraph(self): + def test_clip_dygraph(self): paddle.disable_static() place = ( fluid.CUDAPlace(0) @@ -279,20 +278,14 @@ def func_clip_dygraph(self): out_6.numpy(), data.clip(0.2, 0.8), rtol=1e-05 ) - def test_clip_dygraph(self): - with _test_eager_guard(): - self.func_clip_dygraph() - self.func_clip_dygraph() - def test_clip_dygraph_default_max(self): paddle.disable_static() - with _test_eager_guard(): - x_int32 = paddle.to_tensor([1, 2, 3], dtype="int32") - x_int64 = paddle.to_tensor([1, 2, 3], dtype="int64") - x_f32 = paddle.to_tensor([1, 2, 3], dtype="float32") - egr_out1 = paddle.clip(x_int32, min=1) - egr_out2 = paddle.clip(x_int64, min=1) - egr_out3 = paddle.clip(x_f32, min=1) + x_int32 = paddle.to_tensor([1, 2, 3], dtype="int32") + x_int64 = paddle.to_tensor([1, 2, 3], dtype="int64") + x_f32 = paddle.to_tensor([1, 2, 3], dtype="float32") + egr_out1 = paddle.clip(x_int32, min=1) + egr_out2 = paddle.clip(x_int64, min=1) + egr_out3 = paddle.clip(x_f32, min=1) x_int32 = paddle.to_tensor([1, 2, 3], dtype="int32") x_int64 = paddle.to_tensor([1, 2, 3], dtype="int64") x_f32 = paddle.to_tensor([1, 2, 3], dtype="float32") diff --git a/python/paddle/fluid/tests/unittests/test_complex_abs.py b/python/paddle/fluid/tests/unittests/test_complex_abs.py index 8d21f76d64ff9..45b4ed74a67d7 100644 --- a/python/paddle/fluid/tests/unittests/test_complex_abs.py +++ b/python/paddle/fluid/tests/unittests/test_complex_abs.py @@ -19,7 +19,6 @@ import paddle import paddle.fluid.dygraph as dg -from paddle.fluid.framework import _test_eager_guard class TestComplexAbsOp(OpTest): @@ -109,10 +108,6 @@ def test_all_positive(self): y = paddle.abs(paddle.to_tensor(x)) np.testing.assert_allclose(np.abs(x), y.numpy(), rtol=1e-05) - def test_eager(self): - with _test_eager_guard(): - self.test_all_positive() - class TestRealAbsOp(OpTest): def setUp(self): diff --git a/python/paddle/fluid/tests/unittests/test_complex_cast.py b/python/paddle/fluid/tests/unittests/test_complex_cast.py index 8302ba585856b..348bd8a332f5e 100644 --- a/python/paddle/fluid/tests/unittests/test_complex_cast.py +++ b/python/paddle/fluid/tests/unittests/test_complex_cast.py @@ -17,7 +17,6 @@ import numpy as np import paddle -from paddle.fluid.framework import _test_eager_guard class TestComplexCastOp(unittest.TestCase): @@ -80,12 +79,6 @@ def test_complex64_complex128(self): c_128.cast('complex128').numpy(), c_64.numpy(), rtol=1e-05 ) - def test_eager(self): - with _test_eager_guard(): - self.test_complex64_complex128() - self.test_real_to_complex() - self.test_complex_to_real() - if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_complex_elementwise_layers.py b/python/paddle/fluid/tests/unittests/test_complex_elementwise_layers.py index 98a95eb37a099..8180d7a5c035e 100644 --- a/python/paddle/fluid/tests/unittests/test_complex_elementwise_layers.py +++ b/python/paddle/fluid/tests/unittests/test_complex_elementwise_layers.py @@ -20,7 +20,6 @@ import paddle import paddle.fluid as fluid import paddle.fluid.dygraph as dg -from paddle.fluid.framework import _test_eager_guard paddle_apis = { "add": paddle.add, @@ -112,12 +111,6 @@ def test_real_x_complex_y(self): self.compare_by_basic_api(x, y) self.compare_op_by_basic_api(x, y) - def test_eager(self): - with _test_eager_guard(): - self.test_real_x_complex_y() - self.test_complex_x_real_y() - self.test_complex_xy() - if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/tests/unittests/test_complex_getitem.py b/python/paddle/fluid/tests/unittests/test_complex_getitem.py index 09aca3b060f30..1bce833e78aed 100644 --- a/python/paddle/fluid/tests/unittests/test_complex_getitem.py +++ b/python/paddle/fluid/tests/unittests/test_complex_getitem.py @@ -18,7 +18,6 @@ import paddle.fluid as fluid import paddle.fluid.dygraph as dg -from paddle.fluid.framework import _test_eager_guard class TestComplexGetitemLayer(unittest.TestCase): @@ -95,15 +94,6 @@ def test_case6(self): np.testing.assert_allclose(x_var_slice.numpy(), x_np_slice) - def test_eager(self): - with _test_eager_guard(): - self.test_case1() - self.test_case2() - self.test_case3() - self.test_case4() - self.test_case5() - self.test_case6() - if __name__ == '__main__': unittest.main()