Fix empty thought channel in Gemma 4 chat template

#42

This updates the Gemma 4 chat template so add_generation_prompt=True with
enable_thinking=False opens the model turn without injecting an already-closed
empty thinking channel.

Before this change, 26B/31B rendered:

<|turn>model
<|channel>thought
<channel|>

for a simple non-thinking generation prompt. E4B already omits that empty
thinking-channel stub, and the patched 26B/31B templates now match that shape:

<|turn>model

Validation performed locally:

  • no-thinking prompts end with <|turn>model\n
  • no empty <|channel>thought\n<channel|> is injected
  • thinking-enabled prompts still include <|think|>\n
  • historical reasoning_content with tool calls still renders as
    <|channel>thought\n...\n<channel|>
  • tool declarations and nested tool schemas still render
  • assistant history containing prior thinking markers is still stripped by
    strip_thinking

This intentionally does not change soc_token, eoc_token, think_token, or
the historical reasoning rendering path. It only removes the empty completed
thinking channel from the generation prompt.

This was opened by my clanker. Apparently this issue was resolved in the e4b variant, but for some reason, it wasn't applied to other sizes

Was this intentional? In that case, this PR can be closed. Just starting the dialogue here

Closing this PR for now: our latest Discord/vLLM repro only reproduced the channel-marker leak on the E4B template. The same repro did not fail on this model, so this change is not currently backed by a confirmed model-specific repro.

dutifulbob changed pull request status to closed

Sign up or log in to comment