Skip to content

修改 COPY-FROM No.6 metric #54879

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

Closed

Conversation

RedContritio
Copy link
Contributor

@RedContritio RedContritio commented Jun 26, 2023

PR types

Others

PR changes

Docs

Description

更新 paddle.metric 中部分类与接口的 docstring,使支持新的中文文档生成方式。

@paddle-bot
Copy link

paddle-bot bot commented Jun 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.

@RedContritio
Copy link
Contributor Author

@sunzhongkai588

paddle.metric.Metric_example_1.pypaddle.metric.Metric_example_2.py 都是代码片段,所以无法运行,除非进行修改。

paddle.metric.Accuracy_example_2.py 包含训练过程,因此超过 10s 运行。

能否豁免 Static-Check

@@ -96,7 +97,8 @@ def compute(pred, label):
shape as [N, 5] instead of 2 tensors with shapes as [N, 10] and [N, 1].
:code:`update` can be define as follows:

.. code-block:: text
.. code-block:: python
:name: code-update-example

def update(self, correct):
accs = []
Copy link
Member

Choose a reason for hiding this comment

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

paddle.metric.Metric_example_1.pypaddle.metric.Metric_example_2.py 都是代码片段,所以无法运行,除非进行修改。

按理说这样的函数没有调用不可能会出问题的,这里是解析出现了问题

image

@megemini 可否麻烦有时间看一下这里为什么解析出了问题呢?按理说这里不应该少这个缩进

Copy link
Contributor

Choose a reason for hiding this comment

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

问题是 extract_code_blocks_from_docstr 里面的这个 inspect.cleandoc 方法导致的。

参考 PEP 257 – Docstring Conventions

inspect.cleandoc 这个方法本来不是为 code 准备的,而是为 docstring 使用的。

而,docstring 中,默认第一行的缩进是无意义的:

Docstring processing tools will strip a uniform amount of indentation from the second and further lines of the docstring, equal to the minimum indentation of all non-blank lines after the first line. Any indentation in the first line of the docstring (i.e., up to the first newline) is insignificant and removed. Relative indentation of later lines in the docstring is retained.

也就是说,这个方法是按照第二行的缩进进行删减的,从而导致,如下的代码块可以正常解析:

In [80]: f
Out[80]: 
['            import paddle',
 '            with paddle.static.program_guard(main_program, startup_program):',
 "                data = paddle.static.data(name='image', shape=[None, 784, 784], dtype='float32')"]

In [81]: print(inspect.cleandoc('\n'.join(f)))
import paddle
with paddle.static.program_guard(main_program, startup_program):
    data = paddle.static.data(name='image', shape=[None, 784, 784], dtype='float32')

而,如下的代码块缩进会出问题:

In [82]: e
Out[82]: 
['            with paddle.static.program_guard(main_program, startup_program):',
 "                data = paddle.static.data(name='image', shape=[None, 784, 784], dtype='float32')"]

In [83]: print(inspect.cleandoc('\n'.join(e)))
with paddle.static.program_guard(main_program, startup_program):
data = paddle.static.data(name='image', shape=[None, 784, 784], dtype='float32')

解决办法可以有以下办法:

  • 写 example 的时候,第一行加个 import xxx 之类无意义的东西
  • 或者,修改 extract_code_blocks_from_docstr 中的 _append_code_block 方法,让 inspect.cleandoc 里面的这个代码块,追加一个空白的行(含缩进,与代码第一行相同的缩进)在第一个元素,如:
In [86]: ee = ['            '] + e

In [87]: print(inspect.cleandoc('\n'.join(ee)))
with paddle.static.program_guard(main_program, startup_program):
    data = paddle.static.data(name='image', shape=[None, 784, 784], dtype='float32')

Copy link
Member

Choose a reason for hiding this comment

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

或者,修改 extract_code_blocks_from_docstr 中的 _append_code_block 方法,让 inspect.cleandoc 里面的这个代码块,追加一个空白的行(含缩进,与代码第一行相同的缩进)在第一个元素,如:

我觉得后者可以试试,不过是否可以不加缩进呢?直接加 \n

image

我这边试了下貌似直接加 \n 就可以~

Copy link
Contributor

Choose a reason for hiding this comment

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

只要是空白行都可以 ~~~

那我提个 PR 改改? Paddle 那边的 CI 也有这部分代码,要改吗?

Copy link
Member

Choose a reason for hiding this comment

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

嗯嗯,要改的,不然会有正确性问题的~正好拿这个作为测试样例

image

修改后 CI 通过就没问题啦~

Copy link
Contributor

Choose a reason for hiding this comment

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

.. code-block:: python
:name: code-model-api-example
Copy link
Member

Choose a reason for hiding this comment

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

paddle.metric.Accuracy_example_2.py 包含训练过程,因此超过 10s 运行。

image

看样子正确性是有保证的,这个不清楚是否可以豁免,如果不可以的话可以考虑 mock 一个数据集之类的

@paddle-ci-bot
Copy link

paddle-ci-bot bot commented Jul 4, 2023

Sorry to inform you that 7afeac5's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

@paddle-bot
Copy link

paddle-bot bot commented Jul 4, 2023

很抱歉,经过我们的反复讨论,你的PR暂未达到合入标准,请阅读飞桨原生算子开发规范,你可以重新提交新的PR,我们先将此PR关闭,感谢你的贡献。
Sorry to inform you that through our discussion, your PR fails to meet the merging standard (Reference: Paddle Custom Operator Design Doc). You can also submit an new one. Thank you.

@luotao1
Copy link
Contributor

luotao1 commented Jul 6, 2023

@megemini @SigureMo 请问任务6的这个PR 还需要继续进行么?

@megemini
Copy link
Contributor

megemini commented Jul 6, 2023

@megemini @SigureMo 请问任务6的这个PR 还需要继续进行么?

#55052 已经合入了,任务6应该已经完成,整体进度那边 Paddle 的 PR 改为 #55052 吧?

可否 @SigureMo ?

@SigureMo
Copy link
Member

SigureMo commented Jul 6, 2023

#55052 已经合入了,任务6应该已经完成,整体进度那边 Paddle 的 PR 改为 #55052 吧?

嗯嗯,本任务是英文 #55052 完成,中文 PaddlePaddle/docs#5971 完成

@luotao1 luotao1 added HappyOpenSource Pro 进阶版快乐开源活动,更具挑战性的任务 and removed HappyOpenSource 快乐开源活动issue与PR labels Aug 7, 2023
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