-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Fix initialized weights resetting in Fabric.setup()
when using FSDP
#19755
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for more information, see https://pre-commit.ci
awaelchli
added
bug
Something isn't working
priority: 0
High priority task
strategy: fsdp
Fully Sharded Data Parallel
labels
Apr 10, 2024
awaelchli
force-pushed
the
bugfix/fabric-apply-fsdp
branch
from
April 10, 2024 14:31
29c035d
to
9559cb9
Compare
for more information, see https://pre-commit.ci
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## master #19755 +/- ##
=========================================
- Coverage 84% 59% -26%
=========================================
Files 424 419 -5
Lines 34919 34820 -99
=========================================
- Hits 29349 20374 -8975
- Misses 5570 14446 +8876 |
carmocca
approved these changes
Apr 10, 2024
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.
Do you understand why unsharding to summon the parameters would impact the optimization?
Merged
justusschock
approved these changes
Apr 11, 2024
awaelchli
added a commit
that referenced
this pull request
Apr 11, 2024
awaelchli
added a commit
that referenced
this pull request
Apr 11, 2024
lantiga
pushed a commit
that referenced
this pull request
Apr 11, 2024
This was referenced Apr 30, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
Something isn't working
fabric
lightning.fabric.Fabric
priority: 0
High priority task
ready
PRs ready to be merged
strategy: fsdp
Fully Sharded Data Parallel
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes a subtle issue with weight initialization in FSDP triggered by the change #19152. The real cause is that FSDP overrides the
apply
method ofnn.Module
:https://github.com/pytorch/pytorch/blob/main/torch/distributed/fsdp/fully_sharded_data_parallel.py/#L567-L605
We call it indirectly here:
pytorch-lightning/src/lightning/fabric/fabric.py
Lines 260 to 262 in 76b691d
and then
root.apply
here:pytorch-lightning/src/lightning/fabric/utilities/device_dtype_mixin.py
Line 122 in 76b691d
which by itself is innocent because all we want to do is apply a function to each submodule.
Since all we want to do is update an attribute recursively, we don't need the parameters to be unshareded anyway. So this PR simply iterates over the modules instead of calling
apply
. Consequently, this should also makefabric.setup()
faster because no longer does each submodule be unsharded.The added test fails on master.
The bug is critical enough that we will need to prioritize a release after this is merged.
Needs #19756 to unblock failing tests.
📚 Documentation preview 📚: https://pytorch-lightning--19755.org.readthedocs.build/en/19755/
cc @Borda @tchaton @carmocca @justusschock @awaelchli