Skip to content

[Blackwell] Reserve SMs for DeepGEMM MegaMoE grid barriers - #36657

Merged
hnyls2002 merged 6 commits into
sgl-project:mainfrom
weireweire:fix/blackwell-megamoe-sm-reserve
Aug 28, 2026
Merged

hnyls2002 merged 6 commits into
sgl-project:mainfrom
weireweire:fix/blackwell-megamoe-sm-reserve

Conversation

@weireweire

@weireweire weireweire commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Reserve two SMs by default for Blackwell DeepGEMM MegaMoE launches.
  • Scope the process-wide SM override to the actual MegaMoE kernel calls.
  • Keep symmetric-buffer caching independent of the launch SM count.
  • Keep Hopper/SM90 behavior unchanged and allow the reserve to be tuned or disabled.

Root cause

Blackwell MegaMoE uses an even clustered grid with a whole-grid software barrier. If the launch uses every available SM while another CUDA stream temporarily occupies an SM, not all clusters can become resident. Resident clusters then wait at the barrier for clusters that cannot launch, eventually producing a DeepGEMM grid-sync timeout and a subsequent CUDA launch failure.

Fix

For SM100 and newer, derive the MegaMoE launch size from DeepGEMM's current SM count and reserve two SMs by default. Round the active count down to an even number so it remains compatible with the two-CTA cluster.

Apply the override only around the DeepSeek and Kimi K3 deep_gemm.fp8_fp4_mega_moe calls, then restore DeepGEMM's process-wide setting even when launch setup raises. Gate computation, top-k selection, symmetric-buffer setup, and pre-dispatch continue to use the original setting. The symmetric-buffer cache key remains based only on parameters that affect buffer size or layout.

The separate SM90 MegaMoE implementation remains unchanged. This supersedes the closed #30592 with a smaller diff and explicit architecture gating.

Fixes #30399.

Validation

Validation Full SMs / reserve=0 Reserve=2
CPU unit tests Passed: default reserve, even rounding, zero/excessive reserve, exception restoration, and SM90 no-op
GB300 side-stream repro MegaMoE remained blocked while the side stream was active MegaMoE completed while the side stream was still active
Kernel performance, 100 iterations 0.059546 ms 0.059393 ms
Overlap-scheduler E2E Reproduced DeepGEMM grid-sync timeout 12,748/12,748 warmup requests; 11,052 profiled requests; 0 errors; ~126.7K tok/s/GPU
CUDA Graph/SBO E2E Reproduced liveness failure 12,345 requests; 0 errors; ~69.5K tok/s/GPU
Static/CI checks compileall, pre-commit, lint, build, and Base-A CPU CI passed

CI States

Latest PR Test (Base): ⏳ Run #33208972574
Latest PR Test (Extra): ⏳ Run #33208972664
Latest PR Test (AMD ROCm 7.2): ⏳ Run #33208972751

@weireweire

Copy link
Copy Markdown
Contributor Author

/tag-and-rerun-ci

@weireweire
weireweire force-pushed the fix/blackwell-megamoe-sm-reserve branch from 02b0430 to 0b3393b Compare August 27, 2026 09:23
with mega_stream_ctx:
import deep_gemm

with (

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we scope this SM override to the actual deep_gemm.fp8_fp4_mega_moe call?

set_num_sms is process-wide, and the current context also covers the gate, top-k, buffer setup, and pre-dispatch. Any other DeepGEMM call in this path would inherit the reduced SM count, which seems broader than this fix requires.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make sense, changed to only guard fp8_fp4_mega_moe

num_topk,
hidden,
intermediate_hidden,
num_sms,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the symmetric buffer actually depend on num_sms?

In sgl-deep-gemm 0.1.5.post3, its size and layout are derived from the rank, token, and model dimensions, not the active SM count. If there is no hidden dependency, can we remove this cache-key field and the related argument plumbing? Otherwise changing the reserve can allocate and rendezvous another large symmetric buffer unnecessarily.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, this num_sms won't change after setting anyway, changed.

@BBuf

BBuf commented Aug 27, 2026

Copy link
Copy Markdown
Collaborator

The fix direction makes sense. Before merging, could we carry the Blackwell validation from #30592 over to the current PR head?

At minimum, I would like to see:

  • the side-stream repro with full SMs versus a 2-SM reserve;
  • an overlap-scheduler E2E run confirming that the timeout is gone;
  • a throughput A/B for reserve=0 versus reserve=2;
  • CUDA Graph/SBO coverage.

The current PR only reports CPU unit tests, while this changes a GPU liveness condition and the default MegaMoE launch size.

@weireweire
weireweire force-pushed the fix/blackwell-megamoe-sm-reserve branch from 0b3393b to 9401f06 Compare August 28, 2026 02:05
Root cause:
Blackwell MegaMoE launches an even clustered grid that participates in a whole-grid software barrier. When another stream occupies an SM, launching one cluster per available device SM can leave part of the grid non-resident and trigger a grid-sync timeout.

Fix:
Reserve two SMs by default only while launching each Blackwell fp8_fp4_mega_moe kernel, round the remaining count for two-CTA clusters, and restore DeepGEMM's process-wide setting even when launch setup raises. Apply the same scoped protection to the DeepSeek and Kimi K3 MegaMoE call sites while leaving buffer selection and the SM90 path unchanged.

Validation:
- python3 compileall for the modified source and test
- pre-commit run --all-files --show-diff-on-failure
@weireweire
weireweire force-pushed the fix/blackwell-megamoe-sm-reserve branch from 9401f06 to 06b5da5 Compare August 28, 2026 02:09
@weireweire

Copy link
Copy Markdown
Contributor Author

@BBuf thanks for review, test is updated on pr decripetion.

@weireweire
weireweire requested a review from BBuf August 28, 2026 07:27

@BBuf BBuf left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hnyls2002
hnyls2002 merged commit 3254f9b into sgl-project:main Aug 28, 2026
43 of 65 checks passed
saturn-acc pushed a commit to saturn-acc/sglang that referenced this pull request Aug 31, 2026
…ct#36657)

Co-authored-by: weireweire <20922698+weireweire@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] PD disaggregation: GB200 Deepseek v4 Pro DeepGEMM grid sync timeout

3 participants