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 029e3e9a535b6faff4d246482928d94b6017238f..62878f5cfc93dfb413ac7a78a5c4919a541935ac 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 6620703ab71823051f8b0f4b23237f7df588a4e3..cf5c2b731141fa993f81de0f957b828178a01760 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():