Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the demo of paddle.grad #26498

Merged
merged 2 commits into from
Aug 22, 2020
Merged

Update the demo of paddle.grad #26498

merged 2 commits into from
Aug 22, 2020

Conversation

wzzju
Copy link
Contributor

@wzzju wzzju commented Aug 20, 2020

PR types

Others

PR changes

Docs

Describe

Update the demo code of paddle.grad. The pr of FluidDoc about paddle.grad.
image
image
image

@paddle-bot-old
Copy link

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

Copy link
Contributor

@willthefrog willthefrog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe simplify the examples a bit, something like this should suffice

x = paddle.ones(shape=[1], dtype='float32')
x.stop_gradient = False
y = x * x

dx = paddle.grad(
        outputs=[y],
        inputs=[x],
        create_graph=create_graph,
        retain_graph=True)[0]

print(dx)
# value should be ....

@wzzju
Copy link
Contributor Author

wzzju commented Aug 21, 2020

maybe simplify the examples a bit, something like this should suffice

x = paddle.ones(shape=[1], dtype='float32')
x.stop_gradient = False
y = x * x

dx = paddle.grad(
        outputs=[y],
        inputs=[x],
        create_graph=create_graph,
        retain_graph=True)[0]

print(dx)
# value should be ....

Thanks for your advice. These example codes here are usefully, better left unchanged.

z.backward()
return x.gradient()

print(test_dygraph_grad(create_graph=False)) # [2.]
print(test_dygraph_grad(create_graph=True)) # [4.]

Examples 2:
.. code-block:: python

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exapmle2 里不需要再定义一个函数了吧。

Copy link
Contributor Author

@wzzju wzzju Aug 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢。为了展示参数不同时不同的调用效果(代码复用),所以在example代码中定义了函数。

THREE = fluid.layers.fill_constant(shape=[1], value=3.0, dtype='float32')
FOUR = fluid.layers.fill_constant(shape=[1], value=4.0, dtype='float32')
THREE = paddle.fill_constant(shape=[1], value=3.0, dtype='float32')
FOUR = paddle.fill_constant(shape=[1], value=4.0, dtype='float32')

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THREE, FOUR是干嘛的?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have changed the var name. Thanks.

Copy link
Contributor

@jzhang533 jzhang533 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@willthefrog willthefrog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wzzju wzzju merged commit c037d62 into PaddlePaddle:develop Aug 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants