Skip to content

Conversation

@rohan-varma
Copy link
Contributor

@rohan-varma rohan-varma commented Dec 8, 2022

Stack from ghstack (oldest at bottom):

Use register_state_dict_pre_hook in FSDP to simplify state_dict implementations & remove hacks. This removes def state_dict entirely and paves the path for composable API as well.

@pytorch-bot
Copy link

pytorch-bot bot commented Dec 8, 2022

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/90436

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 108c6bd:
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot bot added the release notes: distributed (fsdp) release notes category label Dec 8, 2022
rohan-varma added a commit that referenced this pull request Dec 8, 2022
ghstack-source-id: e28bf65
Pull Request resolved: #90436
@rohan-varma rohan-varma changed the title Adopt state_dict_pre_hook in FSDP [WIP] Adopt state_dict_pre_hook in FSDP Dec 8, 2022
rohan-varma added a commit that referenced this pull request Dec 8, 2022
ghstack-source-id: c340d39
Pull Request resolved: #90436
Use register_state_dict_pre_hook in FSDP to simplify state_dict implementations & remove hacks.



[ghstack-poisoned]
Use register_state_dict_pre_hook in FSDP to simplify state_dict implementations & remove hacks.



[ghstack-poisoned]
@rohan-varma rohan-varma changed the title [WIP] Adopt state_dict_pre_hook in FSDP Adopt state_dict_pre_hook in FSDP Dec 8, 2022
Use register_state_dict_pre_hook in FSDP to simplify state_dict implementations & remove hacks.



[ghstack-poisoned]
rohan-varma added a commit that referenced this pull request Dec 8, 2022
ghstack-source-id: eeb957c
Pull Request resolved: #90436
Comment on lines 658 to 666
StateDictType.FULL_STATE_DICT: functools.partial(
_full_pre_state_dict_hook, fsdp_state
),
StateDictType.LOCAL_STATE_DICT: functools.partial(
_local_pre_state_dict_hook, fsdp_state
),
StateDictType.SHARDED_STATE_DICT: functools.partial(
_sharded_pre_state_dict_hook, fsdp_state
),
Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer not to use partial here but just pass the fsdp_state to _pre_state_dict_hook_fn[fsdp_state._state_dict_type]().

try:
state_dict.pop(f"{prefix}{FLAT_PARAM}")
except:
pass
Copy link
Contributor

@fegin fegin Dec 8, 2022

Choose a reason for hiding this comment

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

This is pretty strange. We don't have this try-except before, right? I'm not sure if there will be a hidden bug if we use try-except to avoid the issue.

Use register_state_dict_pre_hook in FSDP to simplify state_dict implementations & remove hacks.



[ghstack-poisoned]
Use register_state_dict_pre_hook in FSDP to simplify state_dict implementations & remove hacks.



[ghstack-poisoned]
rohan-varma added a commit that referenced this pull request Dec 9, 2022
ghstack-source-id: 280904d
Pull Request resolved: #90436
@rohan-varma rohan-varma requested a review from fegin December 9, 2022 03:11
Use register_state_dict_pre_hook in FSDP to simplify state_dict implementations & remove hacks.



[ghstack-poisoned]
rohan-varma added a commit that referenced this pull request Dec 9, 2022
ghstack-source-id: 3e5287d
Pull Request resolved: #90436
Copy link
Contributor

@fegin fegin left a comment

Choose a reason for hiding this comment

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

There are some linter errors. Otherwise it is good to land.

Use register_state_dict_pre_hook in FSDP to simplify state_dict implementations & remove hacks. This removes `def state_dict` entirely and paves the path for composable API as well.



[ghstack-poisoned]
rohan-varma added a commit that referenced this pull request Dec 10, 2022
ghstack-source-id: aa87bd9
Pull Request resolved: #90436
@rohan-varma
Copy link
Contributor Author

@pytorchbot merge -f "CI passed"

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

)
from ._state_dict_utils import (
_post_load_state_dict_hook,
_pre_state_dict_hook,
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like this is going to get sorted in the next ufmt.

@facebook-github-bot facebook-github-bot deleted the gh/rohan-varma/621/head branch June 8, 2023 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants