-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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 paddle/tensor/math
#55768
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
❌ The PR is not created using PR's template. You can refer to this Demo. |
paddle/tensor/math
本 PR 用来测试新版的 另外看看在不同设备是否有「精度」问题 |
一些小的优化点 |
另外,输出信息里面有 不过,这都是小事儿,刚发现个问题, # Always warn when something bad is happening.
# However, dont error if the docstr simply has bad syntax
print('msg = {}'.format(msg))
warnings.warn(msg)
if isinstance(ex, exceptions.MalformedDocstr):
pass
elif isinstance(ex, exceptions.DoctestParseError):
pass
else:
raise 从而导致咱们的 [TestResult(name='Test docstring from: file *test_math_target.py* line number *591*.', nocode=True, passed=False, skipped=False, failed=False, time=-1, test_msg='', extra_info=None)] 这个咱们在 review 的时候要注意一下... ... |
啊这,从 |
嗯嗯,稍后我用新版再尝试几个,看是否还有别的优化点~ |
@megemini 果然有部分在本地和 CI 上有部分精度 diff 的,请问精度 diff 有什么比较好的处理方式嘛?直接忽略数值?前后包裹 |
不建议 skip ~ 这个问题其实有多种解决办法:
pytorch 的 round 已经可以设置保留小数了,paddle 的好像还不行?提个 PR ? 回到此次任务本身,可以考虑转为 numpy 进行 round 输出: 这是在什么设备上导致的问题?影响面大吗?我个人觉得,如果影响面不大,或者只是个别设备的话,可以针对这种设备赦免测试~ 你看咋整?! |
涉及到 API 的变动还是挺麻烦的
这个看起来确实是最好的,directive 可以自定义嘛,可以自己写一个嘛?有什么接口嘛?如果可以自定义我觉得是最好的~
也可以从 CI 上 copy 结果,但我觉得不是很好 这个设备的话,我是 M1 mac,和你都是 |
这个 ... ... 还得再看看 ~ 我觉得目前可能还真得手动 copy ,其他的几个办法(用 要么在 issue 里面写个注意事项? |
关于 float 输出匹配,我大致看了 https://stackoverflow.com/questions/2428618/how-to-test-floats-results-with-doctest 里的几个方案,其中 https://github.com/boisgera/numtest 是比较合适的方案,看起来是利用 monkey patch 将 doctest 的 OutputChecker 替换掉了,我们是否也能将 xdoctest 的检查代码(也许是这里?https://github.com/Erotemic/xdoctest/blob/main/src/xdoctest/checker.py#L201 )替换一下以实现 float 的匹配呢? 大致看了下 PyTorch,没发现使用什么特殊的 directive,不太清楚他们是怎么避免这个问题的,还是说他们没有设备之间计算精度的差异? |
已修改~ 不过,这种打补丁的方式真的不太好... ...
|
paddle/tensor/math
paddle/tensor/math
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM ~
修改本身没啥问题,但是,好像 renorm
的中文文档没有~
英文有:
http://preview-paddle-pr-55768.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/en/api/paddle/renorm_en.html
中文没有~
这只是一少部分~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
示例代码存在问题:
- nansum @SigureMo 修改下缩进
@sunzhongkai588 文档本身存在问题:
- scale
- logaddexp
- renorm(无中文文档)
- increment(中文typo)
- frexp(英文return格式)
>>> # scale with parameter scale as a Tensor | ||
>>> import paddle | ||
|
||
data = paddle.randn(shape=[2, 3], dtype='float32') | ||
factor = paddle.to_tensor([2], dtype='float32') | ||
res = paddle.scale(data, scale=factor, bias=1.0) | ||
>>> data = paddle.arange(6).astype("float32").reshape([2, 3]) | ||
>>> print(data) | ||
Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True, | ||
[[0., 1., 2.], | ||
[3., 4., 5.]]) | ||
>>> factor = paddle.to_tensor([2], dtype='float32') | ||
>>> res = paddle.scale(data, scale=factor, bias=1.0) | ||
>>> print(res) | ||
Tensor(shape=[2, 3], dtype=float32, place=Place(cpu), stop_gradient=True, | ||
[[1. , 3. , 5. ], | ||
[7. , 9. , 11.]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -703,7 +726,7 @@ def logaddexp(x, y, name=None): | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -919,14 +948,16 @@ def remainder(x, y, name=None): | |||
|
|||
Examples: | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remainder 这个api文档在预览里没找着..但我看__all__是有的呀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我记得 remainder 好像是另一个叫啥 API 的一个 alias(忘了是哪个了),也许和这个有关系
>>> import paddle | ||
|
||
>>> # x is a Tensor with following elements: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
就这一个的话我借一个 PR 改一下~
@@ -2156,17 +2290,19 @@ def renorm(x, p, axis, max_norm): | |||
Tensor: the renorm Tensor. | |||
|
|||
Examples: | |||
.. code-block:: python | |||
.. code-block:: python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
记一下:补充中文文档
PR types
Others
PR changes
Others
Description
修改如下文件的示例代码为新的格式,并通过
xdoctest
检查:python/paddle/tensor/math.py
预览:
@sunzhongkai588 @SigureMo @megemini
PCard-66962