Skip to content

fix: patch chat_template to remove think tags at the source#250

Merged
abrichr merged 1 commit into
mainfrom
fix/strip-think-from-chat-template
Mar 29, 2026
Merged

fix: patch chat_template to remove think tags at the source#250
abrichr merged 1 commit into
mainfrom
fix/strip-think-from-chat-template

Conversation

@abrichr
Copy link
Copy Markdown
Member

@abrichr abrichr commented Mar 29, 2026

Summary

#249 stripped <think> from the rendered text, but </think> was missed AND TRL/processor can re-apply the template, re-inserting the tags.

Fix: On first rollout call, patch processor.chat_template and processor.tokenizer.chat_template to remove <think>/</think> from the Jinja template itself. No code path can re-insert thinking mode after this.

Three layers of protection:

  1. enable_thinking=False kwarg (if processor supports it)
  2. Template-level patch (removes tags from the Jinja source)
  3. Text-level strip (catches both <think> and </think> in rendered output)

🤖 Generated with Claude Code

Stripping <think> from rendered text was insufficient — TRL or the
processor may re-apply the template, re-inserting the tags. The fix:
patch processor.chat_template and processor.tokenizer.chat_template
on first rollout call, removing <think>/<think> from the Jinja
template itself. This ensures no code path can re-insert thinking mode.

Also strips </think> (was missed in #249).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@abrichr abrichr merged commit c1d3588 into main Mar 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant