未验证 提交 dbdeecd6 编写于 作者: H huangxu96 提交者: GitHub

Modify doc mistakes of grad API. (#29176)

上级 a5d13d59
...@@ -444,7 +444,6 @@ def grad(outputs, ...@@ -444,7 +444,6 @@ def grad(outputs,
.. code-block:: python .. code-block:: python
import paddle import paddle
paddle.disable_static()
def test_dygraph_grad(create_graph): def test_dygraph_grad(create_graph):
x = paddle.ones(shape=[1], dtype='float32') x = paddle.ones(shape=[1], dtype='float32')
...@@ -479,10 +478,9 @@ def grad(outputs, ...@@ -479,10 +478,9 @@ def grad(outputs,
.. code-block:: python .. code-block:: python
import paddle import paddle
paddle.disable_static()
def test_dygraph_grad(grad_outputs=None): 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 x.stop_gradient = False
y1 = x * x y1 = x * x
...@@ -505,8 +503,7 @@ def grad(outputs, ...@@ -505,8 +503,7 @@ def grad(outputs,
return dx.numpy() 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] # dy1 = [1], dy2 = [1]
print(test_dygraph_grad(None)) # [7.] print(test_dygraph_grad(None)) # [7.]
...@@ -517,7 +514,7 @@ def grad(outputs, ...@@ -517,7 +514,7 @@ def grad(outputs,
print(test_dygraph_grad([grad_value, None])) # [19.] print(test_dygraph_grad([grad_value, None])) # [19.]
# dy1 = [3], dy2 = [4] # 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.] print(test_dygraph_grad([grad_y1, grad_value])) # [24.]
''' '''
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册