Skip to content

Add training chat template for Qwen3-2507#5574

Merged
qgallouedec merged 9 commits into
huggingface:mainfrom
SwayamInSync:qwen3_2507
May 5, 2026
Merged

Add training chat template for Qwen3-2507#5574
qgallouedec merged 9 commits into
huggingface:mainfrom
SwayamInSync:qwen3_2507

Conversation

@SwayamInSync

@SwayamInSync SwayamInSync commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Models like Qwen3-4B-Instruct-2507 ship a chat template that is simpler than the standard Qwen3 template, it has no reasoning_content handling, no <think> block parsing, no multi_step_tool tracking, and no enable_thinking flag. Because get_training_chat_template uses exact string matching, this template variant falls through and raises:

ValueError: The tokenizer's chat template is not training-compatible ...

This PR adds the qwen3_instruct_2507 base and training templates (with {% generation %} / {% endgeneration %} markers) and wires them into get_training_chat_template and add_response_schema.

Follows up on #5470.

cc: @qgallouedec


Note

Low Risk
Low risk: adds support for an additional Qwen3 template variant and updates exact-match routing/tests, with changes largely isolated to template selection and response parsing for that model family.

Overview
Adds first-class support for the Qwen3-*-Instruct-2507 chat-template variant by introducing new base and training Jinja templates, including {% generation %} / {% endgeneration %} markers for assistant_only_loss masking.

Wires this variant into get_training_chat_template and add_response_schema via exact template matching, expands the docs to list the new supported family/template, and extends the chat-template utility tests to cover the new tokenizer (including skipping reasoning_content parsing where unsupported).

Reviewed by Cursor Bugbot for commit 8cdbd28. Bugbot is set up for automated code reviews on this repo. Configure here.

@qgallouedec

Copy link
Copy Markdown
Member

Can you add tests using trl-internal-testing/tiny-Qwen3ForCausalLM-Instruct-2507 (see #5586)

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7b6bdb5. Configure here.

Comment thread tests/test_chat_template_utils.py Outdated
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@qgallouedec qgallouedec left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just waiting for #5586 to be merged

@qgallouedec qgallouedec merged commit e5677da into huggingface:main May 5, 2026
12 checks passed
@aazizyan aazizyan mentioned this pull request May 7, 2026
8 tasks
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.

3 participants