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
[state_dict] Add cpu_only and ranks_only support for _gather_state_dict #112836
Conversation
Add cpu_only and ranks_only support for _gather_state_dict Differential Revision: [D50962980](https://our.internmc.facebook.com/intern/diff/D50962980/) [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/112836
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 9752f60 with merge base 31ded95 (): FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
…er_state_dict" Add cpu_only and ranks_only support for _gather_state_dict Differential Revision: [D50962980](https://our.internmc.facebook.com/intern/diff/D50962980/) [ghstack-poisoned]
…er_state_dict" Add cpu_only and ranks_only support for _gather_state_dict Differential Revision: [D50962980](https://our.internmc.facebook.com/intern/diff/D50962980/) [ghstack-poisoned]
…er_state_dict" Add cpu_only and ranks_only support for _gather_state_dict Differential Revision: [D50962980](https://our.internmc.facebook.com/intern/diff/D50962980/) [ghstack-poisoned]
…er_state_dict" Add cpu_only and ranks_only support for _gather_state_dict Differential Revision: [D50962980](https://our.internmc.facebook.com/intern/diff/D50962980/) [ghstack-poisoned]
…er_state_dict" Add cpu_only and ranks_only support for _gather_state_dict Differential Revision: [D50962980](https://our.internmc.facebook.com/intern/diff/D50962980/) [ghstack-poisoned]
…er_state_dict" Add cpu_only and ranks_only support for _gather_state_dict Differential Revision: [D50962980](https://our.internmc.facebook.com/intern/diff/D50962980/) [ghstack-poisoned]
…er_state_dict" Add cpu_only and ranks_only support for _gather_state_dict Differential Revision: [D50962980](https://our.internmc.facebook.com/intern/diff/D50962980/) [ghstack-poisoned]
Args: | ||
state_dict (Dict[str, Any]): the target sharded state_dict. | ||
pg (Optional[dist.ProcessGroup]): the process group that is used to | ||
gather ShardedTensor. |
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.
nit: gather DTensor or ShardedTensor.
pg (Optional[dist.ProcessGroup]): the process group that is used to | ||
gather ShardedTensor. | ||
device: (Optional[torch.device]): the device that is used to | ||
perform allgather for ShardedTensor. |
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.
nit: gather DTensor or ShardedTensor.
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.
ShardedTensor only. DTensor uses DeviceMesh to gather the tensors.
|
||
new_state_dict[key] = value | ||
if not cpu_offload or len(ranks_only) == 0 or dist.get_rank(pg) in ranks_only: |
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.
Maybe the condition is a bit complicated and I can't think thru lol, but is dist.get_rank(pg) in ranks_only
alone not sufficient?
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.
ranks_only can be empty (the default value). But it seems that we should not restrict this function to be cpu_offload only.
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.
I see. Makes sense!
…er_state_dict" Add cpu_only and ranks_only support for _gather_state_dict Differential Revision: [D50962980](https://our.internmc.facebook.com/intern/diff/D50962980/) [ghstack-poisoned]
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!
…er_state_dict" Add cpu_only and ranks_only support for _gather_state_dict Differential Revision: [D50962980](https://our.internmc.facebook.com/intern/diff/D50962980/) [ghstack-poisoned]
@pytorchbot merge (Initiating merge automatically since Phabricator Diff has merged) |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
#112885) This allows us to do cpu_offload with the same traversal logic Differential Revision: [D50982355](https://our.internmc.facebook.com/intern/diff/D50982355/) Pull Request resolved: #112885 Approved by: https://github.com/LucasLLC, https://github.com/wz337 ghstack dependencies: #112836
…state_dict (#112837) As title Differential Revision: [D50962991](https://our.internmc.facebook.com/intern/diff/D50962991/) Pull Request resolved: #112837 Approved by: https://github.com/LucasLLC, https://github.com/wz337 ghstack dependencies: #112836, #112885
…ct (pytorch#112836) Add cpu_only and ranks_only support for _gather_state_dict Differential Revision: [D50962980](https://our.internmc.facebook.com/intern/diff/D50962980/) Pull Request resolved: pytorch#112836 Approved by: https://github.com/LucasLLC, https://github.com/wz337
pytorch#112885) This allows us to do cpu_offload with the same traversal logic Differential Revision: [D50982355](https://our.internmc.facebook.com/intern/diff/D50982355/) Pull Request resolved: pytorch#112885 Approved by: https://github.com/LucasLLC, https://github.com/wz337 ghstack dependencies: pytorch#112836
…state_dict (pytorch#112837) As title Differential Revision: [D50962991](https://our.internmc.facebook.com/intern/diff/D50962991/) Pull Request resolved: pytorch#112837 Approved by: https://github.com/LucasLLC, https://github.com/wz337 ghstack dependencies: pytorch#112836, pytorch#112885
Stack from ghstack (oldest at bottom):
Add cpu_only and ranks_only support for _gather_state_dict
Differential Revision: D50962980