refactor: Move the linear-attention hybrids onto scheduler-owned layer state
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 8/100
- issue の種類
- リファクタリング
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- rust
調査の方向性
Do not start until PR #3305 lands; first read the ADR docs/adr/0010-scheduler-owned-sequence-state.md and the migrated Qwen 3.5 path in src/models/qwen3_5_layer_state.rs, then the existing model-owned state in src/models/model_owned.rs. Use src/server/prompt_cache/hybrid_ssm.rs to see which families are in HYBRID_SSM_MODEL_TYPES, and src/models/hybrid_snapshot.rs plus src/models/qwen4_exp_checkpoint_tests.rs as the tests to keep passing. Done means the rg 'ModelOwnedSequenceState' acceptance check is empty for the five files, the snapshot-parity test pins the old tensor names, and the bit-exact 16-token round trip passes.
索引モデルが issue の本文から書いたものです。
説明
Part of #3259
Follows #3254 (PR #3305), which introduced scheduler-owned layer state for Gemma 3 and Qwen 3.5 and recorded the design in ADR docs/adr/0010-scheduler-owned-sequence-state.md. PR #3305 is open at filing time: the ADR, LayerStateKind, LayerState, LayerStateEncoding, LayerStateSnapshotSpec, the four layer-state methods on LanguageModel (layer_state_kinds, make_layer_state, layer_state_snapshot_spec, forward_layer_state), src/server/prompt_cache/state_snapshot.rs, models::pooled_model::Pooled and qwen3_5_layer_state::LentCaches exist on branch refactor/issue-3254-scheduler-owned-state and reach main only when PR #3305 merges.
Problem / Background
The GatedDeltaNet and linear-attention hybrids keep per-sequence layer state inside the model wrapper (ModelOwnedSequenceState from src/models/model_owned.rs). Qwen 3.5 migrated in #3254, but still lends its layers a model-owned Qwen3NextCache through qwen3_5_layer_state::LentCaches because Qwen3-Next shares that type.
Recorded reason (ADR 0010 audit): Qwen3-Next interleaves attention and linear layers, so it cannot use the trait's homogeneous slice. Qwen4-Exp's attention layers carry an index cache beside their KV cache and its PLE layers a convolution window and token contexts beside their GatedDeltaNet state. Bailing's linear layers hold a recurrent state and its global layers a KV cache. Kimi Linear and Kimi K3 record no reason in source. Qwen3-Next, Kimi Linear and Kimi K3 are in HYBRID_SSM_MODEL_TYPES (src/server/prompt_cache/hybrid_ssm.rs) because recurrent state cannot be rebuilt from token-prefix KV blocks.
Goal
Migrate these families onto scheduler-owned layer state, as defined below: qwen3_next (src/models/qwen3_next.rs), qwen4_exp (src/models/qwen4_exp.rs, and src/vision/qwen4_exp_vl.rs), bailing_moe_linear (src/models/bailing_moe_linear.rs), kimi_linear (src/models/kimi_linear.rs), kimi_k3 (src/models/kimi_k3.rs, and src/vision/kimi_k3_vl.rs).
Definition of "migrate"
Report LanguageModel::layer_state_kinds(), implement forward_layer_state, name a LayerStateSnapshotSpec, delete the wrapper's ModelOwnedSequenceState and its per-family snapshot hooks, forward the four layer-state methods through every VLM wrapper, and move model-level tests onto models::pooled_model::Pooled.
What migrating involves
- Qwen3-Next uses the
Hybridencoding as Qwen 3.5 does. Once both are migrated,Qwen3NextCachehas no model-owned user left except Qwen4-Exp's sibling type, and Qwen 3.5'sqwen3_5_layer_state::LentCacheslending step (src/models/qwen3_5_layer_state.rs) can be removed by making the decoder layers run overLayerStatedirectly. - Qwen4-Exp needs family-specific recurrent slots (PLE convolution window, QSA index tensors) and host-side
Vec<i64>token contexts thatRecurrentStatedoes not hold today. Decide whetherRecurrentStategains a non-tensor payload or the contexts are encoded as tensors. It also keeps a second per-sequence state, the rollback log behindsupports_speculative_verify_rewind()(src/models/qwen4_exp_rollback.rs), whose replay needs both; the engine's generic decode rewind does not cover a verify-block rewind. - Bailing, Kimi Linear and Kimi K3 need their own encodings or a parameterized
Hybrid(slot prefix and attention names differ per family). Kimi Linear and Kimi K3 have no snapshot hooks and gain prefix reuse and state checkpoints. - Qwen3-Next has a pipeline stage executor, which keeps its own store.
- MRoPE side maps stay keyed by sequence id.
Scope
In scope: the five families and two VLM wrappers listed under Goal, the RecurrentState payload decision for Qwen4-Exp, removal of LentCaches once Qwen3-Next is migrated, and tests.
Out of scope: the Qwen3-Next pipeline stage executor's store; MRoPE side maps (unchanged).
Implement all families in one PR, run the local gate once at the end, and keep pushes to a minimum.
Acceptance Criteria
-
rg 'ModelOwnedSequenceState' src/models/qwen3_next.rs src/models/qwen4_exp.rs src/models/bailing_moe_linear.rs src/models/kimi_linear.rs src/models/kimi_k3.rsreturns nothing for the text path. - A snapshot written by the generic path has the tensor names, shapes and scalars the family wrote before (a test compares both encoders and pins the names).
- Bit-exact round trip on a tiny fixture: prefill P with a fixed partition, snapshot, restore into a fresh pool sequence, decode 16 tokens, equal to a cold run with the same partition.
- A scheduler test under the paged decode override (
--decode-storage-backend paged) passes for the family. - No decode regression: B=1 and B=4 decode tok/s at 256 and 8192 prompt tokens, main against the branch, interleaved with a null arm, recorded in
docs/benchmark_results/. - The #3047 state-checkpoint tests pass unchanged in assertions for Qwen3-Next and Qwen4-Exp (
src/models/qwen4_exp_checkpoint_tests.rsand the Qwen3-Next coverage aroundsrc/models/hybrid_snapshot.rs). - The Qwen4-Exp MTP and speculative-verify rewind tests pass.
- Integrated: the server and CLI paths for every family run through the scheduler-owned state, with no model-owned copy left behind.
Verification
cargo fmt --all -- --check
cargo clippy --workspace --all-targets --features metal,accelerate -- -D warnings
cargo test --workspace --profile test-fast --features metal,accelerate --no-fail-fast -- --test-threads=1
rg 'ModelOwnedSequenceState' src/models/qwen3_next.rs src/models/qwen4_exp.rs src/models/bailing_moe_linear.rs src/models/kimi_linear.rs src/models/kimi_k3.rs
- 主要言語
- 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 日以内に返信