Repository navigation
Conversation
Split Kimi-K3.1's KDA in_proj GEMM at prefill sizes Implements wuhuikx/LLM-Booster#499. From 8192 tokens (_KDA_IN_PROJ_SPLIT_MIN_TOKENS), Kimi-K3.1's unquantized KDA in_proj runs its fused weight as two GEMMs over row slices (6144 + 140 rows at TP8), so aiter's tuned asm kernel serves the large one instead of hipBLASLt. Decode, Mono and a quantized in_proj keep the single fused GEMM. Harness at ctx 49152, rank 0: KDA in_proj 1251.0 -> 927.2 + 61.5 us per layer, KDA attention half 3616 -> 3355 us, forward 1130.1 -> 1111.8 ms. GSM8K 5-shot: 0.9742 flexible-extract, 0.9742 strict-match; only one of its prefill batches reached the split. (cherry picked from commit be44b42) Squashed in: Describe Kimi-K3.1's split KDA in_proj in its comments (#3278) (cherry picked from commit fd627e1)
Row-shard Kimi-K3.1's latent MoE tail on large prefill steps Implements wuhuikx/LLM-Booster#501. Above ATOM_DUAL_STREAM_MOE_TOKEN_THRESHOLD with TP, outside graph capture and TBO, Kimi-K3.1's latent MoE reduce-scatters its routed and shared partial sums, runs the routed norm, up-projection and add on each rank's rows, and all-gathers the sum. With dual-stream off (threshold 0), latent TP blocks with shared experts outside TBO now always take maybe_dual_stream_split_forward. The zero second output is allocated per call, because Inductor can write a later kernel into a cached custom-op output. docs/environment_variables.md and atom/utils/envs.py describe the threshold's new role; _SequenceParallel's docstring calls it the shared TP row-shard helper. Harness at ctx 49152, rank 0: MLP half 5748 -> 5130 us (DSA) and 5616 -> 4987 us (KDA) per layer, up-projection 586.6 -> 104.0 us, forward 1111.8 -> 1056.5 ms. GSM8K 5-shot: 0.9750 flexible-extract and strict-match. At threshold 0, eager steps pay the tail at any row count: eager decode TPOT is 10 to 12% higher and a 1024-token eager prefill slower (wuhuikx/LLM-Booster#524). (cherry picked from commit e12f9a9)
…fill steps (#3288) Row-shard Kimi-K3.1's attention residual before each MoE on large prefill steps Implements wuhuikx/LLM-Booster#503. Above the row tail's gate (#3281), each Kimi-K3.1 MoE layer runs mlp_attn_res on its 1/TP of the rows: o_proj's partial sum is reduce-scattered, the normed rows all-gathered for the MoE, and the MoE's tail adds the prefix rows before its gather. o_proj stops reducing only on layers that take the op (KimiDecoderLayer.post_attention_op); Mono's fallback ends in KimiDecoderLayer._post_attention. The zero addends are fresh each step and apply_attn_res skips loading them by pointer. KimiSparseMoeBlock.takes_row_tail is the one gate for the MoE and the op. Harness at ctx 49152, rank 0, mean over the 92 MoE layers: layer 10172 -> 9886 us, mlp_attn_res 396.1 -> 60.4 us, forward 951.1 -> 928.5 ms. GSM8K 5-shot strict-match: Mono off 0.9735, Mono on 0.9704 (base 0.9727). (cherry picked from commit 2c45b83)
Row-shard Kimi-K3.1's latent MoE tail only from 8192 tokens Implements wuhuikx/LLM-Booster#524. At ATOM_DUAL_STREAM_MOE_TOKEN_THRESHOLD=0, Kimi-K3.1's row-sharded MoE tail ran on every eager forward, adding about 50 ms to each prefill up to 3072 tokens and about 6 ms to each eager decode step. It, and #3288's row-sharded attention residual, now run only from ATOM_KIMI_K3_MOE_ROW_SHARD_MIN_TOKENS rows (default 8192, where an eager prefill sweep breaks even). The floor sits in KimiSparseMoeBlock.takes_row_tail; docs/environment_variables.md and atom/utils/envs.py describe it. Eager decode TPOT at threshold 0, means over 4 passes: 16 requests 56.8 ms base, 58.3 ms here (#3281 65.7, 63.0); 1 request 52.6 ms base, 53.5 ms here (58.9, 59.7). The remaining 1 to 1.5 ms is wuhuikx/LLM-Booster#532. Eager prefill TTFT at 1024 tokens: 409.1 ms base, 466.2 ms at #3281, 418.9 ms here. The 16384-row harness forward runs #3288's path unchanged. (cherry picked from commit 0fa86f4)
🏷️ CI GuideRuns automatically on every eligible PR before approval:
Heavy model tests:
|
Allocate Kimi-K3.1's block-residual bank once per forward Implements wuhuikx/LLM-Booster#504. Kimi-K3.1 grew its block-residual bank by torch.cat at every block close. KimiLinearModel.block_bank now allocates the bank once per forward, and each closing layer copies its prefix into its slot through an as_strided view, which Inductor reinplaces. Every AttnRes site takes the whole bank and mixes its own window (AttnRes.window). The view assumes the bank starts its storage, which holds for block_bank, K3MonoDecodeRunner and a PP receive. Rank 0 ctx=49152 forward: the 7 torch.cat kernels (2777.6 us) become 8 slot copies (647.6 us). GSM8K stays within a point of the base with Mono on and off; the long-prompt A/B logprobs are identical to the base. (cherry picked from commit 156e436)
Leave Kimi-K3.1's row-sharded MoE zero addends unwritten Implements wuhuikx/LLM-Booster#541. On a row-sharded prefill step, each MoE layer filled two [T, 7168] buffers with zeros that apply_attn_res never needed to load. They are now torch.empty_like, registered as folded zeros, and apply_attn_res skips them by pointer. Code that adds them in plain torch (KimiDecoderLayer.aux_hidden_state under the DSpark hooks, the PP hand-off, the AttnRes fallback and K3MonoDecodeRunner._layer before K1) zeroes them first through materialize_folded_zeros, which launches nothing when the slots were written. Rank 0 ctx=49152 forward: zero fills go from 59.9 to 12.5 us a layer (DSA; the rest is the five DSpark hook layers) and from 59.0 to 0 (KDA), and the forward from 903.5 to 896.1 ms. The long-prompt A/B output is identical to the base; GSM8K stays within a point with Mono on and off. (cherry picked from commit b210719)
|
atom-bot review |
|
aiter-bot — queued behind 1 review(s); expect to start in about 50 min. The box reviews one PR at a time. |
aiter-bot
left a comment
There was a problem hiding this comment.
ATOM PR #3312 — Speed up Kimi-K3.1 prefill around its KDA in_proj and latent MoE collectives
Splits Kimi-K3.1's unquantized KDA in_proj into two tuned GEMMs from 8192 tokens, replaces the per-block-close torch.cat with a pre-allocated slot bank, and — on TP steps above 8192 tokens — runs o_proj's reduce, the attention residual and the latent MoE tail on each rank's row shard between a reduce-scatter and an all-gather, returning the MoE's two addends as unwritten "folded zeros" that readers skip or zero.
Review:
Validation (deterministic): NOT RUN -- no unique validation target exists (validation_requirement.json lists 5 candidate K3 test files and blocks on "no unique added one"), REVIEW_AUTO_VALIDATE=0 wrote no validation_report.json, and nothing was run on this box.
📝 [verified] runner.py:572-574's _write_aux docstring still contrasts mono's "fixed-size slot stack" with "the forward's grown cat", but this PR's block_bank/maybe_close_block make the forward's bank a fixed-size slot stack too, so that sentence sends the next reader looking for a cat that no longer exists — a gap the PR body itself discloses as left undone. Author must reword that docstring before merge.
ATOM/atom/models/kimi_k3/mono/runner.py
Lines 572 to 574 in 5b264b2
1 finding(s) posted inline, on the lines they are about:
atom/models/kimi_k3/model.py:644-646— The dev record leaves "GSM8K here" undone and the accuracy evidence is per-change GSM8K onwhx/k31-perf
_Independent refutation: 2 judged, 0 killed, 2 defended — same-family (claude reviewed its own output). Step 7.6 above
Co-authored-by: Cursor <cursoragent@cursor.com>
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (4)
- Split this PR into its three independent changes. It is +1192/-70 (1262 lines, 15 files), over the 1000-line limit, and it already bundles separate PRs: (a) the KDA in_proj split (#3268), (b) the fixed block-residual bank (#3303:
attention_residual.py,block_bank, mono runner, vLLM plugin), (c) the row-sharded attention residual and latent MoE tail (#3281/#3288/#3287:kimi_k3_post_attention_forward, envs/docs, row tests). Each one stands alone and can be measured on its own. - Post head-vs-main before/after numbers at the default env. The only head evidence (run 44175732126) has no main baseline (main timed out at readiness), and every per-change number was taken on
whx/k31-perfatATOM_DUAL_STREAM_MOE_TOKEN_THRESHOLD=0, which is not the default. The default path changes: with TP, every latent MoE layer now runs o_proj's reduce,mlp_attn_resand the MoE inside the opaque op (model.py:1736-1742,module_dispatch_ops.py:168), and the row path is on by default from 8192 tokens. Please post TTFT for a ≥8192-token prefill and decode TPOT, head vs main, at default env, and accuracy (GSM8K) at default env. - Do not hard-code aiter's tuned-table row in
_KDA_IN_PROJ_SPLIT_MIN_TOKENS. Atmodel.py:176-178the comment says the split exists so "aiter's tuned asm kernel serves … (its M=8192 row)". That is a hand copy of aiter's BF16 table and goes stale on the next retune. The 8192 crossover was measured only on gfx950 at TP8, yet it applies to every arch and TP size, and also to GLM-5.3-Flash:Glm5NextKDAAttentioninherits_forward_impl(glm5_next.py:484), and its in_proj is bf16. Keep it only as a measured "which is faster" choice: scope it to the measured config, or show numbers for the other configs it reaches. Otherwise, ask aiter to serve the non-aligned fused N. - Clean up the smaller items. (a)
model.py:1403: drop the deadin_proj.quant_type == QuantType.Noguard;process_weights_after_loadingalready asserts it. (b) Move_SequenceParallelout ofqwen4_exp.pyinto a shared module rather than importing another model's private class (model.py:625,1888), and revert the drive-byqwen4_exp.py:669-673docstring edit (its line 673 is 115 chars). (c) Fix stale comments:model.py:1927("come back unsummed" is false on the row path) andenvs.py:1077(row sharding starts at max(threshold+1, ROW_SHARD_MIN), not above the threshold). (d) Addassert block_residual.storage_offset() == 0inmaybe_close_block(attention_residual.py:231). (e) Note that all five new test files are skipped in the CPU gate (aiter/FlyDSL importorskip), so CI does not exercise them.
Reviewed at f4d1c8c. aiter-bot items verified fixed: the _write_aux docstring (runner.py:570) and exact-head GSM8K (0.9773 strict/flex, run 44175732126). Pre Checkin green; heavy model CI not run (skipped, unapproved).
|
ci triage for f4d1c8c:
|
|
Part of #3312. The fixed residual-bank component is now isolated in #3577, as a draft. This original branch remains unchanged. The KDA input-projection and row-sharded residual/MoE components remain here for their subsequent splits. The new PR includes CPU regression coverage and the PP placeholder-shape correction; GPU and model validation await resources. Its current evidence and remaining checks are recorded there. |
|
Part of #3312 is now isolated in draft #3582: the #3268 KDA input-projection optimization, stacked on #3577. Eligibility is limited to the measured native gfx950/TP8 BF16 configuration. The child changes only projection dispatch and tests; row-tail work remains unsplit. #3312 remains unchanged at f4d1c8c. Both split PRs retain their GPU qualification holds. |
|
Part of #3312 is split into draft #3577 (bank), #3582 (scoped input projection), and #3587 (row-sharded attention residual/MoE tail plus shared TP row helper). Their CPU CI passes; #3587's exact-head record confirms the new CPU cases execute. The third stacks on #3582/e4166f419 and preserves real zero addends. GPU/default-env performance and accuracy holds remain. Original #3312 stays at f4d1c8c. |
|
Part of #3577, #3582 and #3587. Superseded; closing this combined PR without merging. These PRs implement the three-way split requested in the formal review. Their validation and approval gates remain open. No open child targets this branch; the original branch, commits and review history are preserved. The stale ready-for-review statement has been corrected. Main delivery continues through the successor ledger. |
Part of #3577, #3582 and #3587. Superseded: this original combined PR is closed without merging; the successor PRs retain their review and validation gates.
The formal review required splitting the three independent changes. The completed split record and main-delivery plan identify their replacements:
The original head and branch are preserved. No open PR uses
whx/k31-prefill-modelas its base. Follow the successor chain in the order #3577, #3582, #3587.Historical evidence for the original head
Original head:
f4d1c8ca7329a9d3083deb94a485e98336d9c132. CPU CI passed 14,205 tests. GPU/model evidence included 73 passing GPU cases and exact-head GSM8K of 1289/1319, or 1288/1319 with Mono. That workflow failed because its main model comparison timed out; four GQA/AITER interface failures reproduced on main. These records apply to the original head and do not qualify the successor heads or establish a main-relative speedup.