feat(xla): Kimi-Linear (KDA delta + MLA attention + sigmoid MoE)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 6/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- rust
調査の方向性
Start in src/lib/mlxcel-xla/src/emitter/delta.rs, which the issue asks you to create with DeltaGate, DeltaConfig, delta_step and delta_prefill, and read config.rs:140 (MlaConfig), model.rs:2506 (emit_mla_attention) and model.rs:2938 (emit_transformer_layer). Blocking issues #3352, #3345 and #3344 are not yet merged. Done means a synthetic 4-layer Kimi-Linear is token-exact on hip against the MLX oracle and the KDA probe is within 5e-5.
索引モデルが issue の本文から書いたものです。
説明
Part of #564
Problem / Background
Epic #564 brings SSM / hybrid / recurrent architectures to the OpenXLA/IREE backend. Design record: spike/openxla/SSM_HYBRID_DESIGN.md (written 2026-07-01; most symbol locations it cites have moved, use the ones in this issue, which were re-located on main at 56bfb92a, and re-verify them before editing). The Stage 2a spike-first pattern this follows is in spike/openxla/STAGE2_DESIGN.md and spike/openxla/FINDINGS_phase2a.md.
Kimi-Linear interleaves KDA (Kimi Delta Attention, a per-channel gated delta rule) layers with MLA attention layers and a sigmoid-routed MoE. Only the 48B-A3B checkpoint exists, which does not fit this host. MLX reference: src/models/kimi_linear.rs.
Goal
A synthetic tiny Kimi-Linear generates and serves on hip, token-exact against the MLX eager oracle.
Scope
- Config
kimi_linear: layer pattern from its linear-attention layer list;DeltaConfig { gate: DeltaGate::PerChannel, .. }from the KDA head dims; existingMlaConfig(src/lib/mlxcel-xla/src/emitter/config.rs:140) andemit_mla_attention(src/lib/mlxcel-xla/src/emitter/model.rs:2506) for attention layers; sigmoid grouped router from #3345 (MoeScoring::Sigmoid { correction_bias, n_group, topk_group, routed_scaling_factor, norm_topk_prob }, selection onsigmoid(logits) + e_score_correction_bias, combine on uncorrected scores). - KDA mixer in
src/lib/mlxcel-xla/src/emitter/delta.rs(MixerKind::Kda): separate short convs on q, k, v (reusingssm.rsconv1d), per-channel gate fromf_a_proj/f_b_projwithA_loganddt_bias,beta = sigmoid(b_proj), the delta primitive, output gate (g_a_proj/g_b_proj) with gated RMSNorm,o_proj. Followkimi_linear.rsexactly. - Synthetic tiny Kimi-Linear (seeded, 4 layers, 3 KDA + 1 MLA, 8 experts top-2) written in the MLX-loadable layout.
The delta primitive from #3352 (restated):
// src/lib/mlxcel-xla/src/emitter/delta.rs (new)
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum DeltaGate {
Scalar, // g: [.., Hv] one log-decay per head (Qwen3-Next / Qwen3.5 GatedDeltaNet)
PerChannel, // g: [.., Hv, Dk] one log-decay per key channel (Kimi-Linear KDA)
}
#[derive(Clone, Debug, PartialEq)]
pub(crate) struct DeltaConfig {
pub n_k_heads: usize, pub n_v_heads: usize, // Hk, Hv; q/k heads repeat to Hv when Hv > Hk
pub head_k_dim: usize, pub head_v_dim: usize, // Dk, Dv
pub gate: DeltaGate,
pub chunk: usize, // 64, as MLX src/models/gated_delta.rs
pub conv_kernel: usize, // short causal conv before the recurrence (reuses ssm.rs conv1d)
pub use_qk_l2norm: bool,
}
pub(crate) fn delta_step(b: &mut Builder, c: &DeltaConfig, q: &Val /*[B,Hv,Dk]*/, k: &Val /*[B,Hv,Dk]*/, v: &Val /*[B,Hv,Dv]*/,
g: &Val /*[B,Hv] or [B,Hv,Dk]*/, beta: &Val /*[B,Hv]*/, s: &Val /*[B,Hv,Dk,Dv] f32*/) -> (Val /*o [B,Hv,Dv]*/, Val /*s'*/);
pub(crate) fn delta_prefill(b: &mut Builder, c: &DeltaConfig, q: &Val /*[T,Hv,Dk]*/, k: &Val, v: &Val /*[T,Hv,Dv]*/,
g: &Val /*[T,Hv] or [T,Hv,Dk]*/, beta: &Val /*[T,Hv]*/, s0: &Val /*[Hv,Dk,Dv] f32*/) -> (Val /*o [T,Hv,Dv]*/, Val /*s_T*/);
Recurrence (HF torch_recurrent_gated_delta_rule, fp32): if use_qk_l2norm, L2-normalize q and k per head; q *= 1/sqrt(Dk); per step S = S * exp(g) (broadcast over Dv, and over Dk too in Scalar mode); kv_mem = k^T S ([Dv]); delta = (v - kv_mem) * beta; S = S + k outer delta; o = q^T S. Prefill rows t >= real_len get g = 0 and beta = 0, which leaves S unchanged. The prefill form is chunked (chunk 64) with the intra-chunk triangular system solved by forward substitution unrolled over the chunk, mirroring MLX src/models/gated_delta.rs (gated_delta_chunked), and is checked against HF torch_chunk_gated_delta_rule. State tensors per family: delta_s [L_delta, Hv, Dk, Dv] F32 and delta_conv [L_delta, K-1, conv_dim] F32, in that order, appended to Config::state_tensors().
Hybrid contract from #3344 (restated so this issue stands alone): Config::layer_mixers: Vec<MixerKind> (Attention, Mamba2, None for an FFN-only layer, plus variants added by later units) selects the mixer per layer in emit_transformer_layer (src/lib/mlxcel-xla/src/emitter/model.rs:2938); Config::layer_has_ffn(li) selects whether the dense / MoE FFN runs; the KV cache is sized [B, L_attn, S, nkv, d] over attention layers only, and Config::attn_layer_index(li) -> Option<usize> maps a layer to its KV row (used by AttnLayout::write_read_kv and the shim's rg_dims); Config::state_layer_index(li) maps a recurrent layer to its row in each state tensor. The threaded-state ABI is the generic list from Config::state_tensors() (StateTensorSpec { name, dims, elem }), appended after the KV inputs/results in every graph flavor, with the KV region omitted when Config::has_kv_cache() is false.
Acceptance Criteria
- Oracle: mlxcel MLX eager
kimi_linearon the synthetic checkpoint, greedy 40 tokens, recorded in theoracle_continuation.pyJSON format. - CLI on
hiptoken-exact vs that oracle;xla_batch_bench --batch 4 --requests 8 --prompts <json>reference-exact. - KDA probe mode (per-channel gate) within 5e-5 on
hip(from #3352's probe, re-run with Kimi dims). - Goldens registered; previous goldens byte-identical; fmt, clippy, lib tests clean.
Host and environment
Host: ROCm gfx1151 (Strix Halo, 31 GiB unified memory), IREE hip and llvm-cpu / local-task. Every build and every GPU command runs under scripts/rocm_gpu_guard.sh --hold -- <cmd>.
eval "$(scripts/iree/setup-rocm.sh --env)"
export MLXCEL_XLA_DEVICE=hip MLXCEL_XLA_ROCM_TARGET=gfx1151
export OPENSSL_INCLUDE_DIR=/usr/include OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu CARGO_BUILD_JOBS=6
PY=spike/openxla/.venv/bin/python # or $MLXCEL_ORACLE_PYTHON
scripts/rocm_gpu_guard.sh --hold -- cargo build --release --features xla-iree --bin mlxcel --bin mlxcel-server
Dependencies
Blocked by #3352 (delta primitive above), #3345 (sigmoid router above), #3344 (hybrid contract above). Blocks #3357, #3358.
Risks
- No real-checkpoint proof on this host; the synthetic model plus MLX oracle is the whole evidence, so the PR must say so.
User decisions that apply
- Downloads are allowed. If
spike/openxla/.venvis missing, create it withuv venv --python 3.12 spike/openxla/.venvand install CPU torch and transformers as pinned inspike/openxla/requirements.lock(torch==2.12.1+cpu from the PyTorch CPU wheel index, transformers==5.12.1). Small HF-format checkpoints go intomodels/hf/<name>; confirm the exact HF repo id on the model page before downloading. Gated-licence models are skipped and reported unless the licence is already accepted on this account. - Families whose HF modeling code cannot run on CPU (Kimi-Linear, RWKV7, and Plamo2 if its remote code needs
mamba_ssm/causal_conv1d) use mlxcel's own MLX eager model as the oracle, following the pattern of thexla-reference-diagnosticsfeature examples (Cargo.toml:125,:570-575): run the MLX model greedily at temperature 0 on the same prompt and record its token ids in theoracle_continuation.pyJSON format soxla_oracle_checkandxla_batch_benchconsume it unchanged. - Prefix-hash sharing: the recurrent state cannot be rebuilt from a token-prefix hash, so no recurrent model may use the prompt cache or APC on the XLA path. The guard and its test land in #3341; do not attach the prompt-cache store for a config whose
Config::has_recurrent_state()is true.
- 主要言語
- Rust
- スター
- 505
- フォーク
- 81
- 平均マージ
- 14時間 2分
- マージ済み PR(30日)
- 448
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
lablup/mlxcel のほかの issue
-
area:core priority:high status:ready type:security
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
メンテナーはふだん 1 日以内に返信
-
priority:medium status:ready type:security
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
メンテナーはふだん 1 日以内に返信
-
area:models modeltype:text priority:medium status:in-progress type:bug
難易度 4/5 3〜5日 初心者へのやさしさ 57/100
メンテナーはふだん 1 日以内に返信
-
area:models priority:low status:ready type:test
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 1 日以内に返信
-
area:models modeltype:omni priority:medium status:ready type:bug
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
psmux-resurrect: restoring a session with a numeric name puts its windows into the wrong session (`new-window -t 4` is read as window 4)対応中かも @ealwanlee が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
psmux/psmux-plugins#47 ·
-
Link Checker Reportオープンautomated issue report
難易度 1/5 1時間未満 初心者へのやさしさ 76/100
ratatui/awesome-ratatui#598 ·
メンテナーはふだん 1 日以内に返信
-
release
難易度 1/5 1時間未満 初心者へのやさしさ 75/100
github/gh-aw-mcpg#17603 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
C-Bug S-Needs-Triage
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
bevyengine/bevy#26718 ·
メンテナーはふだん 2 日以内に返信