Skip to content

Add sliding windows to the off-graph KV-cache reference - #21901

Open
kiymetakdemir wants to merge 2 commits into
pytorch:mainfrom
kiymetakdemir:kvcache-ring-reference
Open

Add sliding windows to the off-graph KV-cache reference#21901
kiymetakdemir wants to merge 2 commits into
pytorch:mainfrom
kiymetakdemir:kvcache-ring-reference

Conversation

@kiymetakdemir

Copy link
Copy Markdown
Contributor

Summary

Adds a sliding window to the eager KV-cache reference. CacheConfig.window takes 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. ContiguousReferenceCache adds a lower bound to the band it already emits, and windowing alone is now enough to make a step EXPLICIT. CellReferenceCache memoizes 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.pyCacheConfig.window + window_for, the windowed band in ContiguousReferenceCache._spec, and _CellStepPlan split 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.py

New 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.

@pytorch-bot

pytorch-bot Bot commented Aug 17, 2026

Copy link
Copy Markdown

🔗 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 Failures

As of commit befbca3 with merge base c461421 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 17, 2026
@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant