Skip to content

[Refactor] [GB300] kimi_k31: Settle the seven scoped levers on the GB300 results - #83

Merged
Oasis-Git merged 1 commit into
mainfrom
kimi-k31-settle-scoped-levers
Nov 23, 2026
Merged

Oasis-Git merged 1 commit into
mainfrom
kimi-k31-settle-scoped-levers

Conversation

@Oasis-Git

Copy link
Copy Markdown
Collaborator

Motivation

#80 cut the package's env flags from 44 to 12 and left seven levers scoped: best_default (in kimi_k31/k3/default_scope.py) gave the measured value inside the GB300 BEST configuration (TP16, no DCP, 8 draft tokens, --max-running-requests 1) and the older default everywhere else, pending GPU data. The GB300 runs are done. This PR settles all seven, so none of them reads an env variable or depends on the configuration any more, and default_scope.py goes with them.

Inside the measured configuration every lever keeps its measured value, so the measured path is unchanged: 1 / 1 / 0 / on / on / off / 320000. Outside it (--max-running-requests > 1, DCP, TP8) the levers now take that same value. A condition stays only where it is a real kernel, layout or math limit.

After this PR the package reads five env variables: K31MK_DFLASH_RUNTIME, plus the four TP8 levers K31MK_VERIFY_Q5, K31MK_KDA_Q5_R3_C4, K31MK_DSA_EARLY_QAG and K31MK_DSA_DIRECT_QAG. This PR does not touch the TP8 levers.

Modifications

Lever Now Kept condition (real limit)
K31MK_MLA_VALUE_EARLY_TRIGGER (dsa/verify.py) The sparse verify MlaValue always releases the o-proj at entry. This holds for DCP1 (sparse_values) and DCP (cp_values). It is bitwise, because the o-proj still waits for MlaValue's grid. _padded_value loses its early argument. The dense MlaValue (mla/prepared.py) keeps its late trigger. none
K31MK_AUX_SIDE_STREAM (verify_executor.py, attn_res/) At the DFlash capture layers the aux mixture always runs on the side stream. It is joined before the o-proj, the next AttnRes and the end of the step. bind_aux() takes no arguments. ClusterAttnRes loses aux_launch and its in-kernel AuxMixture launch, because nothing else used the main-stream variant. Without saved blocks (nb == 0) the kernel stores the aux row itself, because there is no mixture to run.
K31MK_EXPERTS_COOPERATIVE (moe/experts.py) The routed experts always launch without the cooperative attribute (launch_options and cooperative() are deleted). The "B9+ grids are untested" caveat was a tested-range gate, so it is dropped too. check_residency stays: the CTAs wait on one another, so the whole grid must be co-resident. With that check, a non-cooperative grid cannot deadlock.
SGLANG_K31_DRAFT_MK (draft/serving.py) The draft chain with M1b always builds where the draft spec admits it. max_rows is always 8. The aux (2b) and the head (2a) follow K31MK_DFLASH_RUNTIME alone. With K31MK_DFLASH_RUNTIME=0 the chain still builds, but it builds no aux and no head, and the target names no runtime, so no sampled accept is built either. At --max-running-requests > 1 the runtime hands back the rounds the head (bs 1) does not serve. The spec's tp_sizes={16} and the 8-row block (ROWS) stay where they are. A draft KV pool that is not plain FP8 MLA keeps M1a.
K31MK_OPROJ_NORM_FOLD (oproj/) The o-proj consumers always fold AttnRes's final-norm exchange into exchange 1. The tp == 16 condition was not a limit: the fold is per token inside the 7-CTA cluster, and the TP-wide part is only the mailbox poll. It is gone, together with norm_fold(), the fold compile key and the consumer's separate final-norm exchange (norm_post, norm_total, the third barrier). Layers without saved blocks (nb == 0, which includes the draft's OprojConsumer(0)) have no second exchange to fold.
K31MK_MLAQ_AFTER_SCORING (dsa/verify.py) Deleted, with _query_after_scoring, the _scored event and VerifySelection.run's scored argument. none
K31MK_INDEX_SPLIT_MIN (dsa/split.py, dsa/verify.py) SPLIT_MIN = 320000, the measured crossover. The comment names the measurement: 16-rank merge unit B1 on GB300, +5.8 us/layer at 134K, ~0 at 338K, -13 us/layer at 600K; prepare-early moved the crossover to 320000. The raises for an explicitly set env under DCP or without a merge are gone. DCP (the split scores the replicated index-K cache) and an unusable merge both decline with an INFO line, as before.

kimi_k31/k3/default_scope.py is deleted, because nothing uses it any more. docs/models/kimi_k31.md drops the SGLANG_K31_DRAFT_MK mention and the scope paragraph. The engagement log lines of the four former opt-ins are removed.

What changes at TP8

At TP8, best_default returned the older default, so making a lever unconditional changes the TP8 path. No TP8 gate is added. For each lever:

Lever TP8 change TP8 code path present / reachable
MLA_VALUE_EARLY_TRIGGER late -> early trigger Yes. TP8 DCP8 uses cp_values and TP8 DCP1 uses sparse_values. The midcurve R5 (GB300 TP8/DCP8/Q5) ran with it set. Bitwise.
AUX_SIDE_STREAM in-kernel AuxMixture -> side stream Yes, the executor path is TP-generic. R5 ran with it set. Bitwise.
EXPERTS_COOPERATIVE cooperative -> non-cooperative Yes. Rubin TP8 c1 (2935) measured +2.34 % with it. R5 c36 ran with 0, including B9+ rows.
OPROJ_NORM_FOLD no fold -> fold Yes: TP8 runs OprojConsumer (producer + consumer) at every batch, and the fold is TP-generic. This changes the numerics and has not been measured at TP8. Before this PR TP8 could not fold even with the env set, so R5 did not fold.
INDEX_SPLIT_MIN never split -> split from 320000 TP8 DCP8 (the R5 layout) declines on DCP. TP8 DCP1 does not decline: SGLang's DcpTopKMerge.create admits 8 ranks, and the split-merge kernel is built for 8 or 16 ranks. A TP8 DCP1 step at a context of 320000 or more would arm the 8-rank split on a crossover that was measured with 16 ranks.
SGLANG_K31_DRAFT_MK none The draft spec admits TP16 only. At TP8 SGLang refuses the draft spec (tp_size 8 is not one of [16]), as before.
MLAQ_AFTER_SCORING none It was off at TP8 and is deleted.

GPU validation

These are GB300 TP16 runs on the #80 head (c5754bf, now mega main) from the GPU check of the scoped levers. Each arm ran one boot.

  • A1b (TP16, mrr 8, graph bs [1,2,4,8]; the three target levers MLA_VALUE_EARLY_TRIGGER=1, AUX_SIDE_STREAM=1 and EXPERTS_COOPERATIVE=0 on top of A0h): greedy 24/24, identical to A0h. The bs1 round is 7.53 ms (A0h 7.65, A1 7.41). All of bs 1-8 run in graphs. (A1 also had SGLANG_K31_DRAFT_MK=1 and scored 14/24 greedy. The mismatch came from the draft MK combined with the simulated real-draft-token, which is a measurement-only setting.)
  • V1-G vs V1-GD (GSM8K-200 at the real acceptance length, not simulated; DRAFT_MK off vs on): accuracy 0.990 / 0.990, invalid 0.005 / 0.005, 72.78 s / 72.66 s, 276.0 / 276.4 tok/s.
  • D (TP16 c1 AgentX, 900 s, the BEST configuration):
Run Configuration P50 P90 TPOT median Round median
D-ref main aa0d80e 470.97 447.15 2.1233 7.8356
D0h #80 head 472.39 445.74 2.1169 7.7688
D1h #80 + OPROJ_NORM_FOLD=0 471.27 443.23 2.1219 7.8202
D2h #80 + MLAQ_AFTER_SCORING=1 472.35 451.69 2.1171 7.8496

The boot noise range is P90 447.49-451.80, over the same-node G0/G3 boots. D1h (fold off) is slightly worse on every column but within that noise. The fold stays on where the kernel supports it. D2h shows P90 +1.3 %, but its round median is 0.08 ms slower; both are within the noise, so there is no gain and the lever is deleted.

  • B (TP16, mrr 4, AgentX c4, INDEX_SPLIT_MIN off / on): P50 402.05 / 424.67, P90 248.62 / 281.38. The bucket below 320K moved the most, and this lever does not act on that bucket, so the difference is noise. The per-bs round medians show the same. Both arms handed every round back to the stock round. The result is inconclusive, so the split stays at its measured crossover, 320000.

This PR did not run on GPU. It makes the measured values unconditional; inside the measured configuration they are the same as on main. The only kernel binaries that change on the measured path are the o-proj consumer and the fused and draft kernels built on it. Their shared memory loses the unused separate final-norm buffers and one never-armed barrier, and the computation they run is unchanged.

Tests

  • Measured-scope equivalence (CPU, GPU packages stubbed): each lever's effective value was evaluated from each tree's own source, at origin/main e9e01fe and at this head. Inside the BEST scope the values are identical: 12 values compared, 0 differences. On this head no lever depends on the scope any more, TP8 included. With K31MK_DFLASH_RUNTIME=0 the target names no runtime, the chain builds with M1b and max_rows 8, and it builds no aux and no head. The only env names the package reads are K31MK_DFLASH_RUNTIME, K31MK_DSA_DIRECT_QAG, K31MK_DSA_EARLY_QAG, K31MK_KDA_Q5_R3_C4 and K31MK_VERIFY_Q5. Every kimi_k31 module imports.
  • test/unit/test_kimi_k31_split_merge.py: SplitArming is new. It pins the 320000 crossover and runs _build_split: armed at 320000 for each verify width, with one merge sized for the widest; declined below the crossover, under DCP, and without a usable merge. The K31DFlashRuntimeNaming test (the K31MK_DFLASH_RUNTIME=0 path) passes with the GPU packages stubbed.
  • Full unit suite, one pytest process per file, against SGLang cf6133a (CI pin), a034bb5791 and main b40fc17961: the failure sets equal origin/main's on all three. The count changes come from the tests themselves: test_contract has two fewer parameters because default_scope.py (which had SGLANG_READS) is deleted, and SplitArming adds 2 tests and 3 subtests. On b40fc17961 the K3.1 DFlash runtime tests fail on origin/main too, because SGLang main dropped dflash_utils.apply_dflash_verify_logits_adjustments; on a034bb5791 they pass (test_kimi_k31_split_merge: 16 passed, 25 subtests).
  • 11 of 11 mutants killed: threshold off the crossover, DCP raising again, the threshold read from the env, the cooperative launch restored, the draft not wrapped under K31MK_DFLASH_RUNTIME=0, the draft without M1b, the head or the aux built under K31MK_DFLASH_RUNTIME=0, the fold disabled, the late MlaValue trigger, and the aux mixture back on the main stream.
  • pre-commit run --all-files passes.

🤖 Generated with Claude Code

…300 results

#80 left seven levers on best_default pending GPU data. With the results in,
none of them stays scoped, so kimi_k31/k3/default_scope.py goes too:

- K31MK_MLA_VALUE_EARLY_TRIGGER: the sparse verify MlaValue always releases
  the o-proj at entry. The dense MlaValue keeps its late trigger.
- K31MK_AUX_SIDE_STREAM: the DFlash capture layers' aux mixture always runs
  on the side stream; ClusterAttnRes no longer launches AuxMixture itself.
- K31MK_EXPERTS_COOPERATIVE: the routed experts always launch without the
  cooperative attribute. check_residency still requires a co-resident grid.
- SGLANG_K31_DRAFT_MK: the draft chain (with M1b) always builds where the
  draft spec admits it (TP16, 8-row blocks); max_rows is always 8. The aux
  and head follow K31MK_DFLASH_RUNTIME alone.
- K31MK_OPROJ_NORM_FOLD: the o-proj consumers always fold the final-norm
  exchange when there are saved blocks. The fold is per token inside the
  7-CTA cluster, so the TP16 condition was not a kernel limit and is gone,
  with the consumer's separate final-norm exchange.
- K31MK_MLAQ_AFTER_SCORING: deleted with its reorder path (no gain).
- K31MK_INDEX_SPLIT_MIN: the split threshold is the measured crossover,
  320000. DCP and an unusable merge still decline; the explicit-env raises
  are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Oasis-Git
Oasis-Git merged commit bf98dd9 into main Nov 23, 2026
3 checks passed
@Oasis-Git

Copy link
Copy Markdown
Collaborator Author

GPU check of this PR's head (f185d9b) after merge: Kimi-K3.1, GB300 TP16 (one NVL72 domain), measured configuration (DCP1, 8 draft tokens, --max-running-requests 1), one boot, compared against the same configuration on the previous head c5754bf (D0h above).

  • Builds and serves: TP rank 0 logs DFLASH rounds run on the NVIDIA megakernel at batch sizes [1]; 842/842 decode rounds ran on CUDA graphs, with 0 fallbacks; max_total_num_tokens is 2815616, the same as c5754bf.
  • The o-proj consumer's shared-memory change keeps outputs identical: the short probe (12 greedy + 12 default-sampling prompts) is token-identical to c5754bf, 24/24, and also to main aa0d80e.
  • AgentX c1, 900 s:
this PR c5754bf
P50 tok/s/user 473.74 472.39
P90 tok/s/user 445.40 445.74
TPOT median 2.1109 ms 2.1169 ms
Round median 7.7950 ms 7.7688 ms
Pauses > 12 ms 0.030 % 0.044 %
Errors 0 0

All within the same-node boot range (P90 445.74 to 451.80).

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.

1 participant