refactor: Move Gemma 4 and AFMoE onto scheduler-owned layer state
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 12/100
- Tipo de issue
- Refactorización
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- rust
- Área
- machine-learning
Línea de trabajo
Start from ADR docs/adr/0010-scheduler-owned-sequence-state.md and the Gemma 3 and Qwen 3.5 migrations on branch refactor/issue-3254-scheduler-owned-state, since PR #3305 is not yet merged. Then read src/models/gemma4.rs, src/models/afmoe.rs, src/models/kv_ring_checkpoint.rs and gemma4_ring_checkpoint_tests. Done means no ModelOwnedSequenceState in the text path, bit-exact snapshot round trips, and the ignored ring checkpoint tests passing unchanged.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
Gemma 4 and AFMoE still keep per-sequence layer state inside the model wrapper (ModelOwnedSequenceState from src/models/model_owned.rs) with per-family snapshot and checkpoint hooks, so the scheduler cannot own, report, snapshot or restore their state through the generic path that Gemma 3 and Qwen 3.5 use after #3254.
Recorded reason (ADR 0010 audit): Gemma 4's wrapper doc says its sliding-window-aware Cache enum (src/models/gemma4.rs) cannot be wired to scheduler-managed &mut [KVCache] slices, mirroring Gemma 3. AFMoE's module doc says sliding layers need a RotatingKVCache and global layers a KVCache, which does not fit the trait's homogeneous slice. forward_layer_state removes that constraint.
Goal
Migrate gemma4 (src/models/gemma4.rs, src/vision/gemma4_vl.rs, src/vision/gemma4_unified.rs) and afmoe (src/models/afmoe.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 families keep the ring-checkpoint hooks #3255 added (
state_checkpoint_from_snapshot,restore_sequence_state_from_checkpoint), which callmodels::kv_ring_checkpoint(src/models/kv_ring_checkpoint.rs), the same functions the generic path calls. Migrating deletes the hooks and leaves one caller. - Gemma 4 E-series KV-shared layers are
LayerStateKind::None: they store nothing and restore fresh. The forward-localshared_kv_storestays in the forward. - Gemma 4 MTP hooks reach state by
Option<SequenceId>(speculative_cache_offset,enable_mtp_rotating_cache_buffer,rollback_speculative_cache,gather_speculative_cache,prefill_mtp_chunk, insrc/models/gemma4.rsandsrc/models/gemma4_mtp_target.rs).Gemma4MtpTargetAdapterhas to carry the borrowed layer state for a tick, asQwen35MtpTargetAdapter(src/models/qwen3_5_mtp_target.rs) does after #3254.enable_mtp_rotating_cache_bufferswitches a ring into buffered mode, and a snapshot is refused while it is active; keep that refusal. - The VL and Unified wrappers keep
Gemma4PerLayerInputsState(src/vision/gemma4_per_layer_inputs_state.rs, a per-SequenceIdside map), like Qwen 3.5's MRoPE map. - Gemma 4 declines padded prefill today; keep that.
- AFMoE has no speculative hooks and is the simpler half.
Scope
In scope: src/models/gemma4.rs, src/models/gemma4_mtp_target.rs, src/models/gemma4_mtp_target_rows.rs, src/vision/gemma4_vl.rs, src/vision/gemma4_unified.rs, src/models/afmoe.rs, and their tests.
Out of scope: the other sliding-window families and the deletion of the gemma3::Cache enum that AFMoE and Kolibri-1 share (tracked by #3325); padded prefill for Gemma 4.
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/gemma4.rs src/models/gemma4_mtp_target.rs src/models/afmoe.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 existing
gemma4_ring_checkpoint_tests(ignored, bit-exact vs cold plus a negative control) pass unchanged in assertions. -
--ctx-checkpointsbehaviour and/v1/cache/statsfields are unchanged. - Gemma 4 MTP parity tests pass.
- 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
cargo test --profile test-fast --features metal,accelerate gemma4_ring_checkpoint_tests -- --ignored --test-threads=1
rg 'ModelOwnedSequenceState' src/models/gemma4.rs src/models/gemma4_mtp_target.rs src/models/afmoe.rs
- Lenguaje dominante
- Rust
- Estrellas
- 505
- Forks
- 81
- Merge medio
- 14 h 2 min
- PR fusionados (30 d)
- 448
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de lablup/mlxcel
-
area:core priority:high status:ready type:security
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
priority:medium status:ready type:security
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
Los mantenedores suelen responder en 1 día
-
area:models modeltype:text priority:medium status:in-progress type:bug
Dificultad 4/5 3-5 días Aptitud para principiantes 57/100
Los mantenedores suelen responder en 1 día
-
area:models priority:low status:ready type:test
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
Los mantenedores suelen responder en 1 día
-
area:models modeltype:omni priority:medium status:ready type:bug
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
Los mantenedores suelen responder en 1 día
Todos los issues de lablup/mlxcel
Issues similares
-
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)Posiblemente ocupada @ealwanlee la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
psmux/psmux-plugins#47 ·
-
Link Checker ReportAbiertoautomated issue report
Dificultad 1/5 Menos de una hora Aptitud para principiantes 76/100
ratatui/awesome-ratatui#598 ·
Los mantenedores suelen responder en 1 día
-
release
Dificultad 1/5 Menos de una hora Aptitud para principiantes 75/100
github/gh-aw-mcpg#17603 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
C-Bug S-Needs-Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
bevyengine/bevy#26718 ·
Los mantenedores suelen responder en 2 días