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

Update python api and c++ op develop guide #5189

Merged
merged 6 commits into from
Aug 26, 2022

Conversation

moguguo
Copy link
Collaborator

@moguguo moguguo commented Aug 25, 2022

Update python api and c++ op develop guide.

@paddle-bot
Copy link

paddle-bot bot commented Aug 25, 2022

感谢你贡献飞桨文档,文档预览构建中,Docs-New 跑完后即可预览,预览链接:http://preview-pr-5189.paddle-docs-preview.paddlepaddle.org.cn/documentation/docs/zh/api/index_cn.html
预览工具的更多说明,请参考:[Beta]飞桨文档预览工具

@paddle-bot
Copy link

paddle-bot bot commented Aug 25, 2022

✅ This PR's description meets the template requirements!
Please wait for other CI results.


本教程对新增算子的方法进行介绍,首先新增一个算子大概需要以下几个步骤:
针对第二种情况,可参考本文完成 C++ OP 的开发,并参考 [飞桨 API Python 端开发指南](new_python_api_cn.html) 章节完成 Python 端的开发。
Copy link
Contributor

Choose a reason for hiding this comment

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

新的算子体系下我们希望能够让算子和API更好的对齐,并且淡化OP这个概念,因此文档里的OP算子来替代可能会更好一些

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.中文文档中相关内容改为 C++ 算子。


def test_check_output(self):
self.check_output(check_eager=True)
**单测文件存放路径和命名方式:**在 [python/paddle/fluid/tests/unittests](https://github.com/PaddlePaddle/Paddle/tree/develop/python/paddle/fluid/tests/unittests) 目录下,一般以 `test_*${op_name}*_op.py` 的形式命名,与 Python API 的单元测试文件命名为相同的前缀。
Copy link
Contributor

Choose a reason for hiding this comment

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

image

格式似乎有点问题

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done. 去掉加粗

Comment on lines 1072 to 1073
<center><img src="./images/code_gen_by_yaml.png" width="700px" ></center>

Copy link
Contributor

Choose a reason for hiding this comment

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

image

图片显示有点问题

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done. 文档预览的问题,图片先上传github,再改用绝对链接。


提前 PR 后,github 上的 Bot 会给出根据所提交的中文文档所生成的官网文档的链接,可以点进去查看新增的文档所渲染出的页面效果,看是否符合预期。尤其需要注意检查是否有错别字数学公式示例代码渲染是否正确等问题。例如
提前 PR 后,GitHub 上的 paddle-bot 会给出根据所提交的中文文档所生成的官网文档的预览链接,可以点进去查看新增的文档所渲染出的页面效果,看是否符合预期。尤其需要注意检查是否有错别字数学公式示例代码渲染是否正确等问题。例如

Copy link
Contributor

Choose a reason for hiding this comment

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

image

图片预览好像有问题

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done. 文档预览的问题,图片先上传github,再改用绝对链接。

fix image links
我们在 [`paddle/phi/api/yaml/api.yaml`](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/phi/api/yaml/api.yaml) 和 [`paddle/phi/api/yaml/backward.yaml`](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/phi/api/yaml/backward.yaml) 文件中对算子进行描述及定义,在框架编译时会根据 YAML 文件中的配置自动生成 C++ 端的相关代码接口以及内部实现(详见 [Paddle 基于 YAML 配置的算子代码自动生成](new_cpp_op_cn.html#paddleyaml)),下面主要以 Trace 为例介绍算子的 YAML 配置规则:
### 3.1 算子 Yaml 文件配置

在 `paddle/phi/api/yaml/api.yaml` 和 `paddle/phi/api/yaml/backward.yaml` 文件中对算子进行描述及定义,在框架编译时会根据 YAML 文件中的配置自动生成 C++ 端的相关代码接口以及内部实现(详见 [Paddle 基于 Yaml 配置自动生成算子代码的逻辑解读](#paddleyaml)),下面主要以 [paddle.trace](../../api/paddle/trace_cn.html#trace) 为例介绍算子的 Yaml 配置规则:
Copy link
Contributor

Choose a reason for hiding this comment

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

这里这个paddleyaml是无效链接?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

是跳转到本页面下面的章节,在这里加上章节号使更明显些。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.


```
```plain
Copy link
Contributor

Choose a reason for hiding this comment

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

为什么不用c++

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

@chenwhql
Copy link
Contributor

需要关注下这个PR里luotao的comment
PaddlePaddle/Paddle#45306

@moguguo
Copy link
Collaborator Author

moguguo commented Aug 26, 2022

需要关注下这个PR里luotao的comment PaddlePaddle/Paddle#45306

done.已根据PR更新文档。

fix bugs
Copy link
Collaborator

@momozi1996 momozi1996 left a comment

Choose a reason for hiding this comment

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

LGTM

@momozi1996 momozi1996 merged commit c69c327 into PaddlePaddle:develop Aug 26, 2022
@moguguo moguguo deleted the docs-contr1 branch August 26, 2022 03:08
@@ -168,9 +170,8 @@ b. 如果是实现自定义的 C++ API,需要在'paddle/phi/api/lib/api_custom
</tr>
</tbody>
</table>


`backward.yaml`中反向算子的配置规则如下:
Copy link
Collaborator

Choose a reason for hiding this comment

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

image

需要增加一个空格来保证灰色底块的正常显示

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done. #5199


**InferMeta 的编译时与运行时**

在我们的静态图网络中,`InferMeta`操作在[编译时(compile time)和运行时(run time)](https://github.com/PaddlePaddle/FluidDoc/blob/release/1.2/doc/fluid/getstarted/Developer's_Guide_to_Paddle_Fluid.md#%E8%AE%A9%E6%88%91%E4%BB%AC%E5%9C%A8fluid%E7%A8%8B%E5%BA%8F%E5%AE%9E%E4%BE%8B%E4%B8%AD%E5%8C%BA%E5%88%86%E7%BC%96%E8%AF%91%E6%97%B6%E5%92%8C%E8%BF%90%E8%A1%8C%E6%97%B6)都会被调用,在 compile time 时,由于真实的维度未知,框架内部用-1 来表示,在 run time 时,用实际的维度表示,因此维度的值在 compile time 和 run time 时可能不一致,如果存在维度的判断和运算操作,InferMeta 就需要区分 compile time 和 run time。
在静态图模型中,`InferMeta`操作在 [编译时(compile time)和运行时(run time)](https://github.com/PaddlePaddle/FluidDoc/blob/release/1.2/doc/fluid/getstarted/Developer's_Guide_to_Paddle_Fluid.md#让我们在 fluid 程序实例中区分编译时和运行时) 都会被调用,在 compile time 时,由于真实的维度未知,框架内部用 -1 来表示,在 run time 时,用实际的维度表示,因此维度的值在 compile time 和 run time 时可能不一致,如果存在维度的判断和运算操作,InferMeta 就需要区分 compile time 和 run time。
Copy link
Collaborator

Choose a reason for hiding this comment

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

image

超链接没有正常生效,似乎是后括号位置不太对?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done. #5199

- [paddle/phi/kernels/gpu/trace_grad_kernel.cu](https://github.com/PaddlePaddle/Paddle/blob/develop/paddle/phi/kernels/gpu/trace_grad_kernel.cu)


**(4)公共函数管理:**
Copy link
Collaborator

Choose a reason for hiding this comment

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

冒号删掉,其他子项都没有加

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done. #5199

### 6.4 性能优化
#### 6.4.1 第三方库的选择
### 7.4 性能优化
#### 7.4.1 第三方库的选择
在写算子过程中优先使用高性能(如 cudnn、mkldnn、mklml、eigen 等)中提供的操作,但是一定要做 benchmark,有些库中的操作在深度学习任务中可能会比较慢。因为高性能库(如 eigen 等)中提供的操作为了更为通用,在性能方面可能并不是很好,通常深度学习模型中数据量较小,所以有些情况下可能高性能库中提供的某些操作速度较慢。比如 Elementwise 系列的所有算子(前向和反向),Elementwise 操作在模型中调用的次数比较多,尤其是 Elementwise_add,在很多操作之后都需要添加偏置项。在之前的实现中 Elementwise_op 直接调用 Eigen 库,由于 Elementwise 操作在很多情况下需要对数据做 Broadcast,而实验发现 Eigen 库做 Broadcast 的速度比较慢,慢的原因在这个 PR[#6229](https://github.com/PaddlePaddle/Paddle/pull/6229)中有描述。
Copy link
Collaborator

Choose a reason for hiding this comment

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

image

PR的展示方式统一一下吧,要加括号就统一都加,建议参考release note的格式,使用英文括号+PR号的形式

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done. #5199

@moguguo moguguo mentioned this pull request Aug 26, 2022
@PaddlePaddle PaddlePaddle deleted a comment from zyfncg Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants