Fsdp2 fully_shard embedding and norm #4015
Merged
Merged
Conversation
…rward The FSDP2 path in Accelerate currently passes the plugin's `reshard_after_forward` (default `True`) uniformly to every `fully_shard()` call, including the final call on the whole model that creates the root unit. PyTorch's default (`None`) is smarter: it resolves to `True` for non-root units and `False` for the root, which avoids an unhideable pre-backward all-gather of the root's leftover params (embeddings, final norm, lm_head) that would otherwise be resharded and immediately re-gathered. Stripping the kwarg from the root call lets PyTorch apply its heuristic. Peak memory is unchanged on typical workloads (dominated by backward, where the root is gathered in either case); we save one all-gather per step on the root unit. This also matches torchtitan's default wrapping, which similarly lets the root call fall back to `None`.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
Member
|
lgtm! for context, it was flagged in huggingface/trl#5575 where we measured a significant slowdown because of |
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.
What does this PR do?
This PR updates how we fully shard the model. We create two new units: