Repository navigation
fix: keep the hybrid prompt cache when --ctx-size is set - #207
Merged
Merged
Conversation
…ers a RotatingKVCache hybridCacheBoundary only accepted KVCacheSimple attention layers, so Qwen3.5/3.6 with --ctx-size (RotatingKVCache attention) silently lost the hybrid prompt cache and re-prefilled every turn. The hybrid path never trims; it restores the exact snapshot taken at the turn boundary, and a ring's state+metaState round-trip it even after wrapping, so accepting RotatingKVCache is safe. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014J4GsqznbKNX8tcKzNRxEr
2 of 3 tasks
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.
Problem
On hybrid models (Qwen3.5/3.6),
--ctx-sizemakesmakeAttentionKVCachereturn aRotatingKVCachefor the attention layers.hybridCacheBoundaryonly acceptedKVCacheSimple, so it returned nil. The request then fell to the sliding-window path, whoserestoremisses on anyMambaCacheand whosesaverefuses recurrent state. Result: with--ctx-size, every agent turn re-prefilled the whole conversation, and nothing in the log said why.Change
hybridCacheBoundaryalso acceptsRotatingKVCacheattention layers. This is safe because the hybrid path never trims: it restores the exact snapshot taken synchronously at the turn boundary, and a ring'sstate+metaState(keep, maxSize, offset, idx, wrapped) round-trip it, even once wrapped. #202 already detaches ring buffers on save/restore. The hybrid path already runs before the sliding-window one, so nothing else changes.Tests
New in
HybridPromptCacheTests: boundary accepts a rotating + Mamba cache; a wrapped ring is restored exactly after more decode on the live ring; a divergent prefix still misses. FullSwiftLMTestssuite: 219 pass.Live check
16 GB M2, Qwen3.5 MoE 4-bit (text-only via
--no-vision, #206),--stream-experts --ssd-prefetch --prefill-size 2048 --ctx-size 32768, three agent turns sharing a prefix:"Before" is the same rig and flags on
main+ #206. The "after" run used this branch + #206 (a local merge, not pushed); #206 is needed only because a VLM-capable checkpoint otherwise skips the cache.🤖 Generated with Claude Code