Skip to content

Split qualified Kimi KDA prefill input projections - #3582

Open
whx-sjtu wants to merge 24 commits into
mainfrom
task-3312-inproj-cpu-20261119
Open

whx-sjtu wants to merge 24 commits into
mainfrom
task-3312-inproj-cpu-20261119

Conversation

@whx-sjtu

@whx-sjtu whx-sjtu commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Part of LLM-Booster#499. Ready for human review; agent-team/hold-landing remains.

Large native Kimi-K3.1 prefills use cached LinearBase.make_row_view layers over the fused projection weight. This retains Linear forwarding and tracing while sharing storage and selecting the tuned tile-aligned GEMM. Parent #3577 has merged; this PR now targets main. #3587 supplies the row tail; original #3312 is superseded.

Dev record

  • Found: main integration exposed seven small-prefill fixture failures from accessing split-cache state before admission.
  • Decided: preserve the existing threshold, native scope and recorded performance limits through main integration.
  • Surprised: cached row views share hook bookkeeping, which affected an earlier diagnostic observer.
  • Left undone: maintainer disposition of threshold and subclass scope, formal review, and model qualification of this integrated revision.

Named result

The M8192 comparison measured a 1.49% lower whole-request median, N=5 in fixed order. Both completed GSM8K arms scored 32/32; 30 candidate questions directly exercised the split and were correct. These results do not establish a general crossover.

Testing

At c638070c, maintained projection and prefill/checkpoint CPU tests: 102 passed, 1 GPU-only test skipped. Black, Ruff and whitespace checks pass. Main integration preserves the split policy; actual prefill and row-count admission now precede access to split-cache state, fixing seven existing fixture failures without changing those fixtures.

Gates

The threshold and native-only subclass scope await maintainer disposition. Current GPU evidence retains its original source and recipe attribution; it does not qualify 49K projection behavior or the separate TR-prefill route.

Evidence and limits

The M8192 result belongs to parent 71a6aba6 / child 3e8527a1 with the documented startup-profiler overlay: gfx950 x8, TP8/DCP8/PP1, BF16 KV, FP8 index, Mono on, level3/FULL, Torch 2.10/ROCm 7.2.4, AITER b9e08dac. Whole-request medians were 0.925402 versus 0.911623 seconds. All ranks/layers showed the N6144 and N140 split at M8192. Larger 12K/16K results remain mixed, including the earlier 12K operator slowdown.

The candidate's internal 64-question protocol stopped after 32 outputs because of observer hook aliasing. The completed subset and directly split-exposed questions remain valid within their stated scope; direct N140 observation was missing in that GSM phase.

Historical maintained CPU tests at 3e8527a1: 15,263 passed, 1,562 skipped, 3 xfailed. Full GSM8K at 0277eff3 scored 1282/1319 under its original plain TP8/DCP8 recipe. Neither result is a new full-model run on the integrated revision.

Main's separate TR-prefill _project_in route retains the fused projection. The existing measured FULL route retains split admission; this integration does not expand optimization to TR-prefill, wrappers or subclasses.

ZhiweiYan-96 and others added 10 commits November 8, 2026 20:45
…nts are enabled

Several attention kernels route discarded lanes through block 0 (the
block-table zero-padding target): sparse-index gather writes 0 for
out-of-range top-k entries, the indexer's masked prefetch lanes read
there, and DSpark pad rows point there. This is safe while block 0
holds ordinary fp8 KV, but PAGE state checkpoints store fp32/bf16
state bytes into KV-pool blocks, and the min-heap allocator hands out
block 0 first. When block 0 is a checkpoint unit, those "harmless"
reads see fp8 NaN codes (0x7F/0xFF from the raw state bytes), poisoning
the attention row. Under DSpark verify with prefix caching this caused
garbled tool-call output on ~62% of affected DeepSWE tasks.

Fix: BlockPool.reserve_null_block() removes block 0 from the free set
before any allocation. Called by BlockManager when PAGE checkpoints are
enabled. Cost: one block out of thousands.
Use allocatable block capacity for admission, limits, occupancy, and watermarks. Reserve the padding block whenever PAGE state storage exists, including when prefix caching is disabled, and keep the physical address bound for deferred-block accounting.
@whx-sjtu whx-sjtu added the agent-team/hold-landing Holds landing only; development and review go on label Nov 19, 2026
@whx-sjtu
whx-sjtu marked this pull request as draft November 20, 2026 19:39

@whx-sjtu whx-sjtu left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No blocking source/CPU integration findings at cb34b1093ff6077a869df1e03bdcfd71c61cf7eb. agent-team/hold-landing remains.

Checked: unchanged projection behavior, imported parent contracts and current CPU CI.

Accepted with reservation: hardware, model accuracy, timing, parent/formal and final-tree gates remain.

Watch next: #3587's original 0/1319 remains unexplained; no causal fix is claimed.

Scoped integration review card and evidence

ATOM PR #3582 — Parent integration review

Combines the unchanged KDA projection split with the current parent’s counted residual-bank reads, relative slot writes and written-prefix PP/Mono contracts.

Review: ✅ LGTM for source/CPU integration at cb34b1093ff6077a869df1e03bdcfd71c61cf7eb, tree afe388b472055af3370f872005d3987f694d1637. No integration blocker found. This is scoped source/CPU clearance; root and the owner manage readiness, while agent-team/hold-landing and hardware/parent/final-tree holds remain.

Coverage: 7 files / 117 added lines -- within one review pass

Scope is the parent refresh from e4166f4198c8708d8f235145e5f1b08ab5bdba0a to the frozen merge, whose second parent is e6350bc6d28144e6b60596c647bda5a2e6ef01e1. There are no textual conflict-resolution hunks. Inherited implementations and the earlier projection feature retain their existing ownership and qualification limits.

Validation (advisory): Maintained CPU CI 44804292788 passed 15,016 tests, 1,481 skipped and 3 xfailed on Linux Python 3.12.16 / Torch 2.15.0+cpu. Raw checkout logs name this exact head. JUnit confirms all 26 projection, 42 bank and 17 dispatch cases passed without skips; Black/Ruff/catalog passed. The reviewer inspected existing evidence and dispatched no tests or CI rerun.

Checked: each key class is declared once. KimiKDAAttention is AST-identical to e416; KimiDecoderLayer and KimiLinearModel match e635. All 13 other imported files match e635 byte for byte, and projection tests are unchanged. Replacing only the preserved KDA class and removing its feature import/threshold makes the entire module AST match the parent, accounting for class placement and surrounding definitions.

Checked: active counts reach ordinary/add/quant/add-quant real and fake wrappers. Native and vLLM PP paths reconstruct writable capacity from the incoming written prefix and send only contiguous initialized slots. Slot writes remain relative to the bank view. Mono uses the shared model allocator and direct layer.forward, retaining one explicit auxiliary tap. The preserved projection gate still checks native class, final quantization target, measured geometry, gfx950/TP8, BF16, actual prefill count, scale and contiguity.

The independent weighted count against the current parent matches the author: 61 code / 282 test lines, all from the existing projection feature. Its earlier scoped review remains attributed to e416; this review adds integration evidence rather than transferring a hardware result.

Local CPU evidence and limits:

The 59-case Windows production-body adapter record hashes the working tree’s CRLF source bytes; those hashes match, and LF normalization matches the frozen Git snapshots. It uses Python 3.12.13 / Torch 2.15.0+cpu on one core, with engine/GPU imports and decorators omitted. The direct Windows pytest attempt stops at the pre-existing POSIX ForkContext import; maintained Linux CI supplies complete module collection. No local result is presented as native AITER, GPU, full-model or performance validation.

Accepted with reservation: the named native gfx950/TP8 BF16 projection result, actual prefills of at least 8,192 tokens, current AITER dispatch, compiled/model execution, large-prefill accuracy and crossover/attention timing remain pending. #3587’s original 0/1319 result remains unexplained. This merge is not identified as its causal fix.

Watch next: parent delivery, actual hardware/model evidence, formal review and the final landing tree. No GPU, SSH, source edit or performance sweep was performed for this review; this is not whole-PR or landing approval.

Independent blind refutation defended the source/CPU integration conclusion after checking class placement, call contracts and raw CI evidence. No additional blocker was found.

@whx-sjtu
whx-sjtu marked this pull request as ready for review November 20, 2026 20:17

@valar-cop valar-cop 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.

some changes needed..

gfx950/TP8 crossover timing for the 8192 threshold? and a gsm8k run on the split path?

ci green.



# Measured crossover for native Kimi-K3.1 BF16 in_proj on gfx950 at TP8.
_KDA_IN_PROJ_SPLIT_MIN_TOKENS = 8192

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

where is the gfx950/TP8 crossover number? no timing anywhere, so this threshold is a guess..

@whx-sjtu whx-sjtu Nov 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

At actual M=8192 on eight gfx950 GPUs, the split lowers whole-request median from 0.925402 to 0.911623 seconds (N=5, 1.49%). Matched GSM8K scores are 32/32 per arm; 30 candidate questions directly exercise the split and are correct. Larger measured points remain mixed, so 8192 is not an established general crossover.

Sources, larger shapes and incomplete-protocol limits

Current reference/candidate are 71a6aba/3e8527a1, executed as 9da62c2f/ae03f00d with the same startup-profiler overlay; accuracy observers were installed after timing/tracing. Runtime: TP8/DCP8/PP1, BF16 KV, FP8 index, Mono on, level3/FULL, Torch2.10/ROCm7.2.4, AITER b9e08dac. Timing includes the following 2,048 prompt rows; serial arms and small N limit interpretation. All eight ranks show actual M8192 and 69 KDA layers, with BF16 N6284 versus N6144+N140 projections. The N6144 route is aiter::bf16gemm_bf16_tn_256x256.

The earlier c916574/46361d57 comparison, with its same declared startup-profiler overlay, gives host medians 1.233926 to 1.237164 seconds at M12288 (+0.262%) and 1.560075 to 1.547117 at M16384 (-0.831%), N=5 each. Separate traced complete-KDA times are effectively flat. The one-GPU TP8-shaped operator probe at 8f098db/B9 is 5.38% slower at M12288. These results preserve the inherited threshold's limitation.

The matched GSM8K inputs cover documents 0–31; 29 complete outputs agree and three differ with correct answers. Actual M16331 exposes documents 0–29 to N6144 calls on 69 layers and eight ranks; documents 30–31 run at M845. That phase does not directly record N140. The candidate protocol fails after 32 outputs because shallow-copied row views share hook dictionaries, causing the temporary observer to mislabel the tail. Its second batch never runs; reference completes 64/64. Completed phases remain usable, but the candidate's overall protocol failed.

Existing full GSM8K remains 1282/1319 at source 0277 and its original recipe; this is not a matched full-dataset comparison. The new subset uses cap512 versus the earlier cap256. No candidate protocol success or universal crossover is inferred from these results.

Comment thread atom/models/kimi_k3/model.py Resolved

# Wrappers/subclasses and other geometries have no measured crossover.
return (
type(self) is __class__

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

type(self) is class blocks the vllm and glm subclasses too, intentional? gate on geometry plus opt-out instead?

@whx-sjtu whx-sjtu Nov 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Intentional: this optimization covers native Kimi only. vLLM adds state/capture handling; GLM folds its output gate after load. Matching geometry does not qualify those runtimes. The exact-class guard and tested generic-subclass fallback remain; enabling either subclass needs separate runtime qualification.

@whx-sjtu
whx-sjtu marked this pull request as draft November 20, 2026 20:56

@whx-sjtu whx-sjtu left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No blocking source/CPU correction findings at 8f098dbb9ebdaa2b596b244f789fef4d98af49c1; hardware and landing remain held.

Checked: cached Linear forwarding, shared storage, loader traversal, preserved guards and exact-head CPU evidence.

Accepted with reservation: crossover, tracing/compiled execution, split-path GSM8K, parent/formal and final-tree qualification remain.

Watch next: #3587's original 0/1319 remains unexplained.

Scoped review card and evidence

ATOM PR #3582 — Cached Linear projection views

Routes the eligible Kimi KDA projection split through two cached LinearBase layers that share the fused weight and retain normal forwarding and tracing.

Review: ✅ LGTM for the source/CPU correction at 8f098dbb9ebdaa2b596b244f789fef4d98af49c1, tree 14f70420a5e72eb87e9897e09ae3c7f81419d94c. Independent blind review found no additional source blocker. This is scoped clearance, not whole-PR, hardware or landing approval.
Coverage: 1 files / 17 added lines -- within one review pass
Validation (advisory): Maintained CPU CI 44817642634 passed 15,018 tests, with 1,481 skipped and 3 xfailed, on Linux Python 3.12.16 / Torch 2.15.0+cpu. Checkout logs name this exact head; JUnit confirms all 28 projection cases executed without failures, errors or skips. Black/Ruff/catalog passed. The reviewer inspected the saved records and ran no new tests or CI job; no deterministic validator report is claimed.

The coverage counter describes non-test additions. The correction from cb34b1093ff6077a869df1e03bdcfd71c61cf7eb changes two files, 81 additions and 24 deletions; the independent weighted count is 19 code / 68 test lines. Against the stacked PR base e6350bc6d, the complete existing feature is 70 code / 330 test lines. Parent bank/PP/Mono implementations are untouched.

Checked: the load hook creates the views after weight fusion and caches them once in a plain tuple. LinearBase.make_row_view copies module bookkeeping but narrows the parent's weight storage; the view's forward reaches the existing dtype/bias handling and mark_trace wrapper. The tuple stays outside the loader's parent-first module traversal. Eligible native construction leaves unquantized output padding unset, and the final quantization target must remain unquantized, so the identified later padding/quantization storage-replacement paths do not apply.

Checked: the split still requires the exact native class, gfx950/TP8 geometry, BF16, at least 8192 actual prefill tokens, contiguous input and no input scale. vLLM/GLM and generic subclasses retain the original path. The existing tests now execute the real Linear row-view and forward bodies with a CPU GEMM stand-in; cache reuse, loader-visible modules, storage aliasing, in-place updates, numerical comparisons and fallbacks remain observable. Their saved red controls establish those CPU contracts only.

The author's separate Windows production-body adapter records 28 passes with imports and trace decorators omitted. The prior-source control fails nine cases, registered-view control nine, and copied-weight control two. Source hashes agree with the frozen head. Those advisory controls are distinct from the maintained Linux collection and are not GPU or tracing evidence.

The native review's threshold and subclass questions are kept separate from the forwarding fix. The threshold comment now identifies historical provenance; no current crossover or split-path GSM8K result is inferred. Subclass exclusion remains intentional because those runtimes have separate state/capture or load-folding behavior. Historical and current evidence retain their recorded source/runtime attribution.

Accepted with reservation: native AITER dispatch, trace/compiled execution, current-runtime crossover, split-path GSM8K and large-prefill accuracy remain open, together with parent delivery, formal review and the final landing tree. The advisory controls do not establish GPU correctness or performance. #3587's original 0/1319 remains unexplained. Readiness decisions stay with the PR owner and maintainers; agent-team/hold-landing remains.

The non-author blind pass defended the source correction and its limits. The primary reviewer separately verified the subsequently supplied exact-head CPU records. Neither reviewer edited source, installed packages, ran GPU/SSH/compiler work or dispatched CI.

@whx-sjtu
whx-sjtu marked this pull request as ready for review November 20, 2026 21:35
Merge upstream #3508 through 503c2b2, before its unrelated main refresh. Preserve safe shared checkpoint warmup and usable pool capacity. Carry the two final warmup test additions from tested integration 7e5a225a, including its adaptation to this branch without decode-image folding.
Resolve the GDN warmup and CPU test conflicts with current main. Keep the shared self-copy, decode-image fold, and complete upstream test expectations. The resulting tree is identical to the clean merge of the original residual-bank parent with current main.

@whx-sjtu whx-sjtu left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ATOM PR #3582 — Parent refresh and fixture compatibility

Updates the split-projection child to the cleared parent and initializes its CPU projection fixture with the new Linear default.

Review: ✅ LGTM — final scoped source review at 46361d575a1e1a8575e205af40a98a3e35e09e8c; independently refuted by the sole assigned reader /root/pr_3587_owner; the scoped conclusion survived. No concrete blocker found; existing formal, landing and runtime/performance holds remain.
Coverage: 0 files / 0 added lines -- within one review pass
Validation (advisory): Frozen author CPU-body harness evidence changes from 24 passed / 4 missing-attribute failures to 28 passed / 0 failed; Black and Ruff pass on the two child files. Logs and unchanged harness hash were checked without rerunning tests. The harness omits engine/native imports and trace decorators; full imports, compiled/native execution and maintained CI are not qualified by this result.

The review covers the conflict-free parent merge and one fixture line, reusing the accepted original feature and parent reviews. The coverage counter excludes tests: this incremental diff is exactly one added line in tests/models/test_kimi_k3_kda_in_proj_split.py. Relative to cleared parent c916574f, only the original child model and test files differ.

Clean merge 8c2f7f6a has tree 12519fe4199f69d4e714137b05ed57836a5e0db3, independently reproduced from public 8f098dbb and parent c916574f. Final tree 3111ac6de700547b89a645b7271012bf553ca16b adds only self.runs_bf16 = False to _Projection. Production LinearBase.__init__ gives ordinary BF16 layers this default; its current forward reads the flag before the unquantized route. Supplying it restores the fixture's construction contract. No test assertion, tolerance, reference calculation or fallback condition changes.

The production Kimi model and split selector remain byte-identical to public 8f098dbb. Every non-child file, including LinearBase, equals parent c916574f. The author freeze 3e6e3720626d86b8d1ecdee09100776ce0f1e5f105193762efdb95a139670455 binds exact Git blobs and Windows worktree hashes; their line-ending correspondence was verified.

This card grants no push, CI dispatch, main merge or GPU/model run. Root still conditions publication on final independent source clearance, the parent's actual maintained CPU result and its fresh remote checks. The separately held native helper is outside this production PR maintenance; its hold is neither removed nor used to block this source refresh. G1c evidence remains bound to its tested tree, and actual-M performance remains unqualified here.

@valar-cop

Copy link
Copy Markdown

whx-sjtu added a commit to whx-sjtu/ATOM that referenced this pull request Nov 23, 2026
Port of ROCm#3582 at 3e8527a,
squashed: the diff against its merge base with the ROCm#3577 branch
(71a6aba), applied with `git apply --3way` on top of the ROCm#3577 port
without conflicts. Both touched files are byte-identical to the PR head.

Upstream commits (non-merge):
- 514173a Split qualified Kimi KDA prefill input projections
- e4166f4 Exclude online quantization targets from KDA projection split
- 8f098db Reuse cached Linear row views for KDA input projections
- 46361d5 Match KDA projection fixture to Linear BF16 fallback state

Upstream status at port time: OPEN, agent-team/hold-landing, no formal
review decision; reviewer asked for the gfx950/TP8 crossover behind the
8192-token threshold (author: M8192 -1.49%, M12288 +0.26%, M16384 -0.83%,
N=5 each).

Original old-line commit: be44b42 (ROCm#3268).

Co-authored-by: Cursor <cursoragent@cursor.com>
whx-sjtu added a commit to whx-sjtu/ATOM that referenced this pull request Nov 23, 2026
Port of ROCm#3587 at 35fa940,
squashed: the diff against its merge base with the ROCm#3582 branch
(3e8527a), applied with `git apply --3way` on top of the ROCm#3582 port
without conflicts. Every touched file is byte-identical to the PR head.

Upstream commits (non-merge):
- 92c31ae Split Kimi attention residual and latent MoE tail by rows

Upstream status at port time: OPEN, agent-team/hold-landing, no formal
review decision. The 0/1319 GSM8K result recorded at 92c31ae is
unexplained upstream; 0277eff (same feature) passed 1282/1319.

Original old-line commits: e12f9a9 (ROCm#3281), 0fa86f4 (ROCm#3287),
2c45b83 (ROCm#3288).

Co-authored-by: Cursor <cursoragent@cursor.com>
whx-sjtu pushed a commit to whx-sjtu/ATOM that referenced this pull request Nov 23, 2026
whx-sjtu pushed a commit to whx-sjtu/ATOM that referenced this pull request Nov 23, 2026
…ROCm#3637 ROCm#3638) k31-opt2/PT4@2c68a46f

Conflicts resolved as ROCm#3636 does for PT3 (ROCm#3577/ROCm#3582/ROCm#3587) + PT4:
- kimi_k3/attention_residual.py: PT4's kernel with PT3's num_blocks bound;
  PT3's int64 bank offsets (71a6aba) moved into PT4's _mix_tile and kernel.
- model.py: column tail first (decode, 1-64 tokens), then PT3's dispatch op;
  row tail (>= ATOM_KIMI_K3_MOE_ROW_SHARD_MIN_TOKENS) before PT4's one-AR
  split; aggregate materializes column pendings; per-phase token_graph.
@valarLip valarLip removed the ci:atom label Nov 25, 2026
Base automatically changed from task-3312-bank-cpu-20261119 to main November 27, 2026 14:42

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

agent-team/hold-landing Holds landing only; development and review go on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants