Skip to content

Add Qwen3 Instruct / Thinking chat templates - #3110

Merged
shimmyshimmer merged 1 commit into
unslothai:mainfrom
Etherll:qwen3-chat-template
Aug 8, 2025
Merged

shimmyshimmer merged 1 commit into
unslothai:mainfrom
Etherll:qwen3-chat-template

Conversation

@Etherll

@Etherll Etherll commented Aug 7, 2025

Copy link
Copy Markdown
Collaborator

Seems like the chat template for Qwen3-Instruct always add <think>\n\n</think> when doing tokenizer.apply_chat_template which is weird and shouldn't happen, so i did some modifications to it

--- old/chat_template
+++ new/chat_template
@@ -1,5 +1,5 @@
 {%- if loop.index0 > ns.last_query_index %}
-    {%- if loop.last or (not loop.last and reasoning_content) %}
+    {%- if reasoning_content %}
         {{- '<|im_start|>' + message.role + '\\n<think>\\n' + reasoning_content.strip('\\n') + '\\n</think>\\n\\n' + content.lstrip('\\n') }}
     {%- else %}
         {{- '<|im_start|>' + message.role + '\\n' + content }}

How to use:

from unsloth.chat_templates import get_chat_template
tokenizer = get_chat_template(
    tokenizer,
    chat_template = "qwen3-instruct", # or qwen3-thinking
)

add qwen3-instruct/thinking-chat-template
@shimmyshimmer
shimmyshimmer merged commit 67e4fa5 into unslothai:main Aug 8, 2025
abiswas-realadvice pushed a commit to abiswas-realadvice/unsloth that referenced this pull request May 14, 2026
Add Qwen3 Instruct / Thinking chat templates
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