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

[GLCC]Part-1: Add pylayer op to Support @to_static #56108

Merged
merged 26 commits into from
Aug 21, 2023

Conversation

MarioLulab
Copy link
Contributor

@MarioLulab MarioLulab commented Aug 9, 2023

PR types

New features

PR changes

Others

Description

Original requirements

It is expected that the PyLayer mechanism in the dynamic graph of the Paddle can interoperate with the @to_static of the Paddle's dynamic to static, supporting the custom layer of the PyLayer in the model to be perceived by the @to_static and correctly generating the static graph Program, and supporting the training of the dynamic to static and the exporting for inference.
So our main objective is to Enable PyLayer to Support @to_static. In this PR, we do some fundamental work for our objective, adding an operator called pylayer.

Related issues

【Feature Request】 PyLayer 功能支持动转静 @to_static 🚀: #54120

Project Records

https://github.com/MarioLulab/GLCC2023-Paddle-Record

Main works

  1. Add a static op called pylayer which can excute block user-defined block when forward and backward.
  2. Add some testcases for pylayer op
  3. Add python api for pylayer op, which help users use pylayer op easily.

TO-DO works:

  1. Enable @to_static to sense and handle the computational logic in the forward() and backward() functions in dynamic PyLayer.
  2. Combine @to_static with pylayer op to achive the goal.

@paddle-bot
Copy link

paddle-bot bot commented Aug 9, 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.

@CLAassistant
Copy link

CLAassistant commented Aug 9, 2023

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@Aurelius84 Aurelius84 left a comment

Choose a reason for hiding this comment

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

Nice work!

paddle/fluid/framework/op_compatible_info.cc Outdated Show resolved Hide resolved
paddle/fluid/operators/controlflow/CMakeLists.txt Outdated Show resolved Hide resolved
paddle/fluid/operators/controlflow/static_pylayer_op.h Outdated Show resolved Hide resolved
paddle/fluid/operators/controlflow/static_pylayer_op.cc Outdated Show resolved Hide resolved
paddle/fluid/operators/controlflow/static_pylayer_op.cc Outdated Show resolved Hide resolved
paddle/fluid/operators/controlflow/static_pylayer_op.cc Outdated Show resolved Hide resolved
paddle/fluid/operators/controlflow/static_pylayer_op.cc Outdated Show resolved Hide resolved
python/paddle/jit/dy2static/convert_call_func.py Outdated Show resolved Hide resolved
Copy link
Contributor Author

@MarioLulab MarioLulab left a comment

Choose a reason for hiding this comment

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

reply

paddle/fluid/framework/op_compatible_info.cc Outdated Show resolved Hide resolved

#include "paddle/fluid/operators/controlflow/static_pylayer_op.h"

#include "paddle/fluid/framework/new_executor/standalone_executor.h"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

有道理。目前只需要依赖 interpretercore.h

paddle/fluid/operators/controlflow/static_pylayer_op.cc Outdated Show resolved Hide resolved
paddle/fluid/operators/controlflow/CMakeLists.txt Outdated Show resolved Hide resolved
#include <vector>

#include "paddle/fluid/framework/executor.h"
#include "paddle/fluid/framework/new_executor/standalone_executor.h"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

确实这两个头文件依赖不是必须的,后续将移除

@MarioLulab MarioLulab marked this pull request as ready for review August 18, 2023 02:29
Aurelius84
Aurelius84 previously approved these changes Aug 18, 2023
Copy link
Contributor

@Aurelius84 Aurelius84 left a comment

Choose a reason for hiding this comment

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

LGTM overall

@MarioLulab MarioLulab changed the title GLCC Enable PyLayer to Support @to_static GLCC Add pylayer op Aug 18, 2023
@Aurelius84 Aurelius84 changed the title GLCC Add pylayer op [GLCC]Part-1: Add pylayer op to Support @to_static Aug 21, 2023
Copy link
Contributor

@zoooo0820 zoooo0820 left a comment

Choose a reason for hiding this comment

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

LGTM for fluid change

Copy link
Contributor

@XiaoguangHu01 XiaoguangHu01 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@sunzhongkai588 sunzhongkai588 left a comment

Choose a reason for hiding this comment

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

LGTM for docs

Returns:
Variable|list(Variable)|tuple(Variable): returns the output of ``forward_fn(inputs)``

Examples:
Copy link
Contributor

Choose a reason for hiding this comment

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

代码示例的写法,正逐步改成google style样式,参考 PaddlePaddle/docs#6096

之后若有涉及到写代码示例,请采用新的写法。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的了解了,这个之后的 pr 还会继续修改该 api,会在之后的 pr 中修改成 google style 样式

Copy link
Contributor

@sunzhongkai588 sunzhongkai588 Aug 21, 2023

Choose a reason for hiding this comment

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

@MarioLulab 嗷对了,请同步补充一下中文文档,在 docs repo下。

另外.. code-block:: python 是两个冒号,下个pr同步修改下吧~

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的了解了,下个 pr 完善这个 api 后会一起修改

@Aurelius84 Aurelius84 requested a review from zyfncg August 21, 2023 06:08
Copy link
Contributor

Choose a reason for hiding this comment

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

一般OpMaker和Op类都放在.cc文件中,这个头文件目前看上去也没有专门使用的需要,是否可以去掉?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的了解了,之后的 pr 还会继续修改该 api 和 算子,会在之后的 pr 中将 OpMaker 放在 .cc 文件中

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants