Repository navigation
fix(xla): keep recurrent models out of prefix-hash caches - #3379
Conversation
A saved token prefix cannot restore recurrent state. On the OpenXLA backend this held only because the worker drops prompt-cache warmups, while ModelProvider still attached the store. A new guard (server::xla_prompt_cache_guard) decides from the emitter's Config::has_recurrent_state() (new mlxcel_xla::config_json_has_recurrent_state) or the shared hybrid list: startup builds no store and turns APC off with one info line, and the provider's OpenXLA arm drops any store passed to it. HYBRID_SSM_MODEL_TYPES now also names qwen3_5 (with _moe and _text spellings), granitemoehybrid, falcon_h1 and plamo2/plamo2vl. On MLX membership only turns APC off at startup; these families keep state outside the KV slice, so they never reached the block-hash store, and snapshots and #3047 state checkpoints do not read the APC flag (a new test shows the same checkpoint hit with APC on and off). The startup detector now tolerates HF's bare Infinity, which left APC on for HF Mamba2 and Nemotron-H configs. Validated with the prompt_cache and guard unit tests, and an XLA mamba2-130m server with prompt cache and APC requested: zero cache lookups and hits, both outputs equal the CLI. Closes #3341
The emitter module only compiles with the iree feature or in tests, so mlxcel-xla without iree failed to build. The root crate calls the function only under xla-iree.
The guard tests exercised only the helpers in xla_prompt_cache_guard, so dropping the call from startup::resolve_prompt_cache_store left every test green while a recurrent OpenXLA model got a store again. The new test runs the resolver under MLXCEL_BACKEND=xla (env lock held): tiny Mamba2 and a listed granitemoehybrid config get no store with prompt cache and APC cleared, and a dense Llama config keeps its store and APC. With the startup call disabled it fails with (true, true, false) for Mamba2. Refs #3341
Implementation Review SummaryIntent
Findings Addressed
Remaining Items
Verification
APC is read only by the dense store (insert chain, I reverted each change locally. Without the list and sanitizer changes, 6 tests fail. With the guard neutralized, 3 guard tests fail. Run on gfx1151: |
The OpenXLA prompt-cache guard returned "may share prefixes" when config.json was missing or did not parse, so startup and the provider's OpenXLA arm kept a store attached to a model whose recurrence the guard never checked. The serve engine parses the same text with the same parser and never consumes the store today, so nothing leaked, but an ambiguous config now leaves the cache and APC off instead of on. New test an_unreadable_or_unparseable_config_fails_closed covers a missing and a truncated config.json; it fails on the previous guard. The guard and hybrid_ssm tests pass under --features xla-iree. Refs #3341
Security and performance reviewNo CRITICAL, HIGH or MEDIUM findings. One LOW hardening fixed in c0566f6.
Checked, no change needed:
Validation: guard and |
…ent-no-prefix-share
…r test startup_resolver_builds_no_store_for_an_xla_recurrent_model restored MLXCEL_BACKEND by hand after the assertions' inputs were computed, so a panic in the resolver would leave the variable set for later tests. A BackendEnvGuard now sets it and restores the previous value on drop, under the crate-wide env lock. Refs #3341
Summary
Epic #564 U5. Recurrent models now provably never take part in prefix-hash sharing, on OpenXLA and on MLX.
src/server/xla_prompt_cache_guard.rs). The decision isConfig::has_recurrent_state()(newmlxcel_xla::config_json_has_recurrent_state) or membership inHYBRID_SSM_MODEL_TYPES, so families the emitter cannot load yet are refused too. It is enforced in two places.startup::resolve_prompt_cache_storebuilds no store and clearsprompt_cache.enabledandapc.enabled, logging one info line that names the model type. Because of that, neitherAppStatenor the provider holds a store, and/v1/cache/statsreportsenabled: false.ModelProvider's OpenXLA arm also drops a store that any other caller passes in. ThePromptCacheWarmupdrop inxla_worker_admission.rsis unchanged and now points at the guard.falcon_h1,plamo2(+plamo2vl),qwen3_5(+qwen3_5_text,qwen3_5_moe,qwen3_5_moe_text) andgranitemoehybrid, plus architecture fragments for each.Infinity. Before this, HF Mamba2 and Nemotron-H configs failed the strict parse and kept APC on.What list membership does on MLX
The list has one consumer, the startup APC opt-out (now
disable_apc_for_hybrid_ssm). It setsapc.enabled = falseand does nothing else. APC is read only by the dense KV store: the block-hash chain on insert, partial-match lookup,apc_statsand/v1/cache/stats. It does not touch snapshots, #3047 state checkpoints, paged KV or batching.The four families already keep their state outside the KV slice. Falcon-H1, PLaMo 2 and Granite 4.0-H are
ModelOwned, and Qwen3.5 isSchedulerOwned. So the scheduler skips the dense lookup and the dense donate for them, whether or not they batch. In practice the widening changes the startup warning and the reportedapc_enabled: false, because--apc-enableddefaults to true. #3047 checkpoints keep working:state_checkpoints_do_not_depend_on_apcgets the same checkpoint hit with APC on and off.Changes during review
startup::resolve_prompt_cache_storeleft every guard test green).startup_resolver_builds_no_store_for_an_xla_recurrent_modelruns the resolver underMLXCEL_BACKEND=xlaand fails with the call removed. Left (LOW): the guard logs its disable line even when the prompt cache was never enabled; theModelProviderOpenXLA-arm drop has no direct test (it needs a real XLA worker and startup already passesNone).xla_recurrent_familyreturned "may share" whenconfig.jsonwas missing or unparseable, so the store stayed attached (fail-open; not exploitable because such a model cannot load and the XLA worker never reads the store). It now fails closed and disables the cache and APC.an_unreadable_or_unparseable_config_fails_closedfails without the fix. Cross-tenant paths (startup, in-process, router children, runtime settings PATCH,/v1/cache), crafted configs and env mismatches were checked with no further finding.MLXCEL_BACKENDthrough a drop guard so a panic cannot leak it into later tests.Test plan
cargo test --profile test-fast --lib prompt_cache(382 pass) and the same with--features xla-ireeplusxla_prompt_cache_guard(386 pass), run withMLXCEL_REQUIRE_MODELS=1. Covers the 13 epic types through the XLA guard and the shared list, tiny and local HF mamba2, and the local qwen3.5-0.8b and granite-4.0-h-tiny configs.mlxcel-xlatestconfig_json_has_recurrent_state_matches_the_configmamba2-130mwith--prompt-cache-enabled=true --apc-enabled=true --metrics, two completions sharing all but the last few of their 68 prompt tokens. Prompt-cache hits, misses and snapshot hits are all 0,/v1/cache/statsreportsenabled: false, and both outputs equalmlxcel generate.apc_enabled: false, 0 dense lookups and 1 snapshot hit (68 tokens). Every output is byte-identical to origin/main with APC on. Requests 1 and 2 equal--no-prompt-cacheand the CLI. Granite request 3 also matches. Qwen3.5 request 3 (the snapshot hit) parts from the cold run at about token 9 on both main and this branch. That is the known two-forward partition effect, not this change.cargo fmt --check,cargo clippy --all-targets -D warnings,--features xla-iree --all-targets, and-p mlxcel-xlawith and withoutireeCloses #3341