[GH-ISSUE #10159] gemma3:27b gets stuck into generating the same token and producing useless gibberish output #53178

Open
opened 2026-04-29 02:15:29 -05:00 by GiteaMirror · 10 comments
Owner

Originally created by @rossbg on GitHub (Apr 7, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/10159

What is the issue?

I am using gemma3:27b with prompts with varying length - from 1k to 10k tokens

Sometimes the model starts producing a normal answer then gets stuck into generating the same token over and over again. It only stops when num_predict is reached (1024 in my case). I noticed that it's happening more often when the context is bigger (above 2k tokens)

There's nothing strange in the logs during generation times.

it's the gemma3 unsloth version with their default generation params in the .Modelfile

top_k             64                 
top_p             0.95                            
temperature       1                  
min_p             0.01               
repeat_penalty    1       

but it was happening with the original gemma3:27 as well with ollama defaults for these params.

Right now I am on 0.6.4 but it was also happening on 0.6.3 and 0.6.2.

The following params are part of the model launch:

--ctx-size 98304
--batch-size 512
--n-gpu-layers 63
--threads 32
--flash-attn
--parallel 6

Full log after launch until it gets stuck

ollama_repeat_log.txt

Relevant log output


OS

Linux

GPU

Nvidia

CPU

No response

Ollama version

0.6.4

Originally created by @rossbg on GitHub (Apr 7, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/10159 ### What is the issue? I am using gemma3:27b with prompts with varying length - from 1k to 10k tokens Sometimes the model starts producing a normal answer then gets stuck into generating the same token over and over again. It only stops when num_predict is reached (1024 in my case). I noticed that it's happening more often when the context is bigger (above 2k tokens) There's nothing strange in the logs during generation times. it's the gemma3 unsloth version with their default generation params in the .Modelfile top_k 64 top_p 0.95 temperature 1 min_p 0.01 repeat_penalty 1 but it was happening with the original gemma3:27 as well with ollama defaults for these params. Right now I am on 0.6.4 but it was also happening on 0.6.3 and 0.6.2. The following params are part of the model launch: --ctx-size 98304 --batch-size 512 --n-gpu-layers 63 --threads 32 --flash-attn --parallel 6 Full log after launch until it gets stuck [ollama_repeat_log.txt](https://github.com/user-attachments/files/19628263/ollama_repeat_log.txt) ### Relevant log output ```shell ``` ### OS Linux ### GPU Nvidia ### CPU _No response_ ### Ollama version 0.6.4
GiteaMirror added the bug label 2026-04-29 02:15:29 -05:00
Author
Owner

@pelegel commented on GitHub (Apr 8, 2025):

i am experiencing the same issue

<!-- gh-comment-id:2786670576 --> @pelegel commented on GitHub (Apr 8, 2025): i am experiencing the same issue
Author
Owner

@igorschlum commented on GitHub (Apr 9, 2025):

Hi @rossbg @pelegel

Hi,

Thanks for the detailed report — and for including the generation parameters and logs, that’s really helpful.

First, just to clarify: there have been a silent update to the gemma3 models, which may affect behavior and generation quality. So before diving deeper, it’s worth making sure you’re running the latest version of the model (ollama pull gemma3:27b if you haven’t done that recently).

Regarding the issue you’re describing — the model getting stuck repeating the same token especially with longer prompts — this can sometimes happen due to a combination of factors:
• Context length stress (when approaching or exceeding 2k–4k tokens),
• Repeat penalty being too low for that context size,
• Or possible edge cases introduced in model fine-tuning.

To better reproduce and investigate this, would you be able to share:
• A specific example prompt (or a range of them) that consistently triggers the problem?
• A minimal script or call to Ollama that leads to the repetition behavior?

That way, others in the community or the dev team can try to replicate and narrow down the issue more precisely.

<!-- gh-comment-id:2788318402 --> @igorschlum commented on GitHub (Apr 9, 2025): Hi @rossbg @pelegel Hi, Thanks for the detailed report — and for including the generation parameters and logs, that’s really helpful. First, just to clarify: there have been a silent update to the gemma3 models, which may affect behavior and generation quality. So before diving deeper, it’s worth making sure you’re running the latest version of the model (ollama pull gemma3:27b if you haven’t done that recently). Regarding the issue you’re describing — the model getting stuck repeating the same token especially with longer prompts — this can sometimes happen due to a combination of factors: • Context length stress (when approaching or exceeding 2k–4k tokens), • Repeat penalty being too low for that context size, • Or possible edge cases introduced in model fine-tuning. To better reproduce and investigate this, would you be able to share: • A specific example prompt (or a range of them) that consistently triggers the problem? • A minimal script or call to Ollama that leads to the repetition behavior? That way, others in the community or the dev team can try to replicate and narrow down the issue more precisely.
Author
Owner

@pelegel commented on GitHub (Apr 9, 2025):

Thanks for the answer. I would love a clarification: Gemma3 context length is 128K tokens, so why is this problem happens when reaching only a smaller percentage of it? (2k-4k)

<!-- gh-comment-id:2788400593 --> @pelegel commented on GitHub (Apr 9, 2025): Thanks for the answer. I would love a clarification: Gemma3 context length is 128K tokens, so why is this problem happens when reaching only a smaller percentage of it? (2k-4k)
Author
Owner

@igorschlum commented on GitHub (Apr 9, 2025):

@pelegel did you pull again the gemma3 model you are using?

<!-- gh-comment-id:2791180174 --> @igorschlum commented on GitHub (Apr 9, 2025): @pelegel did you pull again the gemma3 model you are using?
Author
Owner

@pelegel commented on GitHub (Apr 10, 2025):

@igorschlum yes. It’s mainly happens with prompt in languages other than English. By the way, it also happens with llama 3.3, qwq etc. Adjusting num_predict and num_ctx didn't solved the problem.

<!-- gh-comment-id:2791582742 --> @pelegel commented on GitHub (Apr 10, 2025): @igorschlum yes. It’s mainly happens with prompt in languages other than English. By the way, it also happens with llama 3.3, qwq etc. Adjusting num_predict and num_ctx didn't solved the problem.
Author
Owner

@igorschlum commented on GitHub (Apr 20, 2025):

@pelegel there is a new version of Ollama in préparation. Hoping the issue will be addressed.

<!-- gh-comment-id:2817169980 --> @igorschlum commented on GitHub (Apr 20, 2025): @pelegel there is a new version of Ollama in préparation. Hoping the issue will be addressed.
Author
Owner

@Zhenyettta commented on GitHub (May 2, 2025):

+1

<!-- gh-comment-id:2847557401 --> @Zhenyettta commented on GitHub (May 2, 2025): +1
Author
Owner

@bitsydarel commented on GitHub (May 12, 2025):

+1

<!-- gh-comment-id:2870556231 --> @bitsydarel commented on GitHub (May 12, 2025): +1
Author
Owner

@Jannik-Hoffmann commented on GitHub (Sep 1, 2025):

As far as I am concerned, gemma3:27b remains systematically broken. For me it is still producing occassional gibberish in a tightly controlled data parsing pipeline.

<!-- gh-comment-id:3242607916 --> @Jannik-Hoffmann commented on GitHub (Sep 1, 2025): As far as I am concerned, gemma3:27b remains systematically broken. For me it is still producing occassional gibberish in a tightly controlled data parsing pipeline.
Author
Owner

@Rabcor commented on GitHub (Jan 8, 2026):

Still broken for me too. Updated 1 month ago, but still it goes:

Image

Same for 12b:

Image

Whatever new version was being discussed back in april clearly fixed nothing.

Edit: I was able to use the abliterated version of gemma3:27b.

<!-- gh-comment-id:3725223093 --> @Rabcor commented on GitHub (Jan 8, 2026): Still broken for me too. Updated 1 month ago, but still it goes: <details> <img width="841" height="1276" alt="Image" src="https://github.com/user-attachments/assets/dadaecd1-71e3-4b1c-a9ed-fe059c75e020" /> </details> Same for 12b: <details> <img width="991" height="703" alt="Image" src="https://github.com/user-attachments/assets/8060a5a8-a1e0-4922-8655-af88472c2de5" /> </details> Whatever new version was being discussed back in april clearly fixed nothing. Edit: I was able to use the abliterated version of gemma3:27b.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#53178