Support load state dict form inference model format save result#26718
Merged
chenwhql merged 13 commits intoPaddlePaddle:developfrom Sep 3, 2020
Merged
Conversation
|
Thanks for your contribution! |
…' of https://github.com/chenwhql/Paddle into saveload/support_load_inference_model_format_state_dict
phlrain
approved these changes
Sep 2, 2020
lanxianghit
approved these changes
Sep 2, 2020
| def load_dygraph(model_path, keep_name_table=False): | ||
| # @dygraph_only | ||
| @deprecate_keep_name_table | ||
| def load_dygraph(model_path, configs=None): |
Contributor
There was a problem hiding this comment.
configs -> config
这里建议用单数,因为SaveLoadConfig是单数形式
config = paddle.SaveLoadConfig()
可以后续统一再改下
Contributor
Author
There was a problem hiding this comment.
这里能否将SaveLoadConfig改为SaveLoadConfigs,这样兼容性更好处理一些,因为还涉及到jit.save和jit.load接口中的configs参数
| paddle.save(state_dict, "paddle_dy") | ||
|
|
||
| configs = paddle.SaveLoadConfig() | ||
| configs.keep_name_table = True |
Contributor
There was a problem hiding this comment.
keep_name_table默认设置为True的话,会有什么问题吗?
不是很了解背景
Contributor
Author
There was a problem hiding this comment.
也没有什么风险,只是用户载入的state_dict里面会多一些额外信息,这些信息对用户一般没有帮助,保留这个选项主要是为了兼容,怕有同学用利用了旧版实现里面的这个信息
Contributor
Author
There was a problem hiding this comment.
或许我们可以先将这个参数作为内部参数,不向用户公开
chenwhql
added a commit
to chenwhql/Paddle
that referenced
this pull request
Sep 7, 2020
…ddlePaddle#26718) * support load infer model format state dict * add unittests * remove keep name table * recolve circle inport * fix compatible problem * recover unittest * polish doc and comment
chenwhql
added a commit
that referenced
this pull request
Sep 8, 2020
* Update set_dict method name & add aliases (#26700) * update set_dict method name & add aliases * fix var name error * fix alias formats * use set_state_dict in unittest * add decorator solve compatible problem * polish decorator * replace layer set_state_dict by patched method * remove import monkey path layer * fix import function error * add unittest for coverage * Support load state dict form `inference model` format save result (#26718) * support load infer model format state dict * add unittests * remove keep name table * recolve circle inport * fix compatible problem * recover unittest * polish doc and comment * Change jit.save/load configs to config & update code examples (#27056) * change configs to config & update examples * fix deprecate decorator conflict
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR types
New features
PR changes
APIs
Describe
【兼容升级】This PR supprot loading
state_dictfromsave_inference_modelsave result.This is an important feature, and we often see related problems in issues. After we switched from static graph mode to dynamic graph mode, many users rewritten the dynamic graph model code and needed to load from the result of
save_inferenece_modelin original static graph model, such as: #26519API changes:
paddle.load(model_path, keep_name_table=False)->paddle.load(model_path, configs=None): add decoratordeprecate_keep_name_tablefor compatibilitypaddle.jit.SaveLoadConfig->paddle.SaveLoadConfig: becausepaddle.loadalso use it, move it to paddle module,SaveLoadConfigis a class for two save format's compatibility, not only a jit related classpaddle.SaveLoadConfig.keep_name_table: for compatible with oldpaddle.load(model_path, keep_name_table=False)After this PR, the Paddle 2.0 Save/Load inferfaces are like follow:
This PR creates the
green linein graph.Doc change
related PR: PaddlePaddle/docs#2531