Add sliding windows to the off-graph KV-cache reference - #21901
Open
kiymetakdemir wants to merge 2 commits into
Open
Add sliding windows to the off-graph KV-cache reference#21901kiymetakdemir wants to merge 2 commits into
kiymetakdemir wants to merge 2 commits into
Conversation
kiymetakdemir
requested review from
larryliu0820 and
mergennachin
as code owners
August 17, 2026 22:41
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21901
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit befbca3 with merge base c461421 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
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
Adds a sliding window to the eager KV-cache reference.
CacheConfig.windowtakes an int for every layer or one entry per layer, so a model that alternates policies (gemma-style) is expressible.Both reference caches honour it.
ContiguousReferenceCacheadds a lower bound to the band it already emits, and windowing alone is now enough to make a step EXPLICIT.CellReferenceCachememoizes the mask per window rather than per layer: occupancy, membership and causality are common to every layer of a step, and only the lower bound moves, so a mixed model pays two masks per step instead of one per layer.The reference masks; it does not evict. Cells stay allocated under a window, because reclaiming them when layers disagree needs one cache per policy group.
Files
extension/llm/cache/reference_cache.py—CacheConfig.window+window_for, the windowed band inContiguousReferenceCache._spec, and_CellStepPlansplit into a shared base plus a per-window memo.extension/llm/cache/test_update_and_attend.py— 8 new tests.Testing
pytest extension/llm/cache/test_update_and_attend.pyNew coverage: a window narrowing each query without crossing sequences, layers windowing independently, layers sharing a window sharing one mask, windowed decode attending only retained cells, and a window wider than the history staying fused.