Skip to content

Close the CoT block a chat template opens - #514

Open
benthecarman wants to merge 1 commit into
p-e-w:masterfrom
benthecarman:fix-template-cot-prefix
Open

benthecarman wants to merge 1 commit into
p-e-w:masterfrom
benthecarman:fix-template-cot-prefix

Conversation

@benthecarman

Copy link
Copy Markdown
Contributor

When the chat template already ends the prompt with the CoT initializer, as Qwen3.5 does with thinking enabled, the full closed block was appended after it, so the model saw a nested block: "<think>\n<think></think>". Append only the rest of the closed block. Templates that don't insert the initializer (Qwen3, gpt-oss, GLM)

AI use declaration

Check either of the following:

  • I wrote the code in this PR entirely by myself.
  • I used AI to write some or all of the code in this PR, and I have reviewed the entire code myself
    and fully understand it. I'm prepared to discuss the code without letting an agent speak on my behalf.

When the chat template already ends the prompt with the Chain-of-Thought
initializer, as Qwen3.5 does with thinking enabled, the full closed
block was appended after it, so the model saw a nested block:
"<think>\n<think></think>". Append only the rest of the closed block.
@benthecarman
benthecarman force-pushed the fix-template-cot-prefix branch from 8087f83 to b007f3e Compare October 22, 2026 05:46
@p-e-w

p-e-w commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Hey, I think you caught a major bug here!

However, it's not quite so easy to fix, because the template might actually insert the complete CoT block (e.g. when it defaults to disabling thinking).

@Vinay-Umrethe Could you take a look, since you implemented #423? What is the best way forward here?

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.

2 participants