From 724d49da1844b8b4bd552c6381e5a9cd87d5abaf Mon Sep 17 00:00:00 2001 From: 0x45f <23097963+0x45f@users.noreply.github.com> Date: Mon, 17 Jan 2022 10:34:08 +0800 Subject: [PATCH] [Dy2St]close enable_inplace PASS for PE and open test_mnist_pure_fp16.py for windows (#38752) * close enable_inplace PASS for PE, and test dy2st pure fp16 training stability * add some comment * enlarge atol --- .../unittests/dygraph_to_static/test_mnist_pure_fp16.py | 8 ++++++-- .../unittests/dygraph_to_static/test_resnet_pure_fp16.py | 6 +++++- 2 files changed, 11 insertions(+), 3 deletions(-) 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 029e3e9a53..62878f5cfc 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 @@ -33,7 +33,7 @@ class TestPureFP16(TestMNIST): return self.train(to_static=False) def test_mnist_to_static(self): - if paddle.fluid.is_compiled_with_cuda() and os.name != 'nt': + if paddle.fluid.is_compiled_with_cuda(): dygraph_loss = self.train_dygraph() static_loss = self.train_static() # NOTE: In pure fp16 training, loss is not stable, so we enlarge atol here. @@ -52,7 +52,11 @@ class TestPureFP16(TestMNIST): if to_static: print("Successfully to apply @to_static.") - mnist = paddle.jit.to_static(mnist) + build_strategy = paddle.static.BuildStrategy() + # Why set `build_strategy.enable_inplace = False` here? + # Because we find that this PASS strategy of PE makes dy2st training loss unstable. + build_strategy.enable_inplace = False + mnist = paddle.jit.to_static(mnist, build_strategy=build_strategy) optimizer = paddle.optimizer.Adam( learning_rate=0.001, parameters=mnist.parameters()) diff --git a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_resnet_pure_fp16.py b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_resnet_pure_fp16.py index 6620703ab7..cf5c2b7311 100644 --- a/python/paddle/fluid/tests/unittests/dygraph_to_static/test_resnet_pure_fp16.py +++ b/python/paddle/fluid/tests/unittests/dygraph_to_static/test_resnet_pure_fp16.py @@ -106,7 +106,11 @@ def train(to_static, build_strategy=None): class TestResnet(unittest.TestCase): def train(self, to_static): program_translator.enable(to_static) - return train(to_static) + build_strategy = paddle.static.BuildStrategy() + # Why set `build_strategy.enable_inplace = False` here? + # Because we find that this PASS strategy of PE makes dy2st training loss unstable. + build_strategy.enable_inplace = False + return train(to_static, build_strategy) def test_resnet(self): if fluid.is_compiled_with_cuda(): -- GitLab