fix(cache): treat empty paged length list as a benign no-op#826
Merged
Conversation
During batched speculative decode the model-owned paged families (gemma3/gemma4/llama4/qwen3_5/qwen3_next) build the per-layer `target_lens` for `CachePool::sync_paged_state_with_lengths` from their per-sequence `sequence_caches`. A just-admitted or speculative/draft row has empty `sequence_caches` before its first model-owned forward, so an EMPTY length list reaches the sync. The length-count guard treated that as a divergence and returned `CachePool: expected 32 paged layer lengths for seq-N, got 0`, which the scheduler swallowed into a `warn!` that spammed the log hundreds of times per burst. An empty length list is genuinely "nothing to mirror yet": the model-owned shadow paged state has no caches to populate on that tick, so the sync is a real no-op, not a length divergence. Add an early `Ok(())` for the empty case before the length-count check. A NONZERO count that differs from the layer count is still a real desync and still errors, unchanged. The swallowed-Err `warn!` at scheduler.rs is left as is; it now only fires for a genuine mismatch. The fix lives in the shared `CachePool` method so every model-owned family is covered by one change; the model-owned `sync_sequence_storage` impls and the paged block-table accounting are untouched. Add a `CachePool` unit test: a 2-layer model-owned shadow state accepts an empty length list as an Ok no-op that leaves the layer lengths unchanged, while a nonzero-but-wrong count still returns the mismatch Err. Closes #823
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
During batched speculative decode the
Failed to sync paged state for seq-N: CachePool: expected 32 paged layer lengths for seq-N, got 0warning spammed the server log hundreds of times per burst. The underlyingErrwas benign: an empty per-layer length list is the model-owned "nothing to mirror yet" case, not a real length divergence. This makes the empty case a legitimateOk(())no-op so the spam disappears while a genuine mismatch still errors.Root cause
The model-owned paged families (gemma3/gemma4/llama4/qwen3_5/qwen3_next) build the per-layer
target_lensforCachePool::sync_paged_state_with_lengthsfrom their per-sequencesequence_caches(src/models/gemma3.rs,llama4.rs,qwen3_5.rs). A just-admitted or speculative/draft row has emptysequence_cachesbefore its first model-owned forward, sovisible_lensis an empty vec and an EMPTY length list reaches the sync. The length-count guard insync_paged_state_with_lengthstreated0 != state.layers.len()as a divergence and returned the "expected N ... got 0" error, whichscheduler.rsswallowed into awarn!per tick per row. The model-owned paged family uses the paged backend for SHADOW block-table accounting only, so with no populated caches there is genuinely nothing to mirror on that tick.What changed
src/lib/mlxcel-core/src/cache.rs: insync_paged_state_with_lengths, add an earlyreturn Ok(())whentarget_lens.is_empty(), before thetarget_lens.len() != state.layers.len()count check, with a comment explaining the model-owned "nothing to mirror yet" no-op and why it is distinct from a nonzero partial count. The nonzero-mismatch error path is unchanged; a real desync still returnsErr.CachePoolmethod so every model-owned family is covered by one change. The model-ownedsync_sequence_storageimpls, thescheduler.rsswallowed-Errwarn!(which correctly fires only on a genuineErrnow), and the paged block-table accounting are untouched.CachePoolunit testsync_paged_state_with_lengths_empty_is_benign_noop: a 2-layer model-owned shadow state accepts an empty length list as anOkno-op that leaves the layer lengths unchanged, while a nonzero-but-wrong count still returns the mismatchErr. PureCachePoolunit test, no model load.Test plan
cargo test -p mlxcel-core --lib --features cuda sync_paged_state_with_lengths_empty_is_benign_noop(pass)cargo clippy -p mlxcel-core --lib --features cuda -- -D warnings(clean)cargo test -p mlxcel-core --lib --features cuda cachesingle-threaded: the new test and all sync/paged tests pass; the only 2 failures (cache::paged_detach::tests::detached_paged_set_accounts_real_pool_bytes,cache::paged_detach::tests::trim_detached_paged_to_enables_partial_prefix_adoption) are pre-existing on cleanmain(identicalassertion failed: handle.offset >= target_tokensinpaged_detach.rs, an unrelated module) and are not touched by this change.Closes #823