Improved and fixed template for GPT-OSS (again). Includes preserve_thinking and fix for Unsloth-induced bug
Mirrored from r/LocalLLaMA for archival readability. Support the source by reading on the original site.
I posted an updated GPT-OSS template a couple of months ago, which was based on Unsloth's version.
It turns out that both Unsloth's version (and, thus, mine) contain a very serious bug that can degrade the model when chat history is replayed and contains previous reasoning (aka the analysis channel) turns. As far as I can tell, retaining this history is pretty much the default for a lot of tools now and definitely can happen at the API level - tools can consolidate reasoning and answer.
Can you spot the problem in this snippet from the message rendering loop? (Taken from Unsloth's template):
jinja {%- elif "thinking" in message %} {#- CoT is dropped during all previous turns, so we never render it for inference #} {{- "<|start|>assistant<|channel|>analysis<|message|>" + message.thinking + "<|end|>" }} {%- set last_tool_call.name = none %} {%- else %} {#- CoT is dropped during all previous turns, so we never render it for inference #} {{- "<|start|>assistant<|channel|>final<|message|>" + message.content + "<|end|>" }} {%- set last_tool_call.name = none %}
When chat history is rendered, in cases where a message contains both content (the model's answer) and thinking (reasoning), only the reasoning is rendered for the model, while the answer itself is dropped! That can significantly confuse the model across turns.
The comment is also wrong—the whole branch looks like a copy-paste error. OpenAI's reference template does not have it.
I noticed that in some cases GPT-OSS 20B could go completely off the rails, and now I see why. Interestingly, GPT-OSS 120B seems smart enough to recover the context and direction of the conversation using only the reasoning traces.
After this experience, I implemented preserve_thinking in my template as well, because the model handles it just fine without losing coherence. This should make multi-turn inference faster in harnesses (via prefix caching) at the expense of higher token usage.
So there you have it: https://huggingface.co/arbv/gpt-oss-fixed-jinja-template
Give GPT-OSS a second chance if you are bored.
Noticed by pure chance while working on a fixed template for Laguna XS/S 2.1, but more on that another day.
P.S.
Casting u/danielhanchen to take a look, too.
[link] [comments]
More from r/LocalLLaMA
-
NVIDIA shipped OpenShell, an open source sandbox that gives local and open agents real runtime limits instead of prompt rules. Over 100 firms joined the safety stack. OpenAI did not.
Sep 28
-
3090 for $1500???
Sep 28
-
modified qwen 3.8 27b modifies windows credential dumper to bypass EDR detection
Sep 28
-
Minisforum MS-S1 MAX-P495 @ €7.799,00
Sep 28
Discussion (0)
Sign in to join the discussion. Free account, 30 seconds — email code or GitHub.
Sign in →No comments yet. Sign in and be the first to say something.