Fix the bug that ParamBase lose attributes when paddle.save(Layer) #33500
Merged
hbwx24 merged 2 commits intoPaddlePaddle:developfrom Jun 15, 2021
Merged
Fix the bug that ParamBase lose attributes when paddle.save(Layer) #33500hbwx24 merged 2 commits intoPaddlePaddle:developfrom
ParamBase lose attributes when paddle.save(Layer) #33500hbwx24 merged 2 commits intoPaddlePaddle:developfrom
Conversation
|
Thanks for your contribution! |
chenwhql
reviewed
Jun 11, 2021
| core.varbase_copy(self, new_param, device, blocking) | ||
| return new_param | ||
|
|
||
| def __reduce__(self): |
Contributor
There was a problem hiding this comment.
如果用户直接save(ParamBase),会和之前格式不同吗
Contributor
Author
There was a problem hiding this comment.
用户直接save(ParamBase),和之前格式完全相同。
Contributor
|
这个主要是为了修复paddle.save(Layer)时参数属性丢失的问题吧,可以补充下 |
hbwx24
added a commit
to hbwx24/Paddle
that referenced
this pull request
Jun 15, 2021
* Save all the information of 'ParamBase' in 'Layer'. * edit unittest
ParamBase lose attributes when paddle.save(Layer)
Contributor
hbwx24
added a commit
to hbwx24/Paddle
that referenced
this pull request
Jul 9, 2021
* Save all the information of 'ParamBase' in 'Layer'. * edit unittest
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
Bug fixes
PR changes
APIs
Describe
修复paddle.save(Layer)时参数属性丢失的问题:通过实现__reduce__的方式保存layer中的
ParamBase的所有信息。pickle原理简介:
pickle.dump:
pickle.load:
pickle详情参考。
兼容性问题:
如果 Layer、ParamBase、__setstate__改变将对加载模型造成影响。
结论如下: