Skip to content

perf(MegaMoE): add the SM90 DeepGEMM backend for GLM-5.3-Flash - #5186

Merged
silencelamb merged 19 commits into
InternLM:mainfrom
silencelamb:pr/glm53-sm90-megamoe
Dec 3, 2026
Merged

silencelamb merged 19 commits into
InternLM:mainfrom
silencelamb:pr/glm53-sm90-megamoe

Conversation

@silencelamb

@silencelamb silencelamb commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

DeepGEMM MegaMoE on SM90

Adds the opt-in --moe-backend deepgemm_mega_moe to the GLM-5.3-Flash target model for single-node SM90, DP8/EP8/TP1, BF16 activations and 128×128 block-FP8 weights. Routed experts keep one interleaved FC1 payload and separate FP32 gate/up scales. The provider fuses the checkpoint's shared expert. Group-wide token counts and the calibrated engine budget select a workspace or DeepEP normal fallback. DeepEP reads the same interleaved FC1 and computes the shared expert on its usual path.

The optional cu130 target builds a wheel from DeepLink-org/DeepGEMM-MegaMoE at 9730551. The separate deep_gemm_mega package coexists with native deep_gemm used by KPool. FlashInfer pull dispatch is tracked in the stacked draft #5214.

Incremental AgentX performance

The DeepGEMM-only head measured at C90 was d8e46833. The later head change initializes two fields in the route-capture test fixture. The historical C32 benchmark below compares native DeepEP with MegaMoE at matched MTP depths.

Cumulative configuration C Decode tok/s Requests/s Good req/s TTFT P50 / P95 (ms) TPOT P50 / P95 (ms) Both P50s pass
DeepGEMM MegaMoE 90 1,307.87 1.5125 0.7451 840.7 / 3,574.7 24.38 / 74.94 Yes

8×H200, DP8/EP8/TP1, native MTP3, RDMA Mooncake, Weka 256K, independent 1,800 s scored windows. Five-PR AgentX report with configurations, controls and concurrency sweeps.

Full GSM8K accuracy on this PR

Scored 0647531c on GLM-5.3-Flash FP8 with only the feature in this PR enabled. All 1,319 test questions used the same five train demonstrations, greedy decoding, seed 42, C32 through the router and the historical QA setting max_tokens=1024 (generated tokens per question, with input tokens counted separately). The grader compares the last parsable number after #### with the gold answer and includes all 1,319 questions.

Enabled configuration Correct / total Accuracy HTTP errors Missing numeric answer Outputs at limit
--moe-backend deepgemm_mega_moe 1,217 / 1,319 92.27% 0 0 0

The historical QA image on the same GLM-5.3-Flash FP8 weights scored 91.74% / 91.58% (1,210 / 1,208 correct out of 1,319). The earlier 91.96% QA result used a different checkpoint.

Per-PR counts, repeat runs and scoring evidence.

Split validation

On 8×H200, the previous interleaved backend and the extracted DeepGEMM implementation on base 517cb6d7 measured 1298.67 / 1300.92 output tok/s and 0.6995 / 0.7174 good req/s in separate formal C90 Weka windows with native KDA prefill. The sampled real MoE layer was elementwise identical across prefill, mixed verify, overflow fallback, decode graph replay and partial expert reload. Forty-one fixed-history next-token probes agreed on top-1 and top-8 log probabilities. Long, freely generated C64 sequences matched end to end for 302/384 requests. After merging current main (3d6f0bbf), the route-capture and MegaMoE suites passed 45 tests with one CUDA-only skip after fixing the native test fixture.

Earlier isolated MegaMoE measurements

Single node, 8×H200, Weka 256K, C32, seed 42, local prefix caching, native BF16 KDA prefill, Mooncake off. Each arm ran a separate 1,800-second window. The native DeepEP and DeepGEMM MegaMoE arms used the same MTP depth and approximately the same ready GPU memory budget per rank.

MTP depth Native output tok/s MegaMoE output tok/s Gain TPOT p50, native → MegaMoE
0 575.86 645.22 +12.05% 39.37 → 34.36 ms
3 966.51 1,052.21 +8.87% 17.83 → 15.01 ms
5 1,045.56 1,096.64 +4.89% 16.12 → 13.77 ms

At MTP3, 1,424/2,126 native requests and 1,698/2,244 MegaMoE requests met both the 3 s TTFT and 40 tok/s per-user SLOs. H200 AgentX and MTP results · C32 per-depth measurements

A separate fixed-I/O test, MTP off, 8,192 input tokens, 256 output tokens, C64, measured 1,316.91 → 1,603.32 output tok/s (+21.7%). With 64K cold inputs, C32, matched GPU residency and native prefill, native MoE and DeepGEMM measured 703 and 658 tok/s, respectively. Fused prefill matched the native first token on 32/64 long prompts. In an earlier prefill-only comparison with MegaMoE decode enabled in both arms, native vs fused prefill answered 1,219 vs 1,216 of 1,319 GSM8K questions correctly.

@silencelamb silencelamb changed the title [Feature] Add opt-in SM90 MegaMoE backends for GLM-5.3-Flash perf(MegaMoE): add the SM90 DeepGEMM backend for GLM-5.3-Flash Nov 30, 2026

@RunningLeon RunningLeon 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.

Thanks for the implementation and the matched DeepEP benchmarks. I tested the staging kernel and the affected unit tests on H200, but did not run the full eight-rank provider. Please address the inline findings before merge.

Comment thread lmdeploy/pytorch/models/glm5_next.py Resolved
Comment thread tests/pytorch/test_glm53_mega_moe.py Resolved
@silencelamb
silencelamb requested a review from hehesnail December 1, 2026 23:13

@zzwwrr zzwwrr 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The interleaved activation path lacks numerical tests for gate/up pairing, including BF16 inputs, precise multiplication, and clamped values.

1 open issue
What changed in this PR

Adds an opt-in DeepGEMM MegaMoE backend for GLM-5.3-Flash in the PyTorch engine, targeting single-node SM90 with DP8/EP8/TP1. FlashInfer support remains separate in #5214.

Changes:

  • Integrates fused routed/shared experts, interleaved FP8 weights, and DeepEP fallback.
  • Coordinates workspace selection, graph execution, and sleep/wakeup across ranks.
  • Adds regression tests and an optional CUDA 13 provider image.
File Description
tests/​pytorch/​test_glm53_mega_moe.py Tests backend integration and workspace lifecycle.
tests/​pytorch/​nn/​test_moe_deepep.py Updates fallback builder assertions.
tests/​pytorch/​models/​test_routed_experts.py Initializes new MoE fixture fields.
tests/​pytorch/​engine/​test_model_agent.py Updates model-agent fixtures.
tests/​pytorch/​engine/​test_model_agent_kv_connector.py Tests workspace sleep/wakeup ordering.
tests/​pytorch/​engine/​test_compact_forward.py Supplies warmup backend configuration.
lmdeploy/​serve/​openai/​launch_server.py Preserves peer GPU visibility.
lmdeploy/​pytorch/​nn/​moe/​blocked_fp8.py Loads interleaved expert weights.
lmdeploy/​pytorch/​models/​glm5_next.py Integrates MegaMoE and shared-expert fusion.
lmdeploy/​pytorch/​models/​deepseek_v2.py Extracts reusable expert execution.
lmdeploy/​pytorch/​model_inputs.py Carries token counts and backend settings.
lmdeploy/​pytorch/​kernels/​cuda/​moe/​ep_fp8.py Supports custom gate/up projection.
lmdeploy/​pytorch/​kernels/​cuda/​activation.py Supports interleaved SwiGLU inputs.
lmdeploy/​pytorch/​engine/​model_agent/​agent.py Manages backend warmup and workspace lifecycle.
lmdeploy/​pytorch/​engine/​executor/​ray_executor.py Synchronizes budgets and GPU bindings.
lmdeploy/​pytorch/​engine/​config_builder.py Propagates backend selection.
lmdeploy/​pytorch/​config.py Adds internal backend configuration.
lmdeploy/​pytorch/​backends/​cuda/​moe/​mega_moe.py Implements the SM90 provider runner.
lmdeploy/​pytorch/​backends/​cuda/​moe/​blocked_fp8.py Connects interleaved DeepEP fallback.
lmdeploy/​pytorch/​backends/​cuda/​graph_runner/​standard.py Adds exact capture sizes.
lmdeploy/​pytorch/​backends/​cuda/​graph_runner/​runner.py Configures mixed-step capture sizes.
lmdeploy/​messages.py Exposes and validates backend selection.
lmdeploy/​cli/​serve.py Adds the backend CLI option.
docker/​Dockerfile Adds an optional MegaMoE image target.
docker/​check_deepgemm_mega.py Checks provider coexistence and packaged files.
docker/​build_deepgemm_mega.sh Builds the pinned provider wheel.
.github/​workflows/​test_docker.yml Limits build parallelism.

Review effort: Balanced

Comment on lines +40 to +42
if GATE_UP_INTERLEAVE:
weight_col = offs_n // GATE_UP_INTERLEAVE * (2 * GATE_UP_INTERLEAVE) + offs_n % GATE_UP_INTERLEAVE
up_offset = GATE_UP_INTERLEAVE

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added four regression cases in tests/pytorch/kernel/test_activation.py. They pack independent BF16 gate and up tensors in groups of eight and run the Triton kernel with precise_mul=True. The PyTorch reference uses the original tensors, applies SiLU and multiplication in FP32, then rounds once to BF16. The cases cover widths 520 (a partial final tile) and 2048 (the GLM expert width), both unclamped and with the model’s 10.0 clamp. Commit e4cbaf7f

On NVIDIA H200, all four cases matched the reference elementwise with rtol=0, atol=0. The activation and MegaMoE suites passed all 49 tests. I also checked that the tests catch the reported failure mode: deliberately reading the gate slot for up failed all four cases. Rounding SiLU to BF16 before multiplication also failed all four, and incorrectly applying a lower clamp to gate failed both clamped cases.

@RunningLeon RunningLeon 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.

pls resolve conflicts

Keep the global KV length and per-rank token counts in DPMeta. Supply both KV transfer settings and the prefill budget to the native DFlash build fixture.
silencelamb added a commit to silencelamb/lmdeploy that referenced this pull request Dec 2, 2026
Preserve the node GPU order while Ray records accelerator assignments. Expose the EP peer mask before CUDA initialization and resolve the assigned GPU in the worker process before distributed setup.
…ternLM#5186

Use the final device IDs produced by the DP launcher once. Supply the ordered node-local peers separately when the CUDA communication policy requires them, and leave actor binding to the Ray assignment.

@RunningLeon RunningLeon 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

Keep the test-docker workflow from main after InternLM#5224 landed the same wheel concurrency limits. Retain the opt-in MegaMoE target alongside the upstream FlashInfer MLA runtime dependency.
@silencelamb
silencelamb merged commit b5b7936 into InternLM:main Dec 3, 2026
14 checks passed
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.

5 participants