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 200] reformat example code with google style in python/paddle/tensor/creation.py #56685

Merged
merged 4 commits into from
Aug 29, 2023

Conversation

@paddle-bot
Copy link

paddle-bot bot commented Aug 26, 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 Aug 26, 2023
SigureMo
SigureMo previously approved these changes Aug 27, 2023
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 🐾

Copy link
Contributor

@megemini megemini left a comment

Choose a reason for hiding this comment

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

就是 clone 那里感觉有点奇怪,接口好像有变动 ~ 看看能不能改一下 ~

Comment on lines 2310 to 2321
>>> import paddle

x = paddle.ones([2])
x.stop_gradient = False
clone_x = paddle.clone(x)
>>> x = paddle.ones([2])
>>> x.stop_gradient = False
>>> clone_x = paddle.clone(x)

y = clone_x**3
y.backward()
print(clone_x.grad) # [3]
print(x.grad) # [3]
>>> y = clone_x**3
>>> y.backward()
>>> print(clone_x.grad)
None
>>> print(x.grad.numpy())
[3. 3.]
Copy link
Contributor

Choose a reason for hiding this comment

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

这段示例代码参考

def test_clone(self):
self.python_api = paddle.clone
x = paddle.ones([2])
x.stop_gradient = False
x.retain_grads()
clone_x = paddle.clone(x)
clone_x.retain_grads()
y = clone_x**3
y.backward()
np.testing.assert_array_equal(x, [1, 1])
np.testing.assert_array_equal(clone_x.grad.numpy(), [3, 3])
np.testing.assert_array_equal(x.grad.numpy(), [3, 3])
paddle.enable_static()

改一下吧 ~ 主要是加上 retain_grads ,不然有点反直觉 ~

pytorch 不加 retain_grad 会有 warning ,个人感觉这样用不太合适 ... ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

帮我看看改的对不对😍😍😍

Copy link
Contributor

Choose a reason for hiding this comment

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

不用这么麻烦,怪我 ~~~ 🤣

            >>> import paddle
            >>> x = paddle.ones([2])
            >>> x.stop_gradient = False
            >>> x.retain_grads()
            >>> clone_x = paddle.clone(x)
            >>> clone_x.retain_grads()
            >>> y = clone_x**3
            >>> y.backward()
            >>> print(clone_x.grad.numpy())
            [3. 3.]
            >>> print(x.grad.numpy())
            [3. 3.]

@luotao1 luotao1 added the HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 label Aug 28, 2023
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 🐾

@megemini 再看看呢?

Copy link
Contributor

@megemini megemini left a comment

Choose a reason for hiding this comment

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

LGTM ~ 赞!

@luotao1 luotao1 merged commit d64deaa into PaddlePaddle:develop Aug 29, 2023
@ooooo-create ooooo-create deleted the ooooo/xdoctest200 branch August 31, 2023 10:18
BeingGod pushed a commit to BeingGod/Paddle that referenced this pull request Sep 9, 2023
…on/paddle/tensor/creation.py` (PaddlePaddle#56685)

* [Doctest]fix No.200, test=docs_preview

* fix output

* add retain_grads

* fix style
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.

5 participants