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-3: Support jit.save and jit.load for pylayer op #57066

Merged
merged 88 commits into from
Sep 22, 2023

Conversation

MarioLulab
Copy link
Contributor

@MarioLulab MarioLulab commented Sep 7, 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_staitc 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 support pylayer op can be exported by jit.save and loaded by jit.load for subsequent inference.

Related issues

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

Related PR

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

[GLCC]Part-2: @to_static support for PyLayer: #56531

Project Records

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

Main works

  1. Enable core.prune and core.prune_backward to handle BLOCKS attribute of operators by refining the prune.cc.
  2. Modify normalize_program function to remove backward block id of pylayer op.
  3. Add some testcases in test_prune.py, test_program_prune_backward.py and test_inference_model_io.py, etc.
  4. Support non-Variable input arguments and keyword-arguments for dy2st PyLayer.

@MarioLulab MarioLulab marked this pull request as ready for review September 20, 2023 12:52
@MarioLulab MarioLulab changed the title [GLCC]Part-3: Support jit.save for pylayer op [GLCC]Part-3: Support jit.save and jit.load for pylayer op Sep 20, 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,一些代码规范上小的 Comment 可以单独提PR fix

def forward(self, x1, x2):
y1 = self.linear1(x1)
y2 = self.linear1(x2)
out = cus_tanh_2.apply(y1, func1=paddle.tanh)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
out = cus_tanh_2.apply(y1, func1=paddle.tanh)
out = cus_tanh_2.apply(y1, paddle.tanh)

部分单测可以去掉形参指示,这样可以丰富单测样例

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 进行修改

@@ -160,77 +211,83 @@ def _mock_guard(mock):
base.Executor._prune_program = original


def net1():
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def net1():
def create_net1():

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 进行修改

return x, y, label, loss1, loss2, w_param_attrs


def net2():
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def net2():
def create_net2():

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 进行修改

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

@Aurelius84 Aurelius84 merged commit 8941263 into PaddlePaddle:develop Sep 22, 2023
27 checks passed
@MarioLulab MarioLulab deleted the luqi/dev_export_pylayer branch October 7, 2023 08:39
Frida-a pushed a commit to Frida-a/Paddle that referenced this pull request Oct 14, 2023
…dle#57066)

* complete static_pylayer op

* finish static_pylayer op context manager

* finish single test

* append import path

* maybe modify test/ir/inference

* percept static_pylayer op in dy2st
jiahy0825 pushed a commit to jiahy0825/Paddle that referenced this pull request Oct 16, 2023
…dle#57066)

* complete static_pylayer op

* finish static_pylayer op context manager

* finish single test

* append import path

* maybe modify test/ir/inference

* percept static_pylayer op in dy2st
danleifeng pushed a commit to danleifeng/Paddle that referenced this pull request Nov 14, 2023
…dle#57066)

* complete static_pylayer op

* finish static_pylayer op context manager

* finish single test

* append import path

* maybe modify test/ir/inference

* percept static_pylayer op in dy2st
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.

3 participants