refactor: Extend scheduler-owned layer state to composite per-layer state (DeepSeek V4, IQuest-Coder Loop)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 12/100
Research direction
Start by reading ADR docs/adr/0010-scheduler-owned-sequence-state.md and PR #3305, since the layer-state API this issue extends only exists on that branch. Then read src/lib/mlxcel-core/src/cache/layer_state.rs and src/server/prompt_cache/state_snapshot.rs to see the current single-storage-per-layer model, followed by the DeepSeek V4 and IQuest-Coder Loop model files named in the issue. Done means both families report layer_state_kinds, implement forward_layer_state, name a LayerStateSnapshotSpec, delete ModelOwnedSequenceState, and pass the acceptance tests and benchmarks listed.
Written by the indexing model from the issue text.
Description
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
DeepSeek V4 and IQuest-Coder Loop keep per-sequence layer state inside the model wrapper (ModelOwnedSequenceState from src/models/model_owned.rs) because each layer index holds more than one storage, which LayerState (one storage per layer, src/lib/mlxcel-core/src/cache/layer_state.rs) cannot express today.
Recorded reason (ADR 0010 audit): DeepSeek V4's module doc says its heterogeneous per-layer state (a rotating local KV plus one or two pooling caches) does not fit the trait's homogeneous slice. IQuest-Coder Loop's wrapper doc says the family needs two caches per layer, one of them a RotatingKVCache, and excludes prefix reuse on purpose.
Goal
Decide the composite per-layer representation and migrate deepseek_v4 (src/models/deepseek_v4.rs, src/models/deepseek_v4_attention.rs, src/models/deepseek_v4_compress.rs) and iquestloopcoder (src/models/iquestloopcoder.rs, src/models/iquestloopcoder_model.rs) onto scheduler-owned layer state, as defined below.
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
- Both need more than one storage per layer index. This issue decides the representation (a composite
LayerStatevariant, or a per-layer group) and shares it with Falcon-H1 and Inkling from #3328 if that issue has not settled it. Neither issue blocks the other. - DeepSeek V4's pooled state folds
ratiopositions into one row with a remainder buffer, so it cannot be truncated and haseval_statebarriers (src/models/deepseek_v4_compress.rs) to preserve. Its paged length mirror reportslocal.offset, not a visible length. - IQuest-Coder Loop keeps prefix reuse off by design. Migrating moves ownership only;
supports_snapshot_reuse()staysfalseunless the issue revisits that decision with evidence.
Scope
In scope: the composite per-layer representation in src/lib/mlxcel-core/src/cache/layer_state.rs and its handling in src/server/prompt_cache/state_snapshot.rs, the two families listed under Goal, and tests.
Out of scope: enabling prefix reuse for IQuest-Coder Loop without new evidence; truncation of DeepSeek V4's pooled state.
Implement both families in one PR, run the local gate once at the end, and keep pushes to a minimum.
Acceptance Criteria
-
rg 'ModelOwnedSequenceState' src/models/deepseek_v4.rs src/models/iquestloopcoder_model.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. This criterion applies to DeepSeek V4 only if the issue enables snapshot reuse for it.
- 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 chosen composite representation is recorded in ADR
docs/adr/0010-scheduler-owned-sequence-state.mdor the PR, with the rejected alternative and the reason. - Integrated: the server and CLI paths for both families 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/deepseek_v4.rs src/models/iquestloopcoder_model.rs
- Dominant language
- Rust
- Stars
- 505
- Forks
- 81
- Avg merge
- 14h 2m
- Merged PRs (30d)
- 448
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from lablup/mlxcel
-
area:core priority:high status:ready type:security
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
priority:medium status:ready type:security
Difficulty 4/5 3-5 days Newbie friendliness 45/100
Maintainers usually reply within 1 day
-
area:models modeltype:text priority:medium status:in-progress type:bug
Difficulty 4/5 3-5 days Newbie friendliness 57/100
Maintainers usually reply within 1 day
-
area:models priority:low status:ready type:test
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 1 day
-
area:models modeltype:omni priority:medium status:ready type:bug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
Maintainers usually reply within 1 day
Similar issues
-
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)Possibly taken @ealwanlee claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
psmux/psmux-plugins#47 ·
-
Link Checker ReportOpenautomated issue report
Difficulty 1/5 Under an hour Newbie friendliness 76/100
ratatui/awesome-ratatui#598 ·
Maintainers usually reply within 1 day
-
release
Difficulty 1/5 Under an hour Newbie friendliness 75/100
github/gh-aw-mcpg#17603 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
C-Bug S-Needs-Triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
bevyengine/bevy#26718 ·
Maintainers usually reply within 2 days