-
Notifications
You must be signed in to change notification settings - Fork 21.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
[FSDP2] allow meta tensors during loading state dict and cpu offloading #126267
Conversation
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: [ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/126267
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 5eb2e7d with merge base c1dc8bb ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: c077e9e6ae7ae23c855eb0997e5da18120649919 Pull Request resolved: #126267
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! I left some nits on the unit test.
test/distributed/_composable/fsdp/test_fully_shard_state_dict.py
Outdated
Show resolved
Hide resolved
test/distributed/_composable/fsdp/test_fully_shard_state_dict.py
Outdated
Show resolved
Hide resolved
…pu offloading" unit test: ``pytest test/distributed/_composable/fsdp/test_fully_shard_state_dict.py`` with meta init and cpu offloading, we have meta tensors after`model.load_state_dict(assign=True, strict=False)`. This PR avoided calling `.cpu` on meta tensors otherwise it's a runtime error cc mrshenli pritamdamania87 zhaojuanmao satgera gqchen aazzolini osalpekar jiayisuse H-Huang kwen2501 awgu penguinwu fegin XilunWu wanchaol fduwjj wz337 tianyu-l wconstab yf225 chauhang d4l3k [ghstack-poisoned]
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags: ghstack-source-id: 002a35b0abf528b8a7327ce7762416f0e42efa13 Pull Request resolved: #126267
@pytorchmergebot merge |
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 |
@@ -245,7 +245,7 @@ def _init_sharded_param(self, param: nn.Parameter, device: torch.device): | |||
self.padded_sharded_param_size = padded_sharded_param.size() | |||
if sharded_param.numel() > 0: | |||
padded_sharded_param[: sharded_param.size(0)].copy_(sharded_param) | |||
if self.offload_to_cpu: | |||
if self.offload_to_cpu and not torch.empty(0).is_meta: |
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.
if self.offload_to_cpu and not torch.empty(0).is_meta: | |
if self.offload_to_cpu and not padded_sharded_param.is_meta: |
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.
resolving in #126305
support fully_shard(model_on_meta, cpu_offload) when fully_shard is placed outside of `torch.device("meta")` Pull Request resolved: #126305 Approved by: https://github.com/awgu ghstack dependencies: #126267
…ng (pytorch#126267) unit test: ``pytest test/distributed/_composable/fsdp/test_fully_shard_state_dict.py`` with meta init and cpu offloading, we have meta tensors after`model.load_state_dict(assign=True, strict=False)`. This PR avoided calling `.cpu` on meta tensors otherwise it's a runtime error Pull Request resolved: pytorch#126267 Approved by: https://github.com/awgu
support fully_shard(model_on_meta, cpu_offload) when fully_shard is placed outside of `torch.device("meta")` Pull Request resolved: pytorch#126305 Approved by: https://github.com/awgu ghstack dependencies: pytorch#126267
Stack from ghstack (oldest at bottom):
unit test:
pytest test/distributed/_composable/fsdp/test_fully_shard_state_dict.py
with meta init and cpu offloading, we have meta tensors after
model.load_state_dict(assign=True, strict=False)
. This PR avoided calling.cpu
on meta tensors otherwise it's a runtime errorcc @mrshenli @pritamdamania87 @zhaojuanmao @satgera @gqchen @aazzolini @osalpekar @jiayisuse @H-Huang @kwen2501 @awgu @penguinwu @fegin @XilunWu @wanchaol @fduwjj @wz337 @tianyu-l @wconstab @yf225 @chauhang @d4l3k