-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Conversation
Thanks for your contribution! |
There was a problem hiding this 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 ....
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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exapmle2 里不需要再定义一个函数了吧。
There was a problem hiding this comment.
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') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
THREE, FOUR是干嘛的?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
Others
PR changes
Docs
Describe
Update the demo code of
paddle.grad
. The pr of FluidDoc about paddle.grad.