[GH-ISSUE #4797] Stop token behavior changes when specifying list of stop tokens #28786

Closed
opened 2026-04-22 07:19:09 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @ccreutzi on GitHub (Jun 3, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/4797

Originally assigned to: @jmorganca on GitHub.

What is the issue?

Setting a stop token of "k=1 was" for this call has no effect, as expected:

$ curl -s http://localhost:11434/api/chat -d '{
>               "model": "mistral","options": {"top_k":1,"stop":["k=1 was"]},
>               "stream": false,
>               "messages":[{"role":"user","content":"Top-k sampling with k=1 returns a definite answer."}]
>             }' | jq .message.content
" Yes, that's correct! Top-k sampling with k=1 is also known as \"taking the top element\" or \"greedy selection.\" It simply selects the highest value (or any other sortable attribute) from a dataset without replacement. Since it only returns one item, it guarantees a definite answer. This method is often used in various machine learning and data analysis applications where you want to focus on the most significant or representative element of your dataset."

Setting a top token of "1" also has the expected effect, of ending after k= in the (constant) output:

$ curl -s http://localhost:11434/api/chat -d '{
>               "model": "mistral","options": {"top_k":1,"stop":["1"]},
>               "stream": false,
>               "messages":[{"role":"user","content":"Top-k sampling with k=1 returns a definite answer."}]
>             }' | jq .message.content
" Yes, that's correct! Top-k sampling with k="

But combining the two results in the generated text ending before the k= tokens:

$ curl -s http://localhost:11434/api/chat -d '{
>               "model": "mistral","options": {"top_k":1,"stop":["k=1 was","1"]},
>               "stream": false,
>               "messages":[{"role":"user","content":"Top-k sampling with k=1 returns a definite answer."}]
>             }' | jq .message.content
" Yes, that's correct! Top-k sampling with"

OS

macOS

GPU

Apple

CPU

Apple

Ollama version

0.1.38, installed with Homebrew

Originally created by @ccreutzi on GitHub (Jun 3, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/4797 Originally assigned to: @jmorganca on GitHub. ### What is the issue? Setting a stop token of `"k=1 was"` for this call has no effect, as expected: ``` $ curl -s http://localhost:11434/api/chat -d '{ > "model": "mistral","options": {"top_k":1,"stop":["k=1 was"]}, > "stream": false, > "messages":[{"role":"user","content":"Top-k sampling with k=1 returns a definite answer."}] > }' | jq .message.content " Yes, that's correct! Top-k sampling with k=1 is also known as \"taking the top element\" or \"greedy selection.\" It simply selects the highest value (or any other sortable attribute) from a dataset without replacement. Since it only returns one item, it guarantees a definite answer. This method is often used in various machine learning and data analysis applications where you want to focus on the most significant or representative element of your dataset." ``` Setting a top token of `"1"` also has the expected effect, of ending after `k=` in the (constant) output: ``` $ curl -s http://localhost:11434/api/chat -d '{ > "model": "mistral","options": {"top_k":1,"stop":["1"]}, > "stream": false, > "messages":[{"role":"user","content":"Top-k sampling with k=1 returns a definite answer."}] > }' | jq .message.content " Yes, that's correct! Top-k sampling with k=" ``` But combining the two results in the generated text ending before the `k=` tokens: ``` $ curl -s http://localhost:11434/api/chat -d '{ > "model": "mistral","options": {"top_k":1,"stop":["k=1 was","1"]}, > "stream": false, > "messages":[{"role":"user","content":"Top-k sampling with k=1 returns a definite answer."}] > }' | jq .message.content " Yes, that's correct! Top-k sampling with" ``` ### OS macOS ### GPU Apple ### CPU Apple ### Ollama version 0.1.38, installed with Homebrew
GiteaMirror added the bugapi labels 2026-04-22 07:19:09 -05:00
Author
Owner

@jmorganca commented on GitHub (Nov 12, 2024):

Hi there, this should be fixed now. Thanks for the issue!

<!-- gh-comment-id:2469414298 --> @jmorganca commented on GitHub (Nov 12, 2024): Hi there, this should be fixed now. Thanks for the issue!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#28786