fix: patch chat_template to remove think tags at the source#250
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_templateandprocessor.tokenizer.chat_templateto remove<think>/</think>from the Jinja template itself. No code path can re-insert thinking mode after this.Three layers of protection:
enable_thinking=Falsekwarg (if processor supports it)<think>and</think>in rendered output)🤖 Generated with Claude Code