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

set_state_dict not use state_dict hook #43407

Merged

Conversation

zhangbo9674
Copy link
Contributor

@zhangbo9674 zhangbo9674 commented Jun 10, 2022

PR types

Bug fixes

PR changes

APIs

Describe

修复的问题:
在 amp-o2功能开发过程中,为了支持指定网络存储数据类型的功能,添加state_dict hook功能,但是在Layer的set_state_dict是通过state_dict获取网络参数并加载的,hook接口的存在导致 set_state_dict无法加载到原本网络参数。
本pr通过增加hook控制开关,在set_state_dict中禁用hook解决该问题。

具体改动:
为Layer 的 state_dict 接口增加一个bool参数:use_hook,默认为True,set_state_dict中有调用state_dict接口,use_hook为False
用法上为用户提供了是否使用hook的控制接口,默认使用,用户无需显示声明。

api文档:pr

@paddle-bot-old
Copy link

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

zhiqiu
zhiqiu previously approved these changes Jun 14, 2022
Copy link
Contributor

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

@lanxianghit lanxianghit left a comment

Choose a reason for hiding this comment

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

请注意同时修改中英文文档

@zhangbo9674 zhangbo9674 merged commit 1d0d659 into PaddlePaddle:develop Jun 15, 2022
zhangbo9674 added a commit to zhangbo9674/Paddle that referenced this pull request Jun 21, 2022
* set_state_dict not use state_dict hook

* add ut

* refine doc
lanxianghit pushed a commit that referenced this pull request Jun 22, 2022
在 amp-o2功能开发过程中,为了支持指定网络存储数据类型的功能,添加state_dict hook功能,但是在Layer的set_state_dict是通过state_dict获取网络参数并加载的,hook接口的存在导致 set_state_dict无法加载到原本网络参数。
本pr通过增加hook控制开关,在set_state_dict中禁用hook解决该问题。

详见pr43407
sneaxiy pushed a commit to sneaxiy/Paddle that referenced this pull request Jun 27, 2022
* set_state_dict not use state_dict hook

* add ut

* refine doc
@zhangbo9674 zhangbo9674 deleted the dev/fix_amp_o2_state_dict branch March 2, 2023 03:00
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.

4 participants