Repository navigation
[Feat] kimi-k3.1: MegaMoE, breakable prefill graphs and DFlash under prefill CP - #48710
Conversation
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.
Tip: disable this comment in your organization's Code Review settings.
|
Suggestion: reuse more of #46890's interleave-CP path in This PR already reuses most of #46890 ( Since
With (1) and (2) only, Kimi and GLM would share a single indexer CP path. Validation needed afterwards:
|
| MEGA_MOE_NO_FALLBACK_ARCHS = frozenset( | ||
| { | ||
| "DeepseekV4ForCausalLM", | ||
| "KimiK31ForConditionalGeneration", |
There was a problem hiding this comment.
If K31 has no fallback, we need to throw error when chunked preill size is larger than MegaMoE workspace num tokens * EP size
There was a problem hiding this comment.
Done in fb51283: for Kimi-K3.1, validate_mega_moe_token_budget now raises when the largest prefill forward (--chunked-prefill-size / --max-prefill-tokens / prefill graph buckets) exceeds SGLANG_OPT_DEEPGEMM_MEGA_MOE_NUM_MAX_TOKENS_PER_RANK x ep_size.
5a5c193 to
1cc046d
Compare
c42139a to
fb51283
Compare
|
Folded the indexer split op into #46890's
Still to validate on GPU: Kimi-K3.1 graph vs eager match with interleave BCG, and GLM's #46890 boundary matrix and gsm8k. |
…prefill CP Port of radixark/sglang-k31#34, split out of #48504 and rebased onto #46890. - MegaMoE: mask the CP padding rows of a static graph bucket before dispatch and after combine; allocate the EP symmetric workspace at load so it counts against the KV budget; bound the Kimi MegaMoE eager decode / verify rows and the prefill rows (chunk, max prefill tokens and prefill graph buckets) in the token-budget check. - Breakable prefill graphs: admit Kimi-K3.1 to the interleave BCG adapter (EP only as MegaMoE over the CP group); run the DSA indexer split op on this rank's live rows and keep the unused top-k rows at -1, also during capture (on_capture). - trtllm DSA: pad 65-127 query heads to 128 for trtllm-gen (attention TP 1 under CP-TP group sharing leaves every head on one rank). - DFlash: allow integrated as well as PD prefill; let a PD pair register a replicated MLA draft KV across different physical TP sizes. - Size the linear-attention verify scratch for CUDA graph batch padding. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d bound MegaMoE prefill rows The indexer split op keeps #46890's in_cp path for every interleave-CP model: no live-row truncation, and the aiter fused path stays ungated. Only the generic fixes remain: a top-k-reuse layer under CP stores the gathered K instead of the local K-only path, and the top-k rows past this rank's logical tokens stay -1. Kimi-K3.1 MegaMoE no longer requires --max-running-requests, and its largest prefill forward must fit the workspace of the EP group since it has no non-mega fallback. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Allocating every MoE layer's MegaMoE workspace in post_load_weights charges it to the static memory budget. That is what the prefill-CP recipes are sized for, but the existing Kimi-K3 MegaMoE recipes (e.g. the TestKimiK3B300MegaMoE TP8/EP8/DCP8 launch at --mem-fraction-static 0.85) take it from the non-static slack as on main; charging ~33 GB there leaves the mamba state cache a negative budget and the server fails to start. Keep the eager allocation for attn_cp_size > 1 only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
08b99bf to
8558d86
Compare
Conflicts: - environ.py / environment_variables.mdx: keep SGLANG_ENABLE_NEXTN_DRAFT_PREFILL_CUDA_GRAPH; drop SGLANG_ENABLE_SPLITKV_VERIFY and SGLANG_NGRAM_FORCE_GREEDY_VERIFY, which main removed. - dsa_prefill_cuda_graph.py: keep main's on_capture wrapper of bcg_dsa_indexer_prefill_split (sgl-project#48710) and this PR's top-k-only break. - dsa_backend.py imports: union of main's cp/dcp imports and the cuda graph config imports. Adapted to main: - get_cuda_graph_max_batch_size moved to sglang.srt.layers.dp_attention (sgl-project#48781). - The DSA backend's DCP size is now attn_dcp_size. - Keep the in-graph prefill attention off for 65-127 query heads per rank, which main pads to 128 for trtllm-gen (_trtllm_padded_heads) and forward_prefill_in_graph does not. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Original authors: @Fridge003
Port of #48414
MegaMoE, breakable prefill CUDA graphs (BCG) and DFlash under Kimi-K3.1 prefill CP (radixark/sglang-k31#34), the second PR of the split of #48504. Depends on the core PR (base branch
k31-pcp/1-core).Against the raw port, rebased onto #46890, which landed the interleave BCG path for the GLM DSA family:
dsa_indexer.pychange is dropped: main already runs the indexer split op under every PCG/BCG prefill.cp_live_store_rowsfor the K store and adds only the interleave pieces: query this rank's live rows, skip the K-only path, and keep the top-k rows past its logical tokens at -1.eager_on_graph(True, on_capture=...). The raw port passedcapture_stub=, renamed toon_capturein [Refactor] bcg: Delete capture leftovers and renamecapture_stubtoon_capture#46792, which raisesTypeErrorwhen the module is imported.InterleaveCPBCGInputadds Kimi-K3.1 to main's supported architectures; EP is admitted for Kimi only as MegaMoE over the CP group, and GLM keeps main's rules.Left for the next PR: the padding mask moves into the MegaMoE pre-dispatch kernel.
Split of #48504. Stack: #48709 (core) → #48710 (MegaMoE / BCG / DFlash) → #48711 (fused kernels) → #48712 (PP × PCP BCG). Independent: #48713 (shared-expert TP across PCP), #48714 (trtllm DSA), #48715 (Linker PCP L3).
Modifications
kimi_k3.py,mega_moe_hook.py):MEGA_MOE_NO_FALLBACK_ARCHS. The token budget now bounds eager decode / verify rows (this requires--max-running-requestsoutside a PD prefill node) and prefill rows (chunk,--max-prefill-tokensand prefill graph buckets).interleave_bcg.py,dsa_prefill_cuda_graph.py, outer-modelpp_group/capture_aux_hidden_states/logits_processorproperties): admit Kimi-K3.1 to interleave BCG.dsa_backend.py): pad 65–127 query heads to 128 for trtllm-gen; attention TP 1 under CP-TP group sharing leaves all of Kimi's heads on one rank.linear/utils.py): size the verify scratch index for CUDA graph batch padding as well as eager padding.Accuracy Tests
8× B300, PCP8 + EP8 MegaMoE + BCG + DFlash2, TRTLLM DSA, measured on sglang-k31 dev with the original PR (not re-run on this branch):
Speed Tests and Profiling
BS1 / ISL16384 / OSL1, TP8 MoE → EP8 MegaMoE (sglang-k31 dev):
Review notes
The new
--max-running-requestsrequirement also applies to non-CP Kimi-K3.1 MegaMoE launches (unified and decode).🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ❌ Run #42322986151
Latest PR Test (Extra): ❌ Run #42322985976
Latest PR Test (AMD ROCm 10): ❌ Run #42322986023
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: