Skip to content

kimi: experimental K3.1 index operators on Metal, native serving stays capped - #2228

Closed
ashhart wants to merge 9 commits into
mainfrom
lead/k31-index
Closed

ashhart wants to merge 9 commits into
mainfrom
lead/k31-index

Conversation

@ashhart

@ashhart ashhart commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Draft, experimental, and stacked on #2221. Refs #2192. Candidate Metal key, score and top-k operators for K3.1's Gated DSA layers, with selected absorbed MLA and merge. Index storage and exact snapshots live in the family adapter. The native 2047-token cap is unchanged: only an internal cut-down synthetic diagnostic can exercise longer contexts, and the complete release geometry can't enable it. No lane or lane-host scheduling change.

No real weights, no K3.1 model-forward reference and no full-model run. These are candidate semantics inferred from our own GLM and DeepSeek operators, not confirmed K3.1 facts, so they can't qualify long-context output. Stays in draft until a reference settles the list below.

Assumptions that need a K3.1 model-forward reference

  1. Queries use the existing BF16 normalized q_a row; keys and head weights use the BF16 normalized hidden row. Shapes don't establish those inputs.
  2. All three projections round to BF16. Key normalization is biased population LayerNorm(128), epsilon 1e-5, FP32 affine FMA and one BF16 store. No index RoPE is applied.
  3. Scores sum heads in order: weight/sqrt(32) times ReLU(dot(query,key)/sqrt(128)). The separate scales and rounding are unconfirmed.
  4. Visibility includes the current key. The freq=1/offset=1 synthetic candidate selects on every row, keeping every key through 2048 visible positions. No mandatory recent tail is guessed.
  5. Top-k keeps 2048 individual positions. Numeric scores sort descending, equal signed zeros tie, equal scores prefer lower positions, NaNs rank last. Attention consumes the resulting positions chronologically.
  6. Every cache cut follows committed positions. Rejected verification rows are overwritten before reuse; snapshots contain every visible index-key plane. These state rules are checked locally, but whole-model semantics still need a reference.

Checks on this head

Zig 0.17.0, Metal on an M5 GPU. Synthetic weights keep the real widths, with reduced layers, experts and vocabulary.

  • Host suite 714/714 steps, 10707 passes, 86 skips. Lean adds no new problems. The independent Python reference passes.
  • Scoped kernel contract: 4 kernels pass gates 1-4, 0 fail; 11 planted controls red, 0 missed. That's a scoped --only/--no-limits run on M5, not the full Metal qualification; M1-M4 are unchecked.
  • Capped K3 and K3.1 output arrays and first-logit bytes agree, and all seven component files from the earlier stage are unchanged.
  • Greedy and fixed-seed sampled: drafted equal to plain, and concurrent equal to solo, at 2, 4 and 8 admitted streams.
  • The long internal 2061-row diagnostic passes drafted/plain, two-stream concurrent/solo, five restore cuts and partial verification rollback.

Not checked: decode and prompt throughput, quality, the full global contract, other chips. The complete released model doesn't run on one Mac through this resident adapter.

…ulas

Uncompiled and incomplete Stage 2 draft. The score, normalization, ordering and visibility rules are explicit assumptions adapted from our own GLM and DeepSeek code. The native 2047-token ceiling is unchanged. No real weights, no model reference, no full-model run.
… admission

Uncompiled Stage 2 source only. Keep the native 2047-token cap and the dense short-prefix arithmetic. Own separate BF16 index planes and scratch, include them in snapshots, residency and budget accounting, and expose the longer selected-attention operators for later synthetic gates. No real weights, no model reference, no full-model run.
Retain the original ReleaseFast contract crash and rerun unchanged numerical gates and controls. No arithmetic, bounds, fills or registered shapes change.
A near-constant BF16 row exposes loss of its small mean offset after normalization. Restore the default 100x stress thresholds and plant both FP16 and BF16 shuffle-sum controls. Arithmetic, numerical bounds and served random shapes are unchanged.
@ashhart

ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

Parking this draft. Its six semantic assumptions about the K3.1 index, score and top-k operators need a K3.1 model-forward reference to check against, and none exists yet. The branch lead/k31-index stays, and #2192 keeps the pointer; we reopen once a reference is in hand. Before landing it would then need a rebase (the Metal registry now lives in registry_joins.zig) and the full Metal kernel contract on M3 and M5.

  • Synthena (Ash's Agent)

@ashhart ashhart closed this Nov 13, 2026
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