google-deepmind / google-deepmind/gemma
gemma-4-12B-it: Infinite thinking loop, system prompt non-adherence (>10k tokens), and context loss in multi-turn conversations
- Dominant language
- Python
- Stars
- 5.7k
- Forks
- 1k
- Avg merge
- 10h 33m
- Merged PRs (30d)
- 2
Description
## Bug Report + Improvement Request
### Model
`google/gemma-4-12B-it` (original, non-fine-tuned)
### Runtime
llama.cpp / LM Studio (local inference)
---
## Issue 1 — Infinite thinking loop (no exit condition)
The model frequently enters an infinite loop inside the `<|channel>thought ... ` reasoning block and never terminates generation. The only way to recover is to manually stop generation.
This has been independently confirmed by multiple users running the model locally via llama.cpp and Ollama:
- https://discuss.ai.google.dev/t/gemma4-how-to-prevent-looping-output-in-thinking/173205
**Partial workaround found by the community:** increasing `repeat-penalty` to `1.08` with `repeat-last-n 4096` reduces — but does not eliminate — the issue.
---
## Issue 2 — Complex system prompts (>10,000 tokens) cause unreliable behavior
When a system prompt exceeds ~10,000 tokens, the model exhibits several failure modes:
- Extremely long time spent "reading" the system prompt before producing any output
- Contradicts or ignores rules explicitly stated in the system prompt
- Does not know what to do next after processing the instructions, producing confused or empty responses
- Mixes up steps, skips required actions, or applies rules from one context to another incorrectly
This makes the model unreliable for complex agentic workflows, roleplay frameworks with detailed character cards, or any use case requiring strict instruction-following over a long system prompt.
---
## Issue 3 — Conversation context loss in multi-turn sessions
In longer conversations, the model progressively loses track of:
- Instructions given in the system prompt (behaves as if it never read them after a few turns)
- Content discussed in earlier turns of the conversation
- The current state or "thread" of the dialogue
This is distinct from simply running out of context window — it appears to be a failure of attention over the full sequence even when the content is still within the model's context length.
---
## Expected Behavior
- The thinking channel should always terminate and produce a coherent final response
- Rules and steps defined in the system prompt should be followed consistently regardless of prompt length
- The model should maintain coherent reference to prior conversation turns throughout the session
## Suggested Improvements
- Add a maximum thinking budget / token limit for the reasoning channel to prevent runaway loops
- Improve instruction following for system prompts in the 5,000–15,000 token range
- Investigate attention degradation over long multi-turn contexts and consider fine-tuning on longer conversation datasets
---
## Environment
- Model: `google/gemma-4-12B-it`
- Backend: llama.cpp (also reproducible with Ollama)
- Hardware: Local GPU inference
- Quantization: Q4 to Q8 variants (issue present across quantization levels)
Contributor guide
Research direction
Start by reproducing the reported behavior with google/gemma-4-12B-it through llama.cpp or Ollama, using the described long system prompts and multi-turn sessions. Compare the reported looping, instruction-following, and context-loss behavior across the stated Q4–Q8 variants; done requires a confirmed, scoped failure and an agreed implementation path.
Written by the indexing model from the issue text.
Assessment
- Domain
- ai, machine-learning
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100