-
Notifications
You must be signed in to change notification settings - Fork 5.7k
修改 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
修改 COPY-FROM No.6 metric #54879
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
能否豁免 |
python/paddle/metric/metrics.py
Outdated
@@ -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 = [] |
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.
paddle.metric.Metric_example_1.py
和paddle.metric.Metric_example_2.py
都是代码片段,所以无法运行,除非进行修改。
按理说这样的函数没有调用不可能会出问题的,这里是解析出现了问题

@megemini 可否麻烦有时间看一下这里为什么解析出了问题呢?按理说这里不应该少这个缩进
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.
问题是 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')
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 改改? Paddle 那边的 CI 也有这部分代码,要改吗?
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.
python/paddle/metric/metrics.py
Outdated
.. code-block:: python | ||
:name: code-model-api-example |
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.
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. |
7afeac5
to
259b18a
Compare
很抱歉,经过我们的反复讨论,你的PR暂未达到合入标准,请阅读飞桨原生算子开发规范,你可以重新提交新的PR,我们先将此PR关闭,感谢你的贡献。 |
嗯嗯,本任务是英文 #55052 完成,中文 PaddlePaddle/docs#5971 完成 |
PR types
Others
PR changes
Docs
Description
更新
paddle.metric
中部分类与接口的docstring
,使支持新的中文文档生成方式。