Skip to content

Fix MegaMoE combine readiness under CUDA graph replay (cherry-pick deepseek-ai#451) - #59

Merged
zyongye merged 3 commits into
vllm-project:devfrom
gau-nernst:megamoe-graph-replay-readiness
Nov 12, 2026
Merged

zyongye merged 3 commits into
vllm-project:devfrom
gau-nernst:megamoe-graph-replay-readiness

Conversation

@gau-nernst

Copy link
Copy Markdown

Cherry-pick of deepseek-ai#451 ("Reset MegaMoE combine readiness for CUDA graph replay", still open upstream) onto dev, extended to the SiTU and NVFP4 kernels. This is the MegaMoE counterpart of #48 (deepseek-ai#478). deepseek-ai#478 notes that MegaMoE combine readiness has the same stale-tag problem and that deepseek-ai#451 addresses it.

Problem

MegaMoE tags combine readiness with the launch's %gridid (grid index + 1). A CUDA graph kernel node keeps the same %gridid on every replay, so at EP > 1 a rank can accept a peer's readiness tag left over from the previous replay. It then reads that peer's combine data before the current launch's L2 writes land, and returns stale outputs.

Fix (upstream)

Before the existing dispatch pull barrier, each rank clears its local combine_ready_grid_idx flags with one system-scope store per rank. The barrier orders that reset before every peer's current L2 completion notification. There is no new barrier and no workspace or ABI change.

Commits

  • deepseek-ai/DeepGEMM@d7442af, FP8×FP4 kernel: applied cleanly except for a comment in layout/mega_moe.cuh, which I merged with dev's current description.
  • deepseek-ai/DeepGEMM@7e924a8, BF16 kernel: applied cleanly.
  • The same change for the SM100 FP8×FP4 SiTU and NVFP4 kernels, which exist only on dev and tag readiness the same way. The SM90 kernel already clears these flags before the pull barrier. sm100_fp4_fp4_mega_moe does not use readiness tags.

Test

4x GB200, python tests/test_mega_moe.py --num-processes 4 --num-max-tokens-per-rank 1000 --num-tokens 1000 --hidden 2560 --intermediate-hidden 640 --num-experts 256 --num-topk 8 --num-shared-experts 0 --emu-reference --num-correctness-tests 1:

dev (0f7698f) this PR
Accuracy vs PyTorch reference pass pass
CUDA graph replay vs eager (bitwise) fails, 2/2 runs: CUDA graph replay 2 differs from the eager launch passes, 2/2 runs

This graph check covers the FP8×FP4 SwiGLU kernel. The BF16, SiTU and NVFP4 kernels receive the identical change. In this repo's tests, the BF16 check needs a DeepEP baseline, and the SiTU and NVFP4 tests do not compare graph replays against eager launches.

AI assistance (Claude) was used for this port and its validation.

🤖 Generated with Claude Code

foreverrookie and others added 3 commits November 12, 2026 05:59
CUDA graph replay can reuse the kernel grid ID. Clear local peer-ready flags
before the existing pull barrier so a later replay cannot consume the previous
invocation's combine data when inputs change. Preserve the workspace layout and
existing barriers.

Validated on 8 B300 ranks with input staging, unequal/empty source ranks, and
successive CUDA graph replays with updated inputs (3 tests passed per rank).

Co-authored-by: Codex <[email protected]>
Signed-off-by: foreverrookie <[email protected]>
(cherry picked from commit d7442af)
Reset peer-ready flags before the existing pull barrier, matching the
FP8/FP4 path and preventing stale completion tags on graph replay.

Co-authored-by: OpenAI Codex <[email protected]>
Signed-off-by: foreverrookie <[email protected]>
(cherry picked from commit 7e924a8)
… NVFP4 kernels

Apply the readiness reset of deepseek-ai#451 to the SM100 FP8xFP4
SiTU and NVFP4 MegaMoE kernels, which tag combine readiness with the grid
index in the same way. The SM90 kernel already clears it before the pull
barrier.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: Thien Tran <[email protected]>
@gau-nernst
gau-nernst force-pushed the megamoe-graph-replay-readiness branch from ea1e31f to dfb8c57 Compare November 12, 2026 06:16
@zyongye
zyongye merged commit 196f338 into vllm-project:dev Nov 12, 2026
1 check passed
@gau-nernst
gau-nernst deleted the megamoe-graph-replay-readiness branch November 12, 2026 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants