dutifulbob commited on
Commit
0af3e9e
·
verified ·
1 Parent(s): ba74f5b

Fix empty thought channel in Gemma 4 chat template

Browse files

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:

```text
<|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:

```text
<|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.

Files changed (1) hide show
  1. chat_template.jinja +0 -3
chat_template.jinja CHANGED
@@ -347,8 +347,5 @@
347
  {%- if add_generation_prompt -%}
348
  {%- if ns.prev_message_type != 'tool_response' and ns.prev_message_type != 'tool_call' -%}
349
  {{- '<|turn>model\n' -}}
350
- {%- if not enable_thinking | default(false) -%}
351
- {{- '<|channel>thought\n<channel|>' -}}
352
- {%- endif -%}
353
  {%- endif -%}
354
  {%- endif -%}
 
347
  {%- if add_generation_prompt -%}
348
  {%- if ns.prev_message_type != 'tool_response' and ns.prev_message_type != 'tool_call' -%}
349
  {{- '<|turn>model\n' -}}
 
 
 
350
  {%- endif -%}
351
  {%- endif -%}