-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Add Qwen-3 chat template and Ollama template support #2537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@davedgd and @shimmyshimmer Just tagging you guys since I'm not sure if you get a notification from the issue itself. |
Thank you @kiankyars — much appreciated! |
|
Hey @kiankyars , thanks for this. I understand if ollama_template is included as it might not be easily accessible. |
You raise a good point. The qwen3_template is included mostly to ensure consistency with other templates. in chat_templates.py |
|
@kiankyars: There seems to be issue with the qwen-3 template that was added. Specifically, it reliably produces the following error: TemplateSyntaxError: expected token 'end of print statement', got 'name'I've created a minimal example here that works with qwen-2.5 but fails with qwen-3: from unsloth import FastLanguageModel
from unsloth.chat_templates import get_chat_template
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "unsloth/Qwen3-0.6B-unsloth-bnb-4bit",
max_seq_length = 8192,
load_in_4bit = True,
)
tokenizer = get_chat_template(
tokenizer,
chat_template = "qwen-3", # works with qwen-2.5 but not qwen-3
)
messages = [{"role": "system", "content": "You are an expert assistant."},
{"role": "user", "content": "Say Hello!"},
{"role": "assistant", "content": "Hello!"}]
inputs = tokenizer.apply_chat_template(messages,
tokenize = False,
add_generation_prompt = False)
print(inputs)With However, with TemplateSyntaxError: expected token 'end of print statement', got 'name' |
@davedgd oh great point! would you like to add a PR so I can accept it! Thank you :) |
@shimmyshimmer: Done! :) I traced down the issue to a couple of missing escapes on the double quotes. Seems to work fine with the patch in place: |
Thanks for pointing that out! I gotta figure out how my tests did not reveal that. |
This pull request is in regards to GH-2521.
I have added the templates for both qwen3 and qwen3 ollama.
Please let me know if there's anything else to add since I'd like to use these templates ASAP.