From d4a97673cf7c52c728b09c32bd11ceaa2efadba4 Mon Sep 17 00:00:00 2001 From: huangxu96 <46740794+huangxu96@users.noreply.github.com> Date: Wed, 2 Dec 2020 17:00:27 +0800 Subject: [PATCH] Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into grad_doc (#29246) --- python/paddle/fluid/dygraph/base.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/python/paddle/fluid/dygraph/base.py b/python/paddle/fluid/dygraph/base.py index 76f4a74dd30..5868c9d078c 100644 --- a/python/paddle/fluid/dygraph/base.py +++ b/python/paddle/fluid/dygraph/base.py @@ -444,7 +444,6 @@ def grad(outputs, .. code-block:: python import paddle - paddle.disable_static() def test_dygraph_grad(create_graph): x = paddle.ones(shape=[1], dtype='float32') @@ -479,10 +478,9 @@ def grad(outputs, .. code-block:: python import paddle - paddle.disable_static() def test_dygraph_grad(grad_outputs=None): - x = paddle.fluid.layers.fill_constant(shape=[1], value=2.0, dtype='float32') + x = paddle.to_tensor(2.0) x.stop_gradient = False y1 = x * x @@ -505,8 +503,7 @@ def grad(outputs, return dx.numpy() - grad_value = paddle.fluid.layers.fill_constant(shape=[1], value=4.0, dtype='float32') - + grad_value = paddle.to_tensor(4.0) # dy1 = [1], dy2 = [1] print(test_dygraph_grad(None)) # [7.] @@ -517,7 +514,7 @@ def grad(outputs, print(test_dygraph_grad([grad_value, None])) # [19.] # dy1 = [3], dy2 = [4] - grad_y1 = paddle.fluid.layers.fill_constant(shape=[1], value=3.0, dtype='float32') + grad_y1 = paddle.to_tensor(3.0) print(test_dygraph_grad([grad_y1, grad_value])) # [24.] ''' -- GitLab