fix: disable dynamo on Ulysses all-to-all to prevent FSDP×compile NCCL deadlock - #3195
Merged
Conversation
…L deadlock When torch.compile is used with Ulysses context parallelism and FSDP, the all-to-all collectives are traced into the compiled backward graph while FSDP's reduce-scatter hooks fire eagerly via the autograd engine. The compiler may reorder the all-to-all backward differently across ranks, causing rank 0 to wait on reduce_scatter while rank 1 waits on all_to_all — a classic collective ordering mismatch that deadlocks NCCL after the 1-hour watchdog timeout (PR #3186, job 1578). Wrapping _all_to_all_seq_to_head and _all_to_all_head_to_seq with torch._dynamo.disable forces a graph break around the collectives so they execute eagerly in the autograd engine, restoring a single consistent backward ordering between the two collective systems.
Contributor
|
this unblocks my laguna training should me merge? |
rasdani
approved these changes
Aug 6, 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.
Summary
Fixes the NCCL collective ordering deadlock that occurs when
torch.compileis used together with Ulysses context parallelism and FSDP (reported in PR #3186, Slurm job 1578).Root cause
At NCCL sequence number 3750, rank 0 was stuck on FSDP's
reduce_scatter_tensor(frompost_backward) while rank 1 was stuck on Ulysses'all_to_all_single(fromdist_nn.functionalbackward). Both ranks had completed all collectives up to 3749, then diverged — a classic collective ordering mismatch that deadlocks NCCL after the 1-hour watchdog timeout.The issue is that
torch.compiletraces the Ulysses all-to-all collectives into the compiled backward graph for each decoder layer, while FSDP'spost_backwardreduce-scatter hooks fire eagerly via the autograd engine outside the compiled graph. The compiler may reorder the all-to-all backward differently across ranks (especially for MoE models with data-dependent expert routing or variable-length sequences), causing the two collective systems to interleave in inconsistent orders across ranks.Fix
Wrap
_all_to_all_seq_to_headand_all_to_all_head_to_seqwith@torch._dynamo.disable. This forces a graph break around the collectives so they execute eagerly in the autograd engine — the same scheduling path as FSDP hooks — restoring a single consistent backward ordering between the two collective systems. This mirrors the existingtorch._dynamo.disableon the FA4 flash kernel itself.Note
Medium Risk
Touches distributed training collectives under compile+FSDP; the change is small and aligns scheduling with existing FA4 dynamo-disable behavior, but incorrect ordering could still deadlock or regress multi-GPU training.
Overview
Fixes an NCCL collective-ordering deadlock when
torch.compile, Ulysses context parallelism, and FSDP run together (PR #3186 / job 1578)._all_to_all_seq_to_headand_all_to_all_head_to_seqinulysses_attn.pyare now wrapped with@torch._dynamo.disable, with docstrings noting that Ulyssesall_to_all_singlemust run eagerly in the autograd engine so its backward ordering matches FSDPpost_backwardreduce-scatter hooks instead of being reordered inside compiled backward graphs (which can differ across ranks).This follows the same pattern already used for the FA4 flash kernel in that module.
Reviewed by Cursor Bugbot for commit a8e305f. Bugbot is set up for automated code reviews on this repo. Configure here.