Fix KV cache concat trimming for multi-token updates#3
Open
artuskg wants to merge 1 commit into
Open
Conversation
bpcnpz
added a commit
to bpcnpz/voxmlx
that referenced
this pull request
Mar 28, 2026
Two bugs caused the encoder to produce garbage embeddings once audio exceeded the sliding window size: 1. Encoder KV cache was initialized with hardcoded 100_000 instead of the actual encoder.sliding_window (750). This meant the cache never rotated, growing unbounded until memory or attention degraded. 2. RotatingKVCache._update_concat trim calculation didn't account for the size of the appended keys, trimming one entry too few. Fixes awni#7. Based on patches from PRs awni#3 and awni#4. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Bug fix: KV cache concat trim for multi-token appends
Problem
RotatingKVCache._update_concat()trimmed as if each update appended exactly one token:For
S>1appends, cache length can exceedmax_sizeand stay above cap.Resolution
trim_size = max(0, cur + add - self.max_size)max_sizepositions.max_size > 0in constructor.Why this helps
This restores bounded-window semantics and prevents memory/context drift when updates append multiple tokens.
Regression tests
tests/test_bugfix_kvcache_optional.py::test_concat_append_respects_max_sizetests/test_bugfix_kvcache_optional.py::test_oversized_first_update_trims_to_max_sizeHow to run