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

Sharded state dicts save correctly when save_weights_only=True #19524

Merged
merged 15 commits into from
Mar 13, 2024

Conversation

dimitri-voytan
Copy link
Contributor

@dimitri-voytan dimitri-voytan commented Feb 23, 2024

What does this PR do?

Fixes #19492 for FSDP sharded state_dicts. Optimizer states are default to an empty list if they are not in the state_dict, which can happen when the model checkpoint callback uses save_weights_only=True

Before submitting
  • Was this discussed/agreed via a GitHub issue? (not for typos and docs)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure your PR does only one thing, instead of bundling different changes together?
  • Did you make sure to update the documentation with your changes? (if necessary)
  • Did you write any new necessary tests? (not for typos and docs)
  • Did you verify new and existing tests pass locally with your changes?
  • Did you list all the breaking changes introduced by this pull request?
  • [ ]Did you update the CHANGELOG? (not for typos, docs, test updates, or minor internal changes/refactors)

PR review

Anyone in the community is welcome to review the PR.
Before you start reviewing, make sure you have read the review guidelines. In short, see the following bullet-list:

Reviewer checklist
  • Is this pull request ready for review? (if not, please submit in draft mode)
  • Check that all items from Before submitting are resolved
  • Make sure the title is self-explanatory and the description concisely explains the PR
  • Add labels and milestones (and optionally projects) to the PR so it can be classified

📚 Documentation preview 📚: https://pytorch-lightning--19524.org.readthedocs.build/en/19524/

@github-actions github-actions bot added the pl Generic label for PyTorch Lightning package label Feb 23, 2024
@dimitri-voytan
Copy link
Contributor Author

@awaelchli

This works now in that the test fails on master and passes with the corrections. It could improve with verification that the checkpoints are useable in the lightning ecosystem downstream. If this is of interest, can I ask the lightning team for some help as I don't have a lot of free time to work on this.

@dimitri-voytan dimitri-voytan marked this pull request as ready for review February 27, 2024 23:01
@awaelchli awaelchli added strategy: fsdp Fully Sharded Data Parallel bug Something isn't working community This PR is from the community labels Feb 29, 2024
@awaelchli awaelchli added this to the 2.2.x milestone Feb 29, 2024
@awaelchli awaelchli self-assigned this Feb 29, 2024
@mergify mergify bot added the has conflicts label Mar 8, 2024
Copy link
Contributor

@awaelchli awaelchli left a comment

Choose a reason for hiding this comment

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

@dimitri-voytan Great fix, thanks a lot!

I integrated your test in an existing one we already had for weights_only=True, we just needed to add the parameterization for sharded checkpoints.

@mergify mergify bot removed the has conflicts label Mar 8, 2024
@mergify mergify bot added the ready PRs ready to be merged label Mar 8, 2024
@awaelchli awaelchli merged commit b3275e0 into Lightning-AI:master Mar 13, 2024
85 of 86 checks passed
awaelchli added a commit that referenced this pull request Apr 10, 2024
)

Co-authored-by: Dimitri <dvoytan@sparkcognition.com>
Co-authored-by: awaelchli <aedu.waelchli@gmail.com>
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
lantiga pushed a commit that referenced this pull request Apr 11, 2024
)

Co-authored-by: Dimitri <dvoytan@sparkcognition.com>
Co-authored-by: awaelchli <aedu.waelchli@gmail.com>
Co-authored-by: Jirka Borovec <6035284+Borda@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working community This PR is from the community pl Generic label for PyTorch Lightning package ready PRs ready to be merged strategy: fsdp Fully Sharded Data Parallel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FSDP state_dict_type 'sharded' not working with ModelCheckpoint(save_weights_only=True)
5 participants