Modify doc mistakes of grad API. (#29176)

revert-31562-mean
huangxu96 4 years ago committed by GitHub
parent a5d13d593c
commit dbdeecd665
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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.]
'''

Loading…
Cancel
Save