[PR #7158] [MERGED] runner.go: Handle truncation of tokens for stop sequences #12335

Closed
opened 2026-04-12 23:55:52 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/7158
Author: @jessegross
Created: 10/10/2024
Status: Merged
Merged: 10/10/2024
Merged by: @jessegross

Base: mainHead: jessegross/bug7153


📝 Commits (2)

  • 2d23bed server: Don't clear cmd when closing a server
  • f2999a8 runner.go: Handle truncation of tokens for stop sequences

📊 Changes

4 files changed (+64 additions, -35 deletions)

View changed files

📝 llama/runner/runner.go (+20 -7)
📝 llama/runner/stop.go (+6 -4)
📝 llama/runner/stop_test.go (+35 -23)
📝 llm/server.go (+3 -1)

📄 Description

When a single token contains both text to be return and a stop sequence, this causes an out of bounds error when we update the cache to match our text. This is because we currently assume that the removing the stop sequence will consume at least one token.

This also inverts the logic to deal with positive numbers, rather than a value to be subtracted, which is easier to reason about.


🔄 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/7158 **Author:** [@jessegross](https://github.com/jessegross) **Created:** 10/10/2024 **Status:** ✅ Merged **Merged:** 10/10/2024 **Merged by:** [@jessegross](https://github.com/jessegross) **Base:** `main` ← **Head:** `jessegross/bug7153` --- ### 📝 Commits (2) - [`2d23bed`](https://github.com/ollama/ollama/commit/2d23bede70299a51c627be0f045cdd0b12d62a13) server: Don't clear cmd when closing a server - [`f2999a8`](https://github.com/ollama/ollama/commit/f2999a822939633520facb5877b856242c49c9eb) runner.go: Handle truncation of tokens for stop sequences ### 📊 Changes **4 files changed** (+64 additions, -35 deletions) <details> <summary>View changed files</summary> 📝 `llama/runner/runner.go` (+20 -7) 📝 `llama/runner/stop.go` (+6 -4) 📝 `llama/runner/stop_test.go` (+35 -23) 📝 `llm/server.go` (+3 -1) </details> ### 📄 Description When a single token contains both text to be return and a stop sequence, this causes an out of bounds error when we update the cache to match our text. This is because we currently assume that the removing the stop sequence will consume at least one token. This also inverts the logic to deal with positive numbers, rather than a value to be subtracted, which is easier to reason about. --- <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-12 23:55:52 -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#12335