Pre-overlap collective bucketing pass for FSDP/DDP#412
Open
fmassa wants to merge 1 commit into
Open
Conversation
PyTorch's overlap scheduler adds sequential timeline dependencies between all consecutive events on each process group, which prevents its downstream bucketer from merging collectives that were originally independent. This PR adds a pre-pass that merges per-parameter FSDP/DDP collectives before the overlap scheduler runs, so it sees fewer, larger collectives. The pass targets three collective types: forward all-gathers (param-derived), backward reduce-scatters (terminal-derived), and backward all-reduces (terminal-derived, for DDP). The implementation is split into two phases: - Tagging runs on the joint graph (where placeholder metadata is available) and marks eligible collectives via node.meta. Tags survive the fw/bw partition via node_copy's shallow copy. - Bucketing runs on the split fw/bw graphs inside the compiler, reads the tags, and merges collectives using PyTorch's existing merge functions. This PR also fixes a pre-existing bug in _copy_descriptors_and_rename_placeholders where make_fx could nest the output tuple while desc stayed flat, causing get_all_input_and_grad_nodes's zip to silently mismatch output nodes with their descriptors. Results on LLaMA: AG 290→98 (fwd), 225→97 (bwd recomputed), RS 290→194 (bwd). Test plan - example_autoparallel.py passes (compile=False) - example_llama3.py passes - pytest tests/ passes Authored with Claude.
IvanKobzarev
approved these changes
Apr 10, 2026
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.
PyTorch's overlap scheduler adds sequential timeline dependencies between all consecutive events on each process group, which prevents its downstream bucketer from merging collectives that were originally independent. This PR adds a pre-pass that merges per-parameter FSDP/DDP collectives before the overlap scheduler runs, so it sees fewer, larger collectives.
The pass targets three collective types: forward all-gathers (param-derived), backward reduce-scatters (terminal-derived), and backward all-reduces (terminal-derived, for DDP).
The implementation is split into two phases:
This PR also fixes a pre-existing bug in
_copy_descriptors_and_rename_placeholderswheremake_fxcould nest the output tuple while desc stayed flat, causingget_all_input_and_grad_nodes's zip to silently mismatch output nodes with their descriptors.Results on LLaMA: AG 290→98 (fwd), 225→97 (bwd recomputed), RS 290→194 (bwd).
Test plan
Authored with Claude.