-
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
Fix the bug that ParamBase
lose attributes when paddle.save(Layer)
#33500
Conversation
Thanks for your contribution! |
@@ -5535,6 +5535,18 @@ def _copy_to(self, device, blocking): | |||
core.varbase_copy(self, new_param, device, blocking) | |||
return new_param | |||
|
|||
def __reduce__(self): |
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.
如果用户直接save(ParamBase),会和之前格式不同吗
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.
用户直接save(ParamBase),和之前格式完全相同。
这个主要是为了修复paddle.save(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.
LGTM
* Save all the information of 'ParamBase' in 'Layer'. * edit unittest
ParamBase
lose attributes when paddle.save(Layer)
* Save all the information of 'ParamBase' in 'Layer'. * edit unittest
PR types
Bug fixes
PR changes
APIs
Describe
修复paddle.save(Layer)时参数属性丢失的问题:通过实现__reduce__的方式保存layer中的
ParamBase
的所有信息。pickle原理简介:
pickle.dump:
pickle.load:
pickle详情参考。
兼容性问题:
如果 Layer、ParamBase、__setstate__改变将对加载模型造成影响。
结论如下: