Repository navigation
Conversation
…al length For N > 1, make_mask trims the left padding by _idx - max_size + 1. After the window wraps, _idx is the ring cursor, but the update first puts the ring in temporal order (the length becomes the buffer length) and then drops that many oldest columns, so a left-padded row lost its oldest valid key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
BatchRotatingKVCache.make_maskdrops the oldest valid key of a left-padded row on every multi-token update after its sliding window wraps.For
N > 1the mask trims the left padding by_idx - max_size + 1. After a wrap,_idxis the ring cursor. Butupdate_and_fetchfirst puts the ring back in temporal order, so the length becomes the buffer length, and then drops that many oldest columns. The mask still uses the cursor, so the padding it trims is off by the cursor position and the row's first real key gets masked.The fix uses the buffer length for a multi-token update of a rotated cache. Single-token updates and caches that have not wrapped are unchanged.
Tests:
test_batch_rotating_wrapped_multi_token_matches_single_row: a left-padded row of a batch window that wraps in place, then gets 3-token updates, has to attend exactly like the same row in its ownRotatingKVCache. It fails on main and passes with the fix.test_batch_rotating_kv_cacheexpected the buggy mask for the 2-token update after the wrap. That update drops one padding slot, so the first real key is column 2, not 3. I changed the expected mask; the new test checks the same case against a single-row cache.python -m unittest tests.test_prompt_cache: 26 passed. Without the fix both tests above fail.This came up in oMLX (jundot/omlx#5235), where batched speculative verify over sliding-window layers takes this path. mlx-vlm has the same code; the same fix there is Neywa-Labs/mlx-vlm#2757.