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

support save load optimizer master_weights #60027

Merged

Conversation

pangengzheng
Copy link
Contributor

@pangengzheng pangengzheng commented Dec 14, 2023

PR types

Others

PR changes

Others

Description

card-78318
support flatten state_dict, save load optimizer master_weights and deduplicate tensor when save state_dict

Copy link

paddle-bot bot commented Dec 14, 2023

你的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.

@pangengzheng pangengzheng changed the title Flatten and dedup for save load support save load optimizer master_weights Dec 19, 2023
@@ -61,5 +61,47 @@ def compute_local_shape_and_global_offset(


def flatten_state_dict(state_dict):
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it support multiple level, i.e., {'model': {'m': {'w': xxx}}} ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

支持的

)

tensor.set(load_para_np, framework._current_expected_place())
var.set_value(state_dict[var_tmp.name])
Copy link
Contributor

Choose a reason for hiding this comment

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

why change here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

代码复用,set_value api的行为包含这部分删掉的代码逻辑,且支持设置distributed tensor赋值

@@ -74,6 +73,16 @@ def dedup_storage_metadata(global_storage_metadata):
return out


def dedup_tensor(state_dict, local_storage_metadata, dedup_storage_metadata):
Copy link
Contributor

Choose a reason for hiding this comment

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

add some comments

Copy link
Contributor Author

@pangengzheng pangengzheng Dec 26, 2023

Choose a reason for hiding this comment

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

ok,不过这个方法可以算是此文件的私有方法,不对外。comment已加

Copy link
Contributor

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

@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

@zhiqiu zhiqiu merged commit 76ce9bb into PaddlePaddle:develop Dec 28, 2023
29 checks passed
Wanglongzhi2001 pushed a commit to Wanglongzhi2001/Paddle that referenced this pull request Jan 7, 2024
* exclude xpu

* dedup tensor in state_dict

* polish

* support flatten and unflatten state_dict

* test flatten

* rename test

* fix dedup tensor test

* fix test

* fix load state dict

* rename

* fix test

* support save load optimizer master weights

* add comment
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.

3 participants