From 6bccfbdcdfffe24bb7bd47d95c4fe0543bc78196 Mon Sep 17 00:00:00 2001 From: yjjiang11 Date: Tue, 6 Dec 2022 09:09:54 +0000 Subject: [PATCH 1/2] rm dygraph_to_static eager guard tests part2 minst2ptb_lm --- .../unittests/dygraph_to_static/test_mnist.py | 22 +++++++++---------- .../dygraph_to_static/test_mnist_amp.py | 3 +-- .../dygraph_to_static/test_mnist_pure_fp16.py | 3 +-- .../dygraph_to_static/test_mobile_net.py | 3 +-- .../dygraph_to_static/test_multi_forward.py | 4 +--- .../test_program_translator.py | 3 +-- .../dygraph_to_static/test_ptb_lm.py | 4 +--- 7 files changed, 16 insertions(+), 26 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist.py index d178370f546c4..49ef5f4a88046 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist.py @@ -25,7 +25,6 @@ from paddle.fluid.dygraph import to_variable from paddle.fluid.dygraph.base import switch_to_static_graph from paddle.fluid.dygraph.io import INFER_MODEL_SUFFIX, INFER_PARAMS_SUFFIX -from paddle.fluid.framework import _test_eager_guard from paddle.fluid.optimizer import AdamOptimizer from paddle.nn import Linear @@ -168,17 +167,16 @@ def test_mnist_to_static(self): dygraph_loss, static_loss ), ) - with _test_eager_guard(): - dygraph_loss = self.train_dygraph() - static_loss = self.train_static() - np.testing.assert_allclose( - dygraph_loss, - static_loss, - rtol=1e-05, - err_msg='dygraph is {}\n static_res is \n{}'.format( - dygraph_loss, static_loss - ), - ) + dygraph_loss = self.train_dygraph() + static_loss = self.train_static() + np.testing.assert_allclose( + dygraph_loss, + static_loss, + rtol=1e-05, + err_msg='dygraph is {}\n static_res is \n{}'.format( + dygraph_loss, static_loss + ), + ) def test_mnist_declarative_cpu_vs_mkldnn(self): dygraph_loss_cpu = self.train_dygraph() diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist_amp.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist_amp.py index 014062152903e..8dc16c0f458e9 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist_amp.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist_amp.py @@ -106,5 +106,4 @@ def train(self, to_static=False): if __name__ == '__main__': - with paddle.fluid.framework._test_eager_guard(): - unittest.main() + unittest.main() diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist_pure_fp16.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist_pure_fp16.py index 683d097cc9e19..39cdf40b03599 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist_pure_fp16.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist_pure_fp16.py @@ -120,5 +120,4 @@ def train(self, to_static=False): if __name__ == '__main__': - with paddle.fluid.framework._test_eager_guard(): - unittest.main() + unittest.main() diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mobile_net.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mobile_net.py index 06def97195e35..d464c4b1d13a7 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mobile_net.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mobile_net.py @@ -726,5 +726,4 @@ def verify_predict(self): if __name__ == '__main__': - with fluid.framework._test_eager_guard(): - unittest.main() + unittest.main() diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_multi_forward.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_multi_forward.py index 17a9a661dd44a..10039c4882a5c 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_multi_forward.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_multi_forward.py @@ -15,7 +15,6 @@ import unittest import paddle -import paddle.fluid as fluid class MyLayer(paddle.nn.Layer): @@ -63,5 +62,4 @@ def test_order_1(self): if __name__ == '__main__': - with fluid.framework._test_eager_guard(): - unittest.main() + unittest.main() diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_program_translator.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_program_translator.py index dd581526f4ec5..65d7d301cd5f4 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_program_translator.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_program_translator.py @@ -439,5 +439,4 @@ def test_remove_comment(self): if __name__ == '__main__': - with fluid.framework._test_eager_guard(): - unittest.main() + unittest.main() diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ptb_lm.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ptb_lm.py index 6f821265ca7f0..46970eaa27bb6 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ptb_lm.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_ptb_lm.py @@ -347,6 +347,4 @@ def test_check_result(self): if __name__ == '__main__': - # switch into new eager mode - with fluid.framework._test_eager_guard(): - unittest.main() + unittest.main() From 0bc739ad685d1a560459988141b1846d4af33b7a Mon Sep 17 00:00:00 2001 From: yjjiang11 Date: Wed, 7 Dec 2022 08:44:30 +0000 Subject: [PATCH 2/2] remove redudancy tests --- .../tests/unittests/dygraph_to_static/test_mnist.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist.py index 49ef5f4a88046..fb51474af5516 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_mnist.py @@ -167,16 +167,6 @@ def test_mnist_to_static(self): dygraph_loss, static_loss ), ) - dygraph_loss = self.train_dygraph() - static_loss = self.train_static() - np.testing.assert_allclose( - dygraph_loss, - static_loss, - rtol=1e-05, - err_msg='dygraph is {}\n static_res is \n{}'.format( - dygraph_loss, static_loss - ), - ) def test_mnist_declarative_cpu_vs_mkldnn(self): dygraph_loss_cpu = self.train_dygraph()