[PR #11611] [MERGED] kvcache: Enable SWA to retain additional entries #24133

Closed
opened 2026-04-19 17:24:09 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/11611
Author: @jessegross
Created: 7/31/2025
Status: Merged
Merged: 7/31/2025
Merged by: @jessegross

Base: mainHead: jessegross/swa


📝 Commits (1)

  • a6dcf5c kvcache: Enable SWA to retain additional entries

📊 Changes

2 files changed (+196 additions, -42 deletions)

View changed files

📝 kvcache/causal.go (+77 -40)
📝 kvcache/causal_test.go (+119 -2)

📄 Description

Models that use sliding window attention can only resume a sequence from the cache if it falls within the saved windows. This works well if the next message picks up where the old one left off. However, it generally prevents a partial prefix match unless the entire conversation falls within the sliding window.

This can be a problem with reasoning models where the traces are supposed to be removed from future messages, forcing the entire history to be re-evaluated.

This change allows models to specify that a larger amount of the history be retained in memory, to allow more partial resumption. It still respects the window that the model was trained on for token generation.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/11611 **Author:** [@jessegross](https://github.com/jessegross) **Created:** 7/31/2025 **Status:** ✅ Merged **Merged:** 7/31/2025 **Merged by:** [@jessegross](https://github.com/jessegross) **Base:** `main` ← **Head:** `jessegross/swa` --- ### 📝 Commits (1) - [`a6dcf5c`](https://github.com/ollama/ollama/commit/a6dcf5c3e46b4e5503d99f2a28f6fec5e1063d46) kvcache: Enable SWA to retain additional entries ### 📊 Changes **2 files changed** (+196 additions, -42 deletions) <details> <summary>View changed files</summary> 📝 `kvcache/causal.go` (+77 -40) 📝 `kvcache/causal_test.go` (+119 -2) </details> ### 📄 Description Models that use sliding window attention can only resume a sequence from the cache if it falls within the saved windows. This works well if the next message picks up where the old one left off. However, it generally prevents a partial prefix match unless the entire conversation falls within the sliding window. This can be a problem with reasoning models where the traces are supposed to be removed from future messages, forcing the entire history to be re-evaluated. This change allows models to specify that a larger amount of the history be retained in memory, to allow more partial resumption. It still respects the window that the model was trained on for token generation. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-19 17:24:09 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#24133