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 335] reformat example code with google style in python/paddle/base/dygraph/tensor_patch_methods.py #57144

Merged
merged 3 commits into from
Sep 11, 2023

Conversation

yoyoIcy
Copy link
Contributor

@yoyoIcy yoyoIcy commented Sep 9, 2023

@paddle-bot
Copy link

paddle-bot bot commented Sep 9, 2023

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Sep 9, 2023
Comment on lines 253 to 278
>>> import paddle
>>> x = paddle.to_tensor(5., stop_gradient=False)
>>> for i in range(5):
... y = paddle.pow(x, 4.0)
... y.backward()
... print("{}: {}".format(i, x.grad))
0: [500.]
1: [1000.]
2: [1500.]
3: [2000.]
4: [2500.]

>>> x.clear_grad()
>>> print("{}".format(x.grad))
0.

>>> grad_tensor=paddle.to_tensor(2.)
>>> for i in range(5):
... y = paddle.pow(x, 4.0)
... y.backward(grad_tensor)
... print("{}: {}".format(i, x.grad))
0: [1000.]
1: [2000.]
2: [3000.]
3: [4000.]
4: [5000.]
Copy link
Contributor

Choose a reason for hiding this comment

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

输出是 Tensor

>>> y = paddle.pow(x, 4.0)
>>> y.backward()
>>> print("grad of x: {}".format(x.gradient()))
[500.]
Copy link
Contributor

Choose a reason for hiding this comment

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

输出不对~

Comment on lines 402 to 407
>>> print("w.grad:", w.grad)
w.grad: [1. 2. 3. 4.]
>>> print("x.grad:", x.grad)
x.grad: [ 4. 8. 12. 16.]
>>> print("y.grad:", y.grad)
y.grad: [2. 4. 6. 8.]
Copy link
Contributor

Choose a reason for hiding this comment

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

检查一下输出

Comment on lines 638 to 644
>>> import paddle
>>> x = paddle.rand([2, 5])
>>> print(x)

# Tensor(shape=[2, 5], dtype=float32, place=CPUPlace,
# [[0.30574632, 0.55739117, 0.30902600, 0.39413780, 0.44830436],
# [0.79010487, 0.53972793, 0.09495186, 0.44267157, 0.72112119]])
Tensor(shape=[2, 5], dtype=float32, place=CPUPlace,
[[0.30574632, 0.55739117, 0.30902600, 0.39413780, 0.44830436],
[0.79010487, 0.53972793, 0.09495186, 0.44267157, 0.72112119]])
Copy link
Contributor

Choose a reason for hiding this comment

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

加 seed ~ 用 cpu place ~

Comment on lines 662 to 668
>>> print(x)
Tensor(shape=[], dtype=float32, place=CPUPlace, stop_gradient=True,
2.)

>>> print(y)
Tensor(shape=[], dtype=float32, place=CPUPlace, stop_gradient=True,
2.)
Copy link
Contributor

Choose a reason for hiding this comment

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

place=Place(cpu)

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTMeow 🐾

@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Sep 11, 2023
@luotao1 luotao1 merged commit 5157175 into PaddlePaddle:develop Sep 11, 2023
@yoyoIcy yoyoIcy deleted the doc335 branch September 11, 2023 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants