Skip to content

refactor: move SSM and convolution hybrids onto scheduler-owned layer state - #3647

Merged
inureyes merged 1 commit into
mainfrom
refactor/issue-3328-ssm-conv-layer-state
Dec 1, 2026
Merged

inureyes merged 1 commit into
mainfrom
refactor/issue-3328-ssm-conv-layer-state

Conversation

@inureyes

@inureyes inureyes commented Dec 1, 2026

Copy link
Copy Markdown
Member

Closes #3328

Summary

Moves all 12 SSM and convolution hybrid model families (lfm2, plamo2, falcon_h1, granitemoehybrid, jamba, mamba, mamba2, nemotron_h, rwkv7, recurrent_gemma, z1t, inkling) and their VLM wrappers (lfm2_vl, plamo2_vl, granite4_vision, nemotron_h_nano_omni_vl, inkling_vl) from ModelOwnedSequenceState onto scheduler-owned LayerState per ADR 0010 (epic #3259).

Key Changes

  • Composite layer state & transient slots (mlxcel-core): Added LayerStateKind::FullAndRecurrent and LayerState::KvAndRecurrent { kv, recurrent } for parallel KV+SSM/conv layers (Falcon-H1, Inkling) while preserving the one-entry-per-layer pool invariant, plus non-snapshot transient slots on RecurrentState for Inkling verify-block tails.
  • Generic snapshot & checkpoint encoding (state_snapshot.rs): Added LayerStateEncoding::RecurrentHybrid (with skip_empty_index for Nemotron-H MLP/MoE blocks) and LayerStateEncoding::LiveWindowAndRecurrent (with KVCache::seq_len() validation for Inkling trim_front live windows), preserving exact legacy tensor names, shapes, and scalars.
  • Speculative verify rewind & Inkling MTP: Added LanguageModel::rewind_layer_state_decode_appends, updated Engine::verify_rounds_unsupported to check keeps_state_outside_kv_slice(), and threaded &mut [LayerState] through InklingMtpTarget and its scheduler/burst callers.
  • Shared lending adapter (src/models/ssm_layer_state.rs): Introduced zero-copy LayerStateCodec / LentStates lending between pool LayerState slices and each family's typed per-layer caches, plus fail-closed refusal of SequenceId and id-less multi-row batches on legacy KVCache-slice entry points.
  • Hybrid-SSM APC opt-out (hybrid_ssm.rs): Added lfm2, lfm2_vl, lfm2-vl, lfm2_moe, inkling, and inkling_mm_model to HYBRID_SSM_MODEL_TYPES so KV-block APC reuse remains declined for all 12 families.

Verification

  • rg 'ModelOwnedSequenceState' across all 12 model files: 0 matches.
  • cargo test --profile test-fast --features metal,accelerate --lib --no-fail-fast -- --test-threads=1 lfm2 plamo2 falcon_h1 granitemoehybrid granite4_vision jamba mamba mamba2 nemotron_h rwkv7 recurrent_gemma z1t inkling hybrid_ssm snapshot_forwarding_tests state_snapshot ssm_layer_state_tests scheduler_runs_migrated_ssm_hybrids_under_paged_decode_override: 601 passed, 0 failed (10 ignored). Includes new encoder-parity and pinned-name snapshot tests, 16-step bit-exact snapshot round-trip tests on tiny fixtures, hybrid_ssm opt-out tests, and BatchScheduler tests under DecodeStorageBackend::Paged.
  • cargo test --profile test-fast --features metal,accelerate -p mlxcel-core --lib layer_state::tests: 9 passed, 0 failed.
  • cargo fmt --all -- --check: passed.
  • cargo clippy --profile test-fast --features metal,accelerate --lib --tests -- -D warnings -A clippy::manual_contains: passed (0 warnings across all modified files; manual_contains suppresses one pre-existing lint in untouched src/models/lfm3_omni_config.rs under rustc 1.97).
  • python3 scripts/ci/check_cross_repo_refs.py: passed.

Unmeasured

  • Release decode benchmark (B=1 / B=4 on real checkpoints): Unmeasured in this worktree because cold cargo build --release is excluded by the worktree watchdog guard and no local release binary/checkpoints were run here. Needs measurement during release/post-merge validation on real checkpoints.

@inureyes inureyes added status:done Completed type:refactor Code restructuring without changing functionality priority:medium Medium priority area:models Model architectures, weights, loading, metadata area:architecture Architecture and code structure changes labels Dec 1, 2026
… state

Move all 12 SSM and convolution hybrid families (lfm2, plamo2, falcon_h1, granitemoehybrid, jamba, mamba, mamba2, nemotron_h, rwkv7, recurrent_gemma, z1t, inkling) and their VLM wrappers (lfm2_vl, plamo2_vl, granite4_vision, nemotron_h_nano_omni_vl, inkling_vl) from ModelOwnedSequenceState onto scheduler-owned LayerState per ADR 0010 (#3328, epic #3259).

- Add LayerStateKind::FullAndRecurrent and LayerState::KvAndRecurrent for parallel KV+SSM/conv layers (Falcon-H1, Inkling) while preserving the one-entry-per-layer pool invariant, plus non-snapshot transient slots on RecurrentState for Inkling verify-block tails.
- Extend LayerStateEncoding and StatePolicy with RecurrentHybrid (supporting skip_empty_index for Nemotron-H) and LiveWindowAndRecurrent (supporting Inkling trim_front live windows) preserving legacy snapshot tensor names, shapes, and scalars.
- Add LanguageModel::rewind_layer_state_decode_appends and update Engine::verify_rounds_unsupported to check keeps_state_outside_kv_slice() so Inkling prompt-lookup verify rewind runs on scheduler-owned state.
- Add shared zero-copy LayerStateCodec / LentStates lending adapter in src/models/ssm_layer_state.rs and enforce fail-closed refusal of SequenceId and id-less multi-row batches on legacy KVCache-slice entry points.
- Keep all 12 families (including lfm2 and inkling variants) listed in HYBRID_SSM_MODEL_TYPES so KV-block APC reuse remains disabled.
- Add encoder-parity and pinned-name snapshot tests, 16-step bit-exact snapshot round-trip tests on tiny fixtures, and BatchScheduler tests under DecodeStorageBackend::Paged.
@inureyes
inureyes force-pushed the refactor/issue-3328-ssm-conv-layer-state branch from 8b4da5e to 769e55f Compare December 1, 2026 15:57
@inureyes
inureyes marked this pull request as ready for review December 1, 2026 15:58
@inureyes
inureyes merged commit 52e31d3 into main Dec 1, 2026
35 of 36 checks passed
@inureyes
inureyes deleted the refactor/issue-3328-ssm-conv-layer-state branch December 1, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:architecture Architecture and code structure changes area:models Model architectures, weights, loading, metadata priority:medium Medium priority status:done Completed type:refactor Code restructuring without changing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: Move the SSM and convolution hybrids onto scheduler-owned layer state

1 participant