[PR #11561] [MERGED] kvcache: Don't shift empty batches #12318

Closed
opened 2025-11-12 16:33:19 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/11561
Author: @jessegross
Created: 7/28/2025
Status: Merged
Merged: 7/29/2025
Merged by: @jessegross

Base: mainHead: jessegross/shift


📝 Commits (1)

  • dd7c90e kvcache: Don't shift empty batches

📊 Changes

1 file changed (+17 additions, -4 deletions)

View changed files

📝 kvcache/causal.go (+17 -4)

📄 Description

When we context shift, we delete half the context and apply RoPE with an offset to the other half. We used to RoPE across the entire context in a single pass with a zero offset for the deleted section. With the change to shifting in batches, we can skip any batches where all of the offsets would be zero. This typically reduces the number of operations by half.


🔄 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/11561 **Author:** [@jessegross](https://github.com/jessegross) **Created:** 7/28/2025 **Status:** ✅ Merged **Merged:** 7/29/2025 **Merged by:** [@jessegross](https://github.com/jessegross) **Base:** `main` ← **Head:** `jessegross/shift` --- ### 📝 Commits (1) - [`dd7c90e`](https://github.com/ollama/ollama/commit/dd7c90e530574f05d15ce3ba51ecaddd2ec1047c) kvcache: Don't shift empty batches ### 📊 Changes **1 file changed** (+17 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `kvcache/causal.go` (+17 -4) </details> ### 📄 Description When we context shift, we delete half the context and apply RoPE with an offset to the other half. We used to RoPE across the entire context in a single pass with a zero offset for the deleted section. With the change to shifting in batches, we can skip any batches where all of the offsets would be zero. This typically reduces the number of operations by half. --- <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 2025-11-12 16:33:19 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama-ollama#12318