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] reformat example code with google style in No.21-30 #55849

Merged
merged 14 commits into from
Aug 2, 2023
Merged

[xdoctest] reformat example code with google style in No.21-30 #55849

merged 14 commits into from
Aug 2, 2023

Conversation

ooooo-create
Copy link
Contributor

@ooooo-create ooooo-create commented Aug 1, 2023

PR types

Others

PR changes

Others

Description

修改如下文件的示例代码,使其通过 xdoctest 检查:

  • python/paddle/autograd/py_layer.py
  • python/paddle/autograd/saved_tensors_hooks.py
  • python/paddle/framework/dtype.py
  • python/paddle/framework/framework.py
  • python/paddle/framework/io.py
  • python/paddle/framework/io_utils.py
  • python/paddle/framework/random.py
  • python/paddle/nn/initializer/Bilinear.py
  • python/paddle/nn/initializer/assign.py
  • python/paddle/nn/initializer/constant.py

预览:

关联 PR:
#55629
#55295

@sunzhongkai588 @SigureMo @megemini

@paddle-bot
Copy link

paddle-bot bot commented Aug 1, 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 contributor External developers status: proposed labels Aug 1, 2023
@SigureMo SigureMo changed the title [Fix]XDoctest No.25,28-30 [xdoctest] reformat example code with google style in No.25,28-30 Aug 1, 2023
@ooooo-create ooooo-create changed the title [xdoctest] reformat example code with google style in No.25,28-30 [xdoctest] reformat example code with google style in No.21-30 Aug 1, 2023
@luotao1 luotao1 added the HappyOpenSource 快乐开源活动issue与PR label Aug 1, 2023
>>> z = cus_tanh.apply(data)
>>> z.mean().backward()

>>> print(data.grad)
Copy link
Contributor

Choose a reason for hiding this comment

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

如果有输出的话后面加上~

>>> print(data.grad)
Tensor(shape=[2, 3], dtype=float64, place=Place(cpu), stop_gradient=True,
[[0.16604150, 0.05858341, 0.14051214],
[0.15677770, 0.01564609, 0.02991660]])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

如果有输出的话后面加上~

>>> print(data.grad)
Tensor(shape=[2, 3], dtype=float64, place=Place(cpu), stop_gradient=True,
[[0.16604150, 0.05858341, 0.14051214],
[0.15677770, 0.01564609, 0.02991660]])

函数里有print,调用函数时会打印,这种需要写输出吗,python/paddle/autograd/saved_tensors_hooks.py中
` >>> # Example1
>>> import paddle

    >>> def pack_hook(x):
    ...     print("Packing", x)
    ...     return x.numpy()

    >>> def unpack_hook(x):
    ...     print("UnPacking", x)
    ...     return paddle.to_tensor(x)

    >>> a = paddle.ones([3,3])
    >>> b = paddle.ones([3,3]) * 2
    >>> a.stop_gradient = False
    >>> b.stop_gradient = False
    >>> with paddle.autograd.saved_tensors_hooks(pack_hook, unpack_hook):
    ...     y = paddle.multiply(a, b)
    >>> y.sum().backward()`

Copy link
Contributor

Choose a reason for hiding this comment

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

我觉得优先以原示例为准吧~ 如果原来有,就把新的输出改上去,如果没有就算了~

>>> path = "example/main_program.pdmodel"
>>> paddle.save(main_program, path)
>>> load_main = paddle.load(path)
>>> print(load_main)
Copy link
Contributor

Choose a reason for hiding this comment

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

这里感觉没有 print 的必要~ 去掉?

Comment on lines 50 to 51
regularizer=L2Decay(0.),
initializer=nn.initializer.Bilinear())
Copy link
Contributor

Choose a reason for hiding this comment

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

这两行加上 ... 这个前缀吧~

不加前缀 xdoctest 也能兼容,但指不定哪天不用 xdoctest 了,这就出问题了~

另外,这个文件不是用 convert-doctest 转换的?按理说应该可以自动加上前缀的,bug ? ... ...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里没有使用convert-doctest,纯属打漏了

Comment on lines 100 to 103
>>> print(linear.weight)
Tensor(shape=[2, 4], dtype=float32, place=Place(cpu), stop_gradient=False,
[[2., 2., 2., 2.],
[2., 2., 2., 2.]])
Copy link
Contributor

Choose a reason for hiding this comment

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

少了一行

Parameter containing:
Tensor(shape=[2, 4], dtype=float32, place=Place(cpu), stop_gradient=False,
[[2., 2., 2., 2.],
[2., 2., 2., 2.]])

import paddle
sts = paddle.get_rng_state()
>>> import paddle
>>> paddle.seed(2023)
Copy link
Member

Choose a reason for hiding this comment

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

这里也是有必要 seed 的么?是要固定什么的随机性呢?

import paddle
sts = paddle.get_cuda_rng_state()
>>> import paddle
>>> paddle.seed(2023)
Copy link
Member

Choose a reason for hiding this comment

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

同上

sts = paddle.get_rng_state()
paddle.set_rng_state(sts)
>>> import paddle
>>> paddle.seed(2023)
Copy link
Member

Choose a reason for hiding this comment

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

同上

sts = paddle.get_cuda_rng_state()
paddle.set_cuda_rng_state(sts)
>>> import paddle
>>> paddle.seed(2023)
Copy link
Member

Choose a reason for hiding this comment

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

同上

>>> w_attr = paddle.ParamAttr(learning_rate=0.,
... regularizer=L2Decay(0.),
... initializer=nn.initializer.Bilinear())
>>> paddle.seed(2023)
Copy link
Member

Choose a reason for hiding this comment

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

这里没输出也不需要固定 seed?

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 merged commit 5d26d79 into PaddlePaddle:develop Aug 2, 2023
@luotao1
Copy link
Contributor

luotao1 commented Aug 2, 2023

hi, @ooooo-create

  • 非常感谢你对飞桨框架的贡献,我们正在运营一个PFCC组织,会通过定期分享技术知识与发布开发者主导任务的形式持续为飞桨框架做贡献,详情可见 https://github.com/luotao1 主页说明。
  • 如果你对PFCC有兴趣,请发送邮件至 ext_paddle_oss@baidu.com,我们会邀请你加入~

@luotao1 luotao1 added HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 and removed HappyOpenSource 快乐开源活动issue与PR labels Aug 7, 2023
@ooooo-create ooooo-create deleted the xdoctest28-30 branch August 11, 2023 02:37
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