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 No.80-85 #55806

Merged
merged 17 commits into from
Aug 3, 2023

Conversation

enkilee
Copy link
Contributor

@enkilee enkilee commented Jul 29, 2023

PR types

Others

PR changes

Others

Description

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

  • ./python/paddle/nn/functional/pooling.py
  • ./python/paddle/nn/functional/sparse_attention.py
  • ./python/paddle/nn/layer/activation.py
  • ./python/paddle/nn/layer/common.py
  • ./python/paddle/nn/layer/distance.py
  • ./python/paddle/nn/layer/layers.py

预览:

存在的问题:
比如GELU()的结果精度存在差异:
-0.15865529 和 -0.15865526,暂时等待解决办法

关联 PR:
#55629
#55295

@sunzhongkai588 @SigureMo @megemini

@paddle-bot
Copy link

paddle-bot bot commented Jul 29, 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 Jul 29, 2023
python/paddle/nn/layer/layers.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/layers.py Outdated Show resolved Hide resolved
@SigureMo
Copy link
Member

#55811 已经合入,精度问题应该是可以解决了,需要 merge 一下 develop 试一下

不过看样子还有些非精度问题,也需要看一下

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.

好多都改了阿 ~~~~

python/paddle/nn/layer/layers.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/layers.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/common.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/layers.py Outdated Show resolved Hide resolved
python/paddle/nn/functional/pooling.py Outdated Show resolved Hide resolved
@SigureMo SigureMo changed the title [Fix]XDoctest No.80-85 [xdoctest] reformat example code with google style No.80-85 Aug 1, 2023
python/paddle/nn/layer/common.py Outdated Show resolved Hide resolved
python/paddle/nn/functional/pooling.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/layers.py Outdated Show resolved Hide resolved
python/paddle/nn/functional/sparse_attention.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/layers.py Show resolved Hide resolved
python/paddle/nn/layer/layers.py Show resolved Hide resolved
python/paddle/nn/layer/layers.py Show resolved Hide resolved
python/paddle/nn/functional/sparse_attention.py Outdated Show resolved Hide resolved
python/paddle/nn/functional/sparse_attention.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/activation.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/activation.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/activation.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/activation.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/activation.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/activation.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/common.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/common.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/common.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/common.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/common.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/common.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/common.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/common.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/common.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/common.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/common.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/common.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/layers.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/layers.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/layers.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/layers.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/layers.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/layers.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/layers.py Outdated Show resolved Hide resolved
python/paddle/nn/layer/layers.py Outdated Show resolved Hide resolved
...
>>> model = Model()
>>> model.float16()
>>> #UserWarning: Paddle compiled by the user does not support float16, so keep original data type.
Copy link
Member

Choose a reason for hiding this comment

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

这里加的怎么感觉和原来的不是一个意思啊

@luotao1
Copy link
Contributor

luotao1 commented Aug 2, 2023

image 这是什么情况?

@SigureMo
Copy link
Member

SigureMo commented Aug 2, 2023

这是什么情况?

应该是中文分支名引发的,分支名应该不会影响合入

@enkilee
Copy link
Contributor Author

enkilee commented Aug 2, 2023

额,当时随手打了个中文,应该没影响吧

# [-1.25, 6. , 7. , -2. ],
# [ 6. , 7. , 8. , 9. ]]]]
>>> import paddle
>>> paddle.set_default_dtype("float64")
Copy link
Contributor

Choose a reason for hiding this comment

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

日志里fail的,应该都是这个导致的:

2023-08-02 11:44:04 14 sample codes ran failed
2023-08-02 11:44:04 <DocTest(<modname?> paddle.DataParallel.float16:1:0 ln 1)>
2023-08-02 11:44:04 <DocTest(<modname?> paddle.DataParallel.to:1:0 ln 1)>
2023-08-02 11:44:04 <DocTest(<modname?> paddle.nn.ReLU:1:0 ln 1)>
2023-08-02 11:44:04 <DocTest(<modname?> paddle.nn.ReLU6:1:0 ln 1)>
2023-08-02 11:44:04 <DocTest(<modname?> paddle.nn.SELU:1:0 ln 1)>
2023-08-02 11:44:04 <DocTest(<modname?> paddle.nn.Sigmoid:1:0 ln 1)>
2023-08-02 11:44:04 <DocTest(<modname?> paddle.nn.Silu:1:0 ln 1)>
2023-08-02 11:44:04 <DocTest(<modname?> paddle.nn.Softmax2D:1:0 ln 1)>
2023-08-02 11:44:04 <DocTest(<modname?> paddle.nn.Softshrink:1:0 ln 1)>
2023-08-02 11:44:04 <DocTest(<modname?> paddle.nn.Softsign:1:0 ln 1)>
2023-08-02 11:44:04 <DocTest(<modname?> paddle.nn.Swish:1:0 ln 1)>
2023-08-02 11:44:04 <DocTest(<modname?> paddle.nn.Tanh:1:0 ln 1)>
2023-08-02 11:44:04 <DocTest(<modname?> paddle.nn.Tanhshrink:1:0 ln 1)>
2023-08-02 11:44:04 <DocTest(<modname?> paddle.nn.ThresholdedReLU:1:0 ln 1)>

可以尝试在本地用 convert-doctest doctest 测试一下~

这里 paddle.set_default_dtype("float64") 导致后续都是以 float64 进行计算,从而与结果比对出错~

我在本地把 paddle.set_default_dtype("float64") 这行去掉可以过测~

建议把这行删掉,感觉没什么必要,PRelu 对精度也没什么特殊的要求~

@SigureMo 请帮忙看看~

Copy link
Member

Choose a reason for hiding this comment

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

这里 paddle.set_default_dtype("float64") 导致后续都是以 float64 进行计算,从而与结果比对出错~

是说一个示例代码的运行会影响其他示例代码?这会不会有点问题啊,比如之后可能有些 API 会 enable_static,那其他 API 会受到影响的

Copy link
Contributor

Choose a reason for hiding this comment

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

嗯,确实有!

xdoctest 的 doctest_example.py 你可以看一下~

它有一个 global_namespace 跟踪命名空间,每次执行测试都是先 _test_globals 获取全局变量,它自己也说 unclear side effects

image

每次执行后都有 self.global_namespace.clear() 防止 leak memory~

CI 的执行应该是按照字母排名的,导致 PRelu 之后的这些都 fail 了~

解决办法,xdoctest 有个 global_exec 目前的设置是:

XDOCTEST_CONFIG = {
    "global_exec": r"\n".join(
        [
            "import paddle",
            "paddle.device.set_device('cpu')",
        ]
    ),
    "default_runtime_state": {"IGNORE_WHITESPACE": True},
}

我觉得后面可以加个 set_default_dtype disable_static 之类的~

Copy link
Contributor

Choose a reason for hiding this comment

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

是说一个示例代码的运行会影响其他示例代码?这会不会有点问题啊,比如之后可能有些 API 会 enable_static,那其他 API 会受到影响的

嗯,更新一下 Xdoctesterglobal_exec 加上 set_default_dtype disable_static 之类的吧 ~

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 4ff6999 into PaddlePaddle:develop Aug 3, 2023
@luotao1 luotao1 added HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 and removed HappyOpenSource 快乐开源活动issue与PR labels Aug 7, 2023
@enkilee enkilee deleted the 引入xdoctest检查80-85 branch August 24, 2023 09:17
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