-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 save/load function without parameters. #32430
Conversation
Thanks for your contribution! |
python/paddle/fluid/dygraph/jit.py
Outdated
@@ -617,9 +617,9 @@ def train(layer, loader, loss_fn, opt): | |||
raise RuntimeError( | |||
"The paddle.jit.save doesn't work when setting ProgramTranslator.enable to False." | |||
) | |||
if not isinstance(layer, Layer): | |||
if not (isinstance(layer, Layer) or isinstance(layer, StaticFunction)): |
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.
这里我们要支持的是不是function,而不是StaticFunction,当时输入是普通function的时候,像layer一样根据input_spec对其进行转换,现在这样写,会导致存function的情况下,input_spec这个参数就没什么意义了吧
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.
Done, thx.
1f5e58f
to
5a44535
Compare
5a44535
to
f9d42e1
Compare
f9d42e1
to
be8eb18
Compare
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.
还有两点问题:
- 这个改动,文档也需要配合修改一下,参数类型和描述要涵盖function
- 之前实现的时候可能条件卡得比较严,对于layer来讲,如果layer没有参数,是不是也不需要存pdparams和pdparams.info
Done,thx. |
@@ -506,7 +507,7 @@ def _build_load_path_and_config(path, config): | |||
@switch_to_static_graph | |||
def save(layer, path, input_spec=None, **configs): | |||
""" | |||
Saves input Layer as ``paddle.jit.TranslatedLayer`` | |||
Saves input Layer or function as ``paddle.jit.TranslatedLayer`` |
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.
Since function cannot save parameters, you should give a Note or Warning and had better explain the reason for users.
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.
Done, thx.
# 5. save inference model | ||
from paddle.fluid.io import save_inference_model | ||
|
||
# construct new save_inference_model arguments | ||
model_path = dirname | ||
# NOTE(chenweihang): because prefix contains model and params filename, | ||
# so we don't support set model_filename & params_filename | ||
if 'forward' == attr_func: | ||
if 'forward' == attr_func or not isinstance(layer, Layer): |
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.
When not isinstance(layer, Layer)
, that means it is a function, should we also save function's name to model_filename
and params_filename
?
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.
LGTM
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.
LGTM
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.
LGTM
…ePaddle#32430) * jit.save/load support function. * delete unnittest test_jit_load_model_incomplete. * edit code according to CI * Modify the documentation. * add note to doc.
… (#32613) * jit.save/load support function. * delete unnittest test_jit_load_model_incomplete. * edit code according to CI * Modify the documentation. * add note to doc.
PR types
Function optimization
PR changes
APIs
Describe
paddle.jit.save/load支持保存function,只保存了program,没有保存参数。因此没有
.pdparam
和.info
文件。示例如下:
以下情况是不支持的:
文档:红框内为本次修改的内容
http://10.136.157.23:8090/documentation/docs/en/api/paddle/fluid/dygraph/jit/save_en.html