-
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
[xdoctest][task 337] reformat example code with google style in python/paddle/base/framework.py
#57151
[xdoctest][task 337] reformat example code with google style in python/paddle/base/framework.py
#57151
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1006,10 +1006,10 @@ def name_scope(prefix=None): | |
>>> with paddle.static.name_scope("s1"): | ||
... a = paddle.static.data(name='data', shape=[None, 1], dtype='int32') | ||
... b = a + 1 | ||
>>> with paddle.static.name_scope("s2"): | ||
... c = b * 1 | ||
>>> with paddle.static.name_scope("s3"): | ||
... d = c / 1 | ||
... with paddle.static.name_scope("s2"): | ||
... c = b * 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 下面这几个也需要改哦 |
||
... with paddle.static.name_scope("s3"): | ||
... d = c / 1 | ||
>>> with paddle.static.name_scope("s1"): | ||
... f = paddle.tensor.pow(d, 2.0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个也要 😂 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😊是的,新的改好啦~ |
||
>>> with paddle.static.name_scope("s4"): | ||
|
@@ -1538,7 +1538,7 @@ def numpy(self): | |
|
||
>>> import paddle.base as base | ||
>>> from paddle.base.dygraph.base import to_variable | ||
>>> from paddle.base.dygraph import Linear | ||
>>> from paddle.nn import Linear | ||
>>> import numpy as np | ||
|
||
>>> data = np.random.uniform(-1, 1, [30, 10, 32]).astype('float32') | ||
|
@@ -1628,6 +1628,7 @@ def gradient(self): | |
... inputs2.append(tmp) | ||
... ret2 = paddle.add_n(inputs2) | ||
... loss2 = paddle.sum(ret2) | ||
... loss2.retain_grads() | ||
... loss2.backward() | ||
... print(loss2.gradient()) | ||
|
||
|
@@ -1664,7 +1665,7 @@ def clear_gradient(self): | |
.. code-block:: python | ||
|
||
>>> import paddle | ||
>>> import paddle.base as base | ||
>>> import paddle.fluid as base | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fluid? |
||
>>> import numpy as np | ||
|
||
>>> x = np.ones([2, 2], np.float32) | ||
|
@@ -1676,11 +1677,13 @@ def clear_gradient(self): | |
... inputs2.append(tmp) | ||
... ret2 = paddle.add_n(inputs2) | ||
... loss2 = paddle.sum(ret2) | ||
... loss2.retain_grads() | ||
... loss2.backward() | ||
... print(loss2.gradient()) | ||
... loss2.clear_gradient() | ||
... print("After clear {}".format(loss2.gradient())) | ||
|
||
1.0 | ||
After clear 0.0 | ||
""" | ||
pass | ||
|
||
|
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.
这里仍然使用 scalar 的话,基本不会走下面的分支的