Skip to content

feat: hybrid-SSM cache carve-out tests and multimodal digest plumbing - #182

Merged
inureyes merged 1 commit into
mainfrom
feature/issue-124-ssm-mm-digest-foundation
Jun 8, 2026
Merged

inureyes merged 1 commit into
mainfrom
feature/issue-124-ssm-mm-digest-foundation

Conversation

@inureyes

@inureyes inureyes commented Jun 8, 2026

Copy link
Copy Markdown
Member

Summary

Foundation for #124 (Hybrid SSM exclusion and multimodal adopt policy under the unified cache). Implements steps a and b of the agreed decomposition; the VLM-sharing enablement is the separate step c.

(a) Hybrid-SSM / recurrent carve-out: documented + regression-tested

The carve-out from cross-request block sharing is enforced by the sequence-state backend, not an ad-hoc check. A recurrent/hybrid family overrides supports_batching() to false, which routes the default sequence_state_layout() to SequenceStateBackend::ModelOwned. A ModelOwned sequence is rejected by both CachePool::detach and CachePool::detach_paged (both return None), so the scheduler can never donate it to the prompt-cache store, its store stays empty, and every adopt attempt misses. The same flag forces effective_decode_storage_backend to Dense, so --decode-storage-backend paged is silently ignored for these families and their decode output stays bit-identical to the dense path.

  • hybrid_ssm.rs module doc now spells out this two-mechanism guarantee and completes the coverage table (previously 7 of the 12 authoritative model_type entries).
  • New cache_pool_model_owned_recurrent_sequence_is_never_detachable (mlxcel-core) proves a model-owned recurrent sequence is non-detachable on both paths.
  • New all_hybrid_ssm_model_types_round_trip iterates HYBRID_SSM_MODEL_TYPES itself so the list can never drift from the detector.

(b) Multimodal digest plumbed into the prompt-cache key (behavior-neutral)

PromptCacheRequestContext gains an mm_digest field. The chat route builds the context after prepare_chat_request_with_cache so the digest is computed over the resolved (post base64 / file / URL) image and audio bytes, and compose_prompt_cache_key folds it into the bucket via PromptCacheKey::new_full instead of the hardcoded MultimodalDigest::empty().

  • Text-only requests hash to MultimodalDigest::empty(), so the composed key is byte-identical to the pre-change path.
  • Multimodal requests still bypass adopt and donate at the scheduler's is_multimodal gate, so this step changes no runtime behavior. It only makes the key collision-safe so step c can lift that gate and share image/audio prefixes without a text/image bucket collision.
  • New compose_prompt_cache_key_folds_request_multimodal_digest verifies, through the real key-composition seam, that text / image / different-image payloads land in distinct buckets and the text path matches an explicit empty digest.

Validation

  • cargo fmt --all -- --check: clean
  • cargo clippy --all-targets --features metal,accelerate -- -D warnings (cold): clean
  • cargo test --features metal,accelerate: mlxcel 3048 passed, mlxcel-core 844 passed, 0 failed

Follow-up

Step c (lift the is_multimodal gate, slice InputEmbeddings to the adopted suffix, keep MRoPE aligned, real-model VLM cold-vs-adopt parity) lands in a separate PR.

Part of #124

Foundation for #124 (steps a and b). Step a documents and regression-tests the existing hybrid-SSM/recurrent carve-out from the unified paged cache: a model that overrides supports_batching() to false allocates ModelOwned sequence state, which both CachePool::detach and CachePool::detach_paged reject, so a recurrent sequence can never be donated to the prompt-cache store and every adopt attempt misses. The same flag forces effective_decode_storage_backend to Dense, so --decode-storage-backend paged is silently ignored for these families and their output stays bit-identical to the dense path. New tests: cache_pool_model_owned_recurrent_sequence_is_never_detachable (cache layer) and all_hybrid_ssm_model_types_round_trip (drift guard over the authoritative model-type list).

Step b plumbs the resolved multimodal digest into the scheduler's prompt-cache key. The chat route now builds the PromptCacheRequestContext after request preparation so the digest sees the post-resolution image/audio bytes, the context carries an mm_digest field, and compose_prompt_cache_key folds it into the bucket via PromptCacheKey::new_full instead of the hardcoded empty digest. Text-only requests hash to MultimodalDigest::empty(), so the composed key is byte-identical to the pre-change path. Multimodal requests still bypass adopt and donate at the is_multimodal gate, so this step is behavior-neutral; lifting that gate to enable image/audio prefix sharing is step c.
@inureyes inureyes added type:enhancement New features, capabilities, or significant additions area:core mlxcel-core: MLX FFI, primitives, KV cache, layers area:models Model architectures, weights, loading, metadata labels Jun 8, 2026
@inureyes
inureyes merged commit 2203e0e into main Jun 8, 2026
4 checks passed
@inureyes
inureyes deleted the feature/issue-124-ssm-mm-digest-foundation branch June 8, 2026 02:51
@inureyes inureyes self-assigned this Jun 10, 2026
@inureyes inureyes added this to the 0.2 milestone Jun 21, 2026
@inureyes inureyes added the status:done Completed label Sep 6, 2026
be-free-snowboy pushed a commit to freestylejs/snowbrain-mlxcel that referenced this pull request Oct 27, 2026
…lablup#182)

Part of lablup#124 (steps a and b). SSM/recurrent carve-out from the unified paged cache is documented and regression-tested (the ModelOwned backend rejects both detach paths, so a recurrent sequence can never be donated). The resolved multimodal digest is plumbed into the prompt-cache key; text-only requests stay byte-identical and multimodal still opts out until step c.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core mlxcel-core: MLX FFI, primitives, KV cache, layers area:models Model architectures, weights, loading, metadata status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant