Skip to content

[MFSDP] Integrate v2 partial CUDA Graph capture with MoE validation - #9112

Open
WEIXILIN0307 wants to merge 11 commits into
NVIDIA:mainfrom
WEIXILIN0307:feat/mfsdp-v2-partial-cuda-graphs
Open

WEIXILIN0307 wants to merge 11 commits into
NVIDIA:mainfrom
WEIXILIN0307:feat/mfsdp-v2-partial-cuda-graphs

Conversation

@WEIXILIN0307

@WEIXILIN0307 WEIXILIN0307 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What does this PR do?

A BF16 Hybrid MoE model can complete eager steps with Megatron FSDP v2 and then fail at partial CUDA Graph capture. Transformer Engine (TE) rejects the installed FSDP hooks. FSDP can also release gathered weights whose addresses the graph needs for replay.

Pause the FSDP execution hooks during capture and keep the existing gathered-weight allocations alive until graph deletion. Replay goes through the normal module call, so those hooks refresh current weights in the same allocations and keep the existing readiness waits and gradient reduction. Deletion drains GPU work and resets the graph before releasing the allocations.

This preserves the opportunity for independent FSDP all-gather and reduce-scatter to run alongside graph compute. The four-GPU trace at e497dd0 records both, with zero overlap for expert-parallel token all-to-all. The trade-off is higher weight residency at the existing FSDP unit boundaries. The measured proxy retained about 513 MiB per rank. Design and trade-offs · Trace and dependency analysis

Review guide

  1. Start with the parameter group. Check that reshard invalidates readiness, the next gather refreshes the retained allocation, and ordinary eager gathers retain their original allocation path.
  2. Follow the replay dispatch into FSDP capture and replay. Check which hooks are paused and how replay re-enters the normal forward and backward hooks.
  3. Review graph creation and rollback. Check the order of drain, reset and release, including the case where reset raises. Regression cases

Validation

  • On two RTX A6000s with stock TE 2.20.2, the same Hybrid MoE case reaches the hook rejection at capture on base e54d389 and matches eager after replay on 4d48616. All five focused cases pass per rank at 4d48616, covering GPT, MLA, Hybrid, ZeRO-1/2/3, two-microbatch accumulation, deletion, recapture and controlled rollback. Tests
  • Two additional GPT cases pass per rank for evaluation and native checkpoint restore in a local composition with evaluation follow-up c6b78bb and [MFSDP] Preserve native v2 DTensor checkpoint projections #9374 at 4a968a8. The evaluation test applies to that follow-up revision. The tested retry after an exception in TE warmup uses the graph implementation from TE Pass gracefully if token_id not found in message #3862 at 22d4727. Normal training uses stock TE. TE #3862
  • Four-GPU evidence at e497dd0 shows ordinary and expert-DP all-gather and reduce-scatter overlapping graph compute with EP=2 and expert-DP=2. The a8a8424 WikiText-103 proxy had 13.10% lower step time at EP2 and 0.53% higher step time at EP1 versus eager. Normal EP1 graph execution took 4.95% less step time than the serialized graph control. These measurements apply to those revisions and configurations. The control measures total step time under serialization. Trace and commands · Historical performance, memory and logs
python -m torch.distributed.run --standalone --nproc-per-node=2 -m pytest -q --experimental \
  tests/unit_tests/distributed/mfsdp_v2/test_mcore_partial_cuda_graph.py

Scope

The initial path uses fixed-shape BF16, TP=PP=CP=1, TE ≥2.10 for explicit graph reset, and no symmetric memory. It captures attention, dense MLP, the MoE router and router-paired preprocess. Expert dispatch, expert compute and combine remain eager. Upstream GPU CI and functional-test registration are pending. Configuration and limits

Issue tracking

Design discussion in #9113.

Code provenance

No external code copied or adapted.

Contribution process

Pre-checks

  • I have added relevant unit tests.
  • I have added relevant functional tests.
  • If this PR adds or changes a GPU kernel (Triton, jit_fuser/torch.compile, CUDA extension, TE or external-library dispatch, or a scatter/index accumulation), I have added or updated its bit-exact determinism test and registered it in tests/unit_tests/determinism/kernels/manifest.py (guide). No numerical kernel changed.
  • I have added proper typing to my code (guidelines). Baseline diagnostics remain.
  • I have added relevant documentation.
  • I have run the autoformatter.sh on my PR.

@copy-pr-bot

copy-pr-bot Bot commented Nov 8, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@WEIXILIN0307
WEIXILIN0307 force-pushed the feat/mfsdp-v2-partial-cuda-graphs branch from 45bc0d3 to 5c12bd9 Compare November 12, 2026 06:17
@WEIXILIN0307 WEIXILIN0307 changed the title [Dev] Integrate Megatron FSDP v2 with partial CUDA Graphs [MFSDP] Integrate v2 partial CUDA Graph capture with MoE validation Nov 12, 2026
@WEIXILIN0307
WEIXILIN0307 changed the base branch from dev to main November 12, 2026 06:23
Suspend owned FSDP hooks during capture, retain existing gathered buffers and replay through normal module hooks. Clone mutable RNG contents for rollback. Cover MoE state parity, communication streams, deletion, native checkpoint continuation and recapture. Keep Combined1F1B, EP reordering and TE-private recovery outside this change.

Signed-off-by: Pinoeer-kingxi <13022943007@163.com>
@WEIXILIN0307
WEIXILIN0307 force-pushed the feat/mfsdp-v2-partial-cuda-graphs branch from 5c12bd9 to 26714de Compare November 12, 2026 08:05
WEIXILIN0307 and others added 10 commits November 15, 2026 19:28
Signed-off-by: Pinoeer-kingxi <13022943007@163.com>
…acts

Signed-off-by: Pinoeer-kingxi <13022943007@163.com>
Move wrapper-aware graph dispatch to TECudaGraphMixin after the upstream TE refactor. Preserve native deletion callbacks and migrate retained-graph lifecycle checks to te_cuda_graphs.

Signed-off-by: Pinoeer-kingxi <weixilin307@gmail.com>
Exercise GPT, Hybrid, and MLA with representative sharding and stream policies. Fold successful RNG, address, and recapture checks into the parity test, and keep the distinct capture failure paths. Reference evaluation and checkpoint composition evidence from the independent fixes.

Signed-off-by: Pinoeer-kingxi <weixilin307@gmail.com>
Use representative GPT and Hybrid MoE cases and reuse one warmed model for recoverable startup and post-capture failures. Check a secondary cleanup failure without retrying after the helper requires a restart.

Signed-off-by: Pinoeer-kingxi <weixilin307@gmail.com>
Restore the MLA ZeRO-2 path and numerical parity after rollback and retry. Guard against capture over live graphs and confirm launches after recapture. Exercise configuration rejection and caller hook restoration in the existing rollback case.

Signed-off-by: Pinoeer-kingxi <weixilin307@gmail.com>
Signed-off-by: Pinoeer-kingxi <weixilin307@gmail.com>
Attach any capture-exit reshard failure to the original exception and let the graph helper finish cleanup. Exercise this fault in the existing cleanup case and share standalone configuration validation with the parity case.

Signed-off-by: Pinoeer-kingxi <weixilin307@gmail.com>
Use the real Transformer Engine hook rejection to verify that a capture-exit reshard failure preserves the original error and the caller hook.

Signed-off-by: Pinoeer-kingxi <weixilin307@gmail.com>
Gathered buffers can already be allocated before the first eager gather. Keep the original eager resize path, and skip resize only when a capture owns the allocation. Both paths refresh weights and record readiness as before.

Signed-off-by: Pinoeer-kingxi <weixilin307@gmail.com>
@WEIXILIN0307
WEIXILIN0307 marked this pull request as ready for review November 25, 2026 01:50
@WEIXILIN0307
WEIXILIN0307 requested review from a team as code owners November 25, 2026 01:50
@svcnvidia-nemo-ci
svcnvidia-nemo-ci requested a review from a team November 25, 2026 01:50
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the waiting-on-maintainers Waiting on maintainers to respond label Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-request waiting-on-maintainers Waiting on maintainers to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants