feat(fsdp): add --fsdp-reshard-after-forward for ZeRO-2 style training - #196
Open
Rockdu wants to merge 1 commit into
Open
feat(fsdp): add --fsdp-reshard-after-forward for ZeRO-2 style training#196Rockdu wants to merge 1 commit into
Rockdu wants to merge 1 commit into
Conversation
FSDP2 defaults to resharding parameters after forward (ZeRO-3), which re-all-gathers every wrapped block in backward. On setups where the extra memory is affordable, --no-fsdp-reshard-after-forward keeps the gathered parameters between forward and backward (ZeRO-2) and removes the backward all-gather. The flag name mirrors fully_shard's own reshard_after_forward argument rather than inventing a zero2 alias. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
--fsdp-reshard-after-forward/--no-fsdp-reshard-after-forward(default: on, i.e. current behavior).apply_fsdp2now forwards the value to everyfully_shardcall (per-block wraps and the root) asreshard_after_forward.Why
FSDP2 defaults to resharding parameters after forward (ZeRO-3), which re-all-gathers every wrapped block during backward. When the unsharded parameters fit in memory,
--no-fsdp-reshard-after-forwardkeeps them gathered between forward and backward (ZeRO-2), removing the backward all-gather at the cost of holding unsharded parameters through the step.The flag deliberately mirrors
fully_shard's ownreshard_after_forwardargument name (prefixed withfsdp-) instead of introducing azero2alias, so it maps 1:1 to the PyTorch API.Files
miles/utils/arguments.py— new--fsdp-reshard-after-forwardtri-state flag (BooleanOptionalAction, defaultTrue).miles/backends/fsdp_utils/actor.py— pass it viafsdp_kwargsto allfully_shardcalls; include it in the FSDP wrap log line.tests/fast-gpu/backends/fsdp_utils/_param_dtype_map_integration_worker.py— add the new field to the bareNamespacethis worker feedsapply_fsdp2.docs/user-guide/cli-reference.md— document the flag in the training-backend table.Checklist
pre-commit runpasses (run on the touched files;--all-filesnot run)pytest -xis green — not run locally (this environment lackssglang, which the test imports require)python3 train.py --helpstill parses — partially verified: the new argument's parse behavior (default /--no-/ explicit on) was verified in an isolated argparse check; full--helpneedssglanglocally🤖 Generated with Claude Code