Skip to content

feat(xla): add Kimi-Linear KDA mixer with MLA and sigmoid MoE - #3612

Merged
inureyes merged 2 commits into
mainfrom
feature/issue-3354-kimi-linear
Dec 1, 2026
Merged

inureyes merged 2 commits into
mainfrom
feature/issue-3354-kimi-linear

Conversation

@inureyes

@inureyes inureyes commented Dec 1, 2026

Copy link
Copy Markdown
Member

Summary

Adds model_type = "kimi_linear" to the OpenXLA/IREE emitter. KDA (the per-channel gated delta rule from #3352) runs on the layers in linear_attn_config.kda_layers, MLA on the rest, and both feed a dense or sigmoid-routed grouped MoE FFN (from #3345). The KDA mixer runs three short causal convs, the A_log/dt_bias per-channel log decay, beta = sigmoid(b_proj), the delta primitive, the gated output RMSNorm and o_proj; the MLA layer reuses the DeepSeek-V3 path with a direct query projection and the split per-head embed_q/unembed_out expansion, at the layer's compact KV row. delta_s and delta_conv thread through the existing recurrent-state ABI in prefill, single decode and ragged decode.

The checkpoint is the MLX-converted layout; Config::validate_recurrent_checkpoint checks every KDA, MLA and MoE tensor shape. A seeded synthetic 4-layer checkpoint (3 KDA + 1 MLA, 8 experts top-2) and its MLX eager greedy continuation are committed, because only the 48B-A3B checkpoint exists and does not fit this host. The oracle is mlxcel's own MLX eager model, not an independent HF implementation.

Validation

  • hip: token-exact vs the oracle (40 greedy tokens); xla_batch_bench --batch 4 --requests 8 reference-exact; the per-channel KDA probe reads max-abs 3.58e-7 (prefill) and 1.19e-7 (decode) at the synthetic KDA dims, and 2.68e-7 / 1.19e-7 at the 48B's Hv=32, Dk=128 geometry, all within the 5e-5 bar.
  • local-task: the same oracle and batch gates pass.
  • 608 lib tests pass, clippy -D warnings, fmt clean; make verify-env-var-docs, verify-versions, verify-kernel-dtype-keys and verify-used-by pass. The four new goldens are registered and every pre-existing golden re-emits byte-identically.
  • Logs and probe JSON: spike/openxla/kimi_linear_reference/.

Production-width limitation (measured)

delta_lowering_measure.py --dims kimi_prod plans 798.1 MiB of transient at capacity 256 and 12,739.5 MiB (12.4 GiB) at 4096 for one per-channel prefill (still within 5.4e-7 of the fp32 reference). 12.4 GiB cannot coexist with the 48B weights on 31 GiB, so production width needs a smaller chunk or Dk blocking first; the wiring keeps MLX's chunk 64 and spike/openxla/FINDINGS_ssm.md records the follow-up. Raw rows are in kimi_linear_reference/delta-production-geometry.json.

Closes #3354

@inureyes inureyes added status:review Under review type:enhancement New features, capabilities, or significant additions priority:low Low priority labels Dec 1, 2026
@inureyes
inureyes force-pushed the feature/issue-3354-kimi-linear branch 2 times, most recently from 53e02a8 to 4553e7e Compare December 1, 2026 10:50
Adds model_type kimi_linear to the OpenXLA emitter: a KDA mixer (per-channel gated delta rule, three short convs, A_log/dt_bias log-decay, sigmoid beta, gated RMSNorm output gate) on the layers listed in linear_attn_config.kda_layers, MLA on the rest (a direct query projection plus split per-head embed_q/unembed_out expansion, at the layer's compact KV row), and a sigmoid-routed MoE FFN. The KDA layers thread delta_s and delta_conv through the existing recurrent state ABI, so prefill, single decode and ragged continuous batching all carry them.

The Kimi checkpoint uses the MLX-converted layout (flattened A_log/dt_bias, q_conv/k_conv/v_conv, embed_q/unembed_out, stacked switch_mlp experts, mlp.e_score_correction_bias); Config::validate_recurrent_checkpoint cross-checks every shape. A new WeightScheme::KimiLinear names the KDA and MLA tensor lists in the emitter's arg order for the loader. The per-channel log gate is expanded to [rows, Hv, Dk] explicitly; without that broadcast iree-compile rejects the multiply.

Evidence: a seeded synthetic 4-layer checkpoint (3 KDA + 1 MLA, 8 experts top-2) and its MLX eager greedy continuation are committed under spike/openxla/kimi_linear_reference with the local-task and hip gate logs and probe JSON. New StableHLO goldens are registered; every existing golden re-emits byte-identically. Only the 48B-A3B real checkpoint exists and does not fit the 31 GiB host, so the synthetic model plus the MLX oracle is the whole evidence.

At the 48B KDA geometry the per-channel prefill plans 12,739.5 MiB of transient at context 4096 (798.1 MiB at 256) while staying within 5.4e-7 of the fp32 reference, so production width needs a smaller chunk or Dk blocking before it runs; FINDINGS_ssm.md records the measurement and the follow-up.

Refs #3354
@inureyes
inureyes force-pushed the feature/issue-3354-kimi-linear branch from 4553e7e to bbf132a Compare December 1, 2026 10:58
@inureyes
inureyes marked this pull request as ready for review December 1, 2026 10:59
@inureyes
inureyes merged commit fc4a1a2 into main Dec 1, 2026
35 of 36 checks passed
@inureyes
inureyes deleted the feature/issue-3354-kimi-linear branch December 1, 2026 10:59
@inureyes inureyes added status:done Completed and removed status:review Under review labels Dec 1, 2026
inureyes added a commit to Jaeyeong-CHOI/mlxcel that referenced this pull request Dec 1, 2026
lablup#3612 committed spike/openxla/kimi_linear_reference/model.safetensors after this branch was cut, and main fails the binary-assets check on it too. Unlike the RWKV7 fixture, it cannot be regenerated by a standalone script: examples/xla_kimi_linear_oracle.rs needs a full MLX build, and the committed oracle continuation and gate logs were measured against these exact bytes. Declare it with a 448 KiB ceiling and raise the total budget by its 390,720 bytes.

Refs lablup#3611
Refs lablup#3612
inureyes pushed a commit that referenced this pull request Dec 1, 2026
Two seeded synthetic checkpoints made main fail the binary-assets gate. The RWKV7 one from #3609 is removed from Git and ignored: spike/openxla/rwkv7_oracle.py regenerates it from seed 3355, and the two #3609 reports now show how to build the fixture outside the checkout before the parity gate. Regeneration on GB10 (aarch64) reproduced SHA-256 6b3b9811...d828c byte for byte, with identical greedy tokens.

The Kimi-Linear checkpoint from #3612 is declared instead, with a 448 KiB ceiling and the total budget raised by its 390,720 bytes, because regenerating it needs a full MLX build and its committed oracle and gate logs were measured against these exact bytes.

Refs #3609, #3612
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority:low Low priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(xla): Kimi-Linear (KDA delta + MLA attention + sigmoid MoE)

1 participant