Repository navigation
[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
Open
[Perf] [NVIDIA] kimi-k3: Add an opt-in die-local routed MoE for DFlash target verify on two-die GPUs#52972aryatsc wants to merge 11 commits into
aryatsc wants to merge 11 commits into
Conversation
…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]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
aryatsc
marked this pull request as ready for review
November 25, 2026 07:13
aryatsc
requested review from
Alisehen,
AniZpZ,
BBuf,
Edwardf0t1,
FlamingoPg,
HaiShaw,
OrangeRedeng,
Ying1123,
b8zhong,
ch-wan and
merrymercy
as code owners
November 25, 2026 07:13
aryatsc
requested review from
DarkSharpness,
Fridge003,
HydraQYH,
celve,
ispobock and
yuan-luo
as code owners
November 25, 2026 07:13
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
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.pyand.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: finalw13/w2stacks go to die-local pages.srt/models/kimi_k3.py: withSGLANG_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(defaultFalse).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:
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.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.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.
devMegaMoE withlocalize, unmodified (same pages, three processes)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):
4469f9fc, stock EP8, boot 1 / boot 24469f9fc, this PR, boot 1 / boot 2563813c, stock, boot 1 / boot 2The
4469f9fcrows 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
4469f9fcand 35 vs 36 on main, from about 1 GiB per rank of allocator-idle memory (not a second weight copy). Not fixed here.4469f9fcand two stock / three of this PR at main563813c, none on today's main head; the serving results are single pairs.pre-commit; a GPU CI test (no runner has two locality domains).Checklist
Review and Merge Process
/tag-and-rerun-ci,/approve-ci,/rerun-failed-ci🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ⊘ Skipped -- a maintainer comments⚠️ Run #45802357470
/tag-and-rerun-cito run CI tests.Latest PR Test (Extra): ⊘ Skipped -- a maintainer comments
/tag-and-rerun-cito run CI tests.Latest PR Test (AMD ROCm 10):
Tip
Base CI only covers the core cases, and its workload may not exercise your change. Use
/rerun-testto run the tests your change touches, or copy this prompt for an agent: