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

[xdoctest][task 337] reformat example code with google style in python/paddle/base/framework.py #57151

Merged
merged 6 commits into from
Sep 11, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions python/paddle/base/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

这里仍然使用 scalar 的话,基本不会走下面的分支的

>>> 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
Copy link
Member

Choose a reason for hiding this comment

The 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)
Copy link
Member

Choose a reason for hiding this comment

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

这个也要 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

😊是的,新的改好啦~

>>> with paddle.static.name_scope("s4"):
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -1664,7 +1665,7 @@ def clear_gradient(self):
.. code-block:: python

>>> import paddle
>>> import paddle.base as base
>>> import paddle.fluid as base
Copy link
Member

Choose a reason for hiding this comment

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

fluid?

>>> import numpy as np

>>> x = np.ones([2, 2], np.float32)
Expand All @@ -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

Expand Down