diff --git a/python/paddle/fluid/initializer.py b/python/paddle/fluid/initializer.py index ba5e51c11dd65b827d2c3ee5dcaceb6c53667ec3..1c8e39943662552a47725b3e11d4833eeb8d317a 100644 --- a/python/paddle/fluid/initializer.py +++ b/python/paddle/fluid/initializer.py @@ -353,7 +353,6 @@ class NormalInitializer(Initializer): out_var = _C_ops.final_state_gaussian_random( var.shape, self._mean, self._std_dev, self._seed, out_dtype, place) - out_var._share_underline_tensor_to(var) if var.dtype in [VarDesc.VarType.FP16, VarDesc.VarType.BF16]: var_tmp = _C_ops.final_state_cast(out_var, var.dtype) 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 7503a9172fc21bc343011d39c4c785daab9a1d7f..6c2516d6c11efc584268440f84f0d737414bdf68 100644 --- a/python/paddle/fluid/tests/unittests/test_dygraph_mnist_fp16.py +++ b/python/paddle/fluid/tests/unittests/test_dygraph_mnist_fp16.py @@ -19,6 +19,7 @@ import numpy as np import paddle.fluid as fluid from paddle.fluid.dygraph.nn import Conv2D, Pool2D, Linear +from paddle.fluid.framework import _test_eager_guard class SimpleImgConvPool(fluid.dygraph.Layer): @@ -117,7 +118,7 @@ class MNIST(fluid.dygraph.Layer): class TestMnist(unittest.TestCase): - def test_mnist_fp16(self): + def func_mnist_fp16(self): if not fluid.is_compiled_with_cuda(): return x = np.random.randn(1, 3, 224, 224).astype("float16") @@ -129,6 +130,11 @@ class TestMnist(unittest.TestCase): loss = model(x, y) print(loss.numpy()) + def test_mnist_fp16(self): + with _test_eager_guard(): + self.func_mnist_fp16() + self.func_mnist_fp16() + if __name__ == "__main__": unittest.main()