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

jit.save/load support method with parameters. #34070

Merged
merged 3 commits into from
Jul 14, 2021

Conversation

hbwx24
Copy link
Contributor

@hbwx24 hbwx24 commented Jul 9, 2021

PR types

Function optimization

PR changes

Others

Describe

jit.save/load支持保存加载带有参数的成员函数。
根据jit.save的输入为function/StaticFunction 和layer分成了两种情况:

  • 当输入为layer,规则与以前一致。
  • 当输入为function/StaticFunction:
    • 是Layer类的成员函数function的权重都在state_dict里面:按用户指定的名字保存模型,jit.load加载这个模型得到TranslatedLayer,加载的模型对映forward函数。
    • 否则,不能包含权重,因此只生成*.pdmodel 一个文件

调用方式:

  1. 下图这种写法仅支持保存function,如果保存layer(例如:paddle.jit.save(layer, path))由于没有用to_static修饰forward会报错:ValueError: No valid transformed program for function: forward(x), input_spec: None
    image

image

image

@paddle-bot-old
Copy link

paddle-bot-old bot commented Jul 9, 2021

Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

concrete_program = static_function.concrete_program

if static_function._class_instance is None:
warnings.warn(
Copy link
Contributor

Choose a reason for hiding this comment

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

没有看懂这个提示

Copy link
Contributor Author

Choose a reason for hiding this comment

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

好的,已修改

Copy link
Contributor

@chenwhql chenwhql 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

@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

@hbwx24 hbwx24 merged commit 1b37763 into PaddlePaddle:develop Jul 14, 2021
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.

3 participants