Repository navigation
FSDP2: count a sharded activation checkpoint wrapper as its block unit (fsdp2 red since accelerate 1.16) - #18025
Merged
Conversation
…nit (accelerate 1.16)
Member
Author
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Repo tests (CPU, fsdp2)fails on main since accelerate 1.16.0 reached PyPI today (seen on #18012 and #18017, both on20d05c20):Cause
With activation checkpointing on, accelerate wraps each decoder block in a
CheckpointWrapperand then callsfully_shard. Up to 1.15 it sharded the block inside the wrapper. 1.16 shards the wrapper instead and skips the block inside ("Shard the wrapper to keep FSDP hooks outside compiled code",fsdp2_prepare_model).after_fsdp2_wrapfinds the blocks with_decoder_blocks(model)and keeps the ones that areFSDPModules. On 1.16 the block is no longer one, and the wrapper's class is not a decoder layer class, so it found no blocks. The fused LoRA gate does not depend on that list (it checks that each fused layer's owning unit sits in the layer list, which the wrapper does). What was lost is the per-block tuning: the last block was no longer kept gathered after forward (set_reshard_after_forward(False)), so with activation checkpointing every step gathered it again at the start of backward.The test is right. accelerate's change is reasonable, and Unsloth's block lookup assumed the old layout.
Change
unsloth/models/fsdp2.py: new_block_units, which returns each decoder block's FSDP unit: the block itself, or the checkpoint wrapper around it when that wrapper is theFSDPModule(_checkpoint_wrapped_module is block).after_fsdp2_wrapuses it for the block list, the block count and the last-block reshard setting.tests/test_fsdp2_block_units.py(in thefsdp2shard): both layouts with stand-in classes, so the 1.16 layout is checked whatever accelerate CI installs, plus a case where neither the block nor the wrapper is sharded.Verification
tests/test_fsdp2_wrap_gloo.pyon accelerate 1.16.0: the checkpointed test fails on main (0 == 3) and all 5 pass with this change. On accelerate 1.15.0: 5 passed with this change.tests/test_fsdp2_block_units.py: 3 passed. Without the wrapper lookup, the wrapper case fails.fsdp2shard file set on accelerate 1.16.0: 247 passed, 16 skipped.