Skip to content

[Perf] [NVIDIA] kimi-k3: Add an opt-in die-local routed MoE for DFlash target verify on two-die GPUs - #52972

Open
aryatsc wants to merge 11 commits into
sgl-project:mainfrom
aryatsc:arya/k3-moe-die-local-verify
Open

aryatsc wants to merge 11 commits into
sgl-project:mainfrom
aryatsc:arya/k3-moe-die-local-verify

Conversation

@aryatsc

@aryatsc aryatsc commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Depends on sgl-project/DeepGEMM#166 (the one-rank kernel API this path calls). Until a release of that library includes it, the capability check here keeps the stock path, so this PR is safe to merge first but has no effect until then.

This is a die-locality change. A VR200 GPU has two dies, and a read from the other die's memory crosses the die-to-die link. The gain here is where the weights live: on ordinary pages the same kernel is +6.5 % to -4.9 % against tuned trtllm-gen per call, on die-local pages it is -0.6 % to -23.0 % (development build; +0.4 % to -23.1 % on a build of sgl-project/DeepGEMM#166), and the share of HBM bytes that cross dies falls from 50 to 54 % to about 25 %.

On a two-die GPU (NVIDIA VR200, SM 10.7) the routed-expert kernel of Kimi K3.1 (FlashInfer trtllm-gen) reads expert weights from wherever the allocator put them: 50 to 54 % of its HBM bytes cross the die-to-die link. At EP8 it is the largest kernel of a DFLASH target-verify round. This PR keeps each rank's routed-expert weights once, in the trtllm-gen layout, on pages homed on the die that reads them, and runs DeepGEMM's one-rank MegaMoE kernel on those weights for the verify widths where it wins. A call the kernel takes is bitwise equal to the same call on trtllm-gen; every other call runs trtllm-gen as before.

Off by default. It needs the one-rank API of sgl-project/DeepGEMM#166; without it a capability check keeps the stock path and logs one warning.

Modifications

  • srt/layers/moe/k3_die_local_moe.py (new): eligibility and fallback, die-local page placement, zero-copy weight views, per-width dispatch.
  • srt/layers/moe/k3_die_local_moe_widths.json (new): width table, 23 row counts (10 to 235) without all-reduce fusion, 13 (80 to 235) with it.
  • srt/layers/moe/k3_deepgemm_routed.py (new): capability check, layer rules, one-rank buffer, kernel call, all-reduce order policy.
  • kernels/ops/moe/k3_route_quant_packed.py and .cuh (new): routing and MXFP8 activation quant in one launch.
  • moe_route_quant_fused.py, route_quant_handoff.py, moe_runner/flashinfer_trtllm.py: dispatch branch.
  • srt/layers/quantization/mxfp4.py: final w13 / w2 stacks go to die-local pages.
  • srt/models/kimi_k3.py: with SGLANG_K3_AR_FUSION, a call the kernel takes reduces routed latent and shared-expert output in one pull all-reduce behind the kernel. The kernel needs every SM; the stock overlapped order costs +7.0 / +4.8 ms per round at 80 / 160 rows.

One switch: SGLANG_K3_ROUTED_MOE_DEEPGEMM (default False).

Fallback: a layer keeps the stock path and logs the reason when DeepGEMM lacks the one-rank API, the device is not SM 10.7 with two locality domains, the expert shape is not K3.1 EP8 (896 experts, 112 per rank), or die-local placement is unavailable. Prefill, extend and plain decode are unchanged.

Accuracy Tests

Bitwise equality (tokens and logprobs) with stock:

  • Kernel: 0 output elements differ from trtllm-gen in 49 cells, 5 to 235 rows (development build), and in every cell of the [SM100] Mega MoE: one-rank FP8xFP4 fast paths for die-local weights, with opt-in bitwise parity with trtllm-gen DeepGEMM#166 table.
  • Engine at SGLang 4469f9fc, runtime bundle on, deterministic set of 9 sections (1 to 45 concurrent requests): equal to stock at the same request cap in all 9 sections. Against stock at its default cap (43 slots, 41 here) the two 45-request sections are 27 of 45 token-equal; stock at the lower cap shows the same 27 of 45, so that is batch composition.
  • Main 563813c (two stock boots, three of this PR): equal to stock up to 16 concurrent requests; the 45-request sections differ with the cap (35 vs 36) and were not compared at an equal cap. The posted head equals the previous head in all 9 sections, and the two stock boots equal each other in all 9.
  • Below 80 rows the stock path runs, so outputs are identical.
  • Unit tests: 3 CPU tests in one file (fallback without the one-rank API, width-table dispatch, page homing).

Speed Tests and Profiling

Kimi K3.1 Pro, 2 x 4 VR200 GPUs, TP8 / DCP8, EP8, DFLASH, runtime bundle on. One hardware type, one model.

Kernel, per call against trtllm-gen with the engine's autotuned tactic (one GPU, 5 to 235 rows). Full table in sgl-project/DeepGEMM#166.

Time Net energy
This form on a build of sgl-project/DeepGEMM#166 (die-local pages, three processes) +0.4 % (5 rows), -5.4 % (10 rows) to -23.1 % (235 rows) -0.7 % to -14.6 %
DeepGEMM dev MegaMoE with localize, unmodified (same pages, three processes) +38.0 % (5 rows) to -13.6 % (235 rows) -9.8 % to -13.7 %
Development build based on DeepGEMM v0.2.8, die-local pages -0.6 % (5 rows) to -23.0 % (235 rows) -1.2 % to -14.4 %
Development build, same kernel on ordinary pages +6.5 % to -4.9 % +14.3 % to +0.6 %

The first row is the kernel this PR calls once sgl-project/DeepGEMM#166 is in; it has no ordinary-pages run of its own, and at 5 rows it is level with trtllm-gen (the width table starts at 80 rows with all-reduce fusion). The ordinary-pages row and the all-reduce orders were measured with A/B switches that have since been removed from this PR to keep it small; the default path is unchanged. The gain is the placement: 25.2 to 25.8 % of HBM bytes cross dies with this PR.

Verify-round time in the engine, ms (median of the plateau):

80 rows 160 rows Change
4469f9fc, stock EP8, boot 1 / boot 2 20.00 / 19.97 26.39 / 26.34
4469f9fc, this PR, boot 1 / boot 2 19.23 / 19.25 25.28 / 25.24 -3.8 % / -4.3 %
Main 563813c, stock, boot 1 / boot 2 19.97 / 19.93 25.88 / 25.85
Main, this PR on a build of sgl-project/DeepGEMM#166, boot 1 / 2 / 3 19.14 / 19.14 / 19.13 24.63 / 24.64 / 24.66 -4.0 to -4.2 % / -4.6 to -4.8 %

The 4469f9fc rows used the development form of this change and a DeepGEMM build based on v0.2.8. The profile shows exactly one pull per MoE block in 2,912 of 2,912 kernel-taken layers. Below 80 rows the round time is level. On main, boot 3 of this PR is the posted head; boots 1 and 2 are the same path before two rounds of trimming (comments, a width-table override, debug logs, dead code).

Energy per verify round (all 8 GPUs, NVML counters over the same plateaus; boots 1 and 2 on main): -2.9 to -3.5 % at 80 rows and -3.0 to -3.7 % at 160 at 4469f9fc; -2.3 to -2.8 % and -3.8 to -4.0 % on main. Two stock boots differ by at most 0.2 % at those widths.

Serving (4469f9fc, same-turn decode rate, 95 % interval, single pairs): +2.8 % (-1.0 to +5.8) at 32 sessions. At 16 sessions the verify batch never reaches 80 rows and both builds run only trtllm-gen; that pair measured -3.7 % (-5.3 to -0.0), not a kernel effect.

Limits

  • Scope: helps from 15 concurrent decoding requests (80 verify rows) upward and is neutral below. EP8 on 8 GPUs only; the eligibility check rejects EP2 and TP-sharded expert shapes. EP16 and EP32 were not run (two 4-GPU trays).
  • KV capacity: 41 vs 43 request slots at 4469f9fc and 35 vs 36 on main, from about 1 GiB per rank of allocator-idle memory (not a second weight copy). Not fixed here.
  • Depends on [SM100] Mega MoE: one-rank FP8xFP4 fast paths for die-local weights, with opt-in bitwise parity with trtllm-gen DeepGEMM#166. The engine results are two boots a side at 4469f9fc and two stock / three of this PR at main 563813c, none on today's main head; the serving results are single pairs.
  • Not run: pre-commit; a GPU CI test (no runner has two locality domains).

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /approve-ci, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ⊘ Skipped -- a maintainer comments /tag-and-rerun-ci to run CI tests.
Latest PR Test (Extra): ⊘ Skipped -- a maintainer comments /tag-and-rerun-ci to run CI tests.
Latest PR Test (AMD ROCm 10): ⚠️ Run #45802357470

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

aryatsc and others added 2 commits November 24, 2026 21:14
…h target verify on two-die GPUs

SGLANG_K3_ROUTED_MOE_DEEPGEMM (off by default): each EP rank keeps its
routed-expert weights once, in the trtllm-gen layout, on pages homed on the
locality domain that reads them, and target-verify calls whose row count is in
a per-width table run DeepGEMM's one-rank MegaMoE kernel on those weights.
Every other call runs trtllm-gen as before. With SGLANG_K3_AR_FUSION a call the
kernel takes reduces the routed latent and the shared-expert output in one
pull all-reduce behind the kernel.

A layer, device, model shape or DeepGEMM build that does not qualify keeps the
default path and logs one warning.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
… its fallback and its all-reduce order

Co-Authored-By: Claude Fable 5.2 <[email protected]>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

aryatsc and others added 5 commits November 25, 2026 14:01
Share the fixtures, fold per-case tests into tables and merge the
capability tests into test_k3_die_local_moe.py. 1,658 -> 1,054 lines,
39 tests.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Keep the one switch and the width-table override. Placement is always
die-local, a call the kernel takes always reduces latent and shared in
one pull, and k3_ar_fusion.py is unchanged from main again. The default
behaviour is the same as before.

Co-Authored-By: Claude Fable 5.2 <[email protected]>

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

jit-kernel quant LLM Quantization

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant