Skip to content

[bugfix] fix qwen3_5 template#9279

Merged
Jintao-Huang merged 2 commits into
modelscope:mainfrom
Jintao-Huang:fix_qwen3_5_template
May 7, 2026
Merged

[bugfix] fix qwen3_5 template#9279
Jintao-Huang merged 2 commits into
modelscope:mainfrom
Jintao-Huang:fix_qwen3_5_template

Conversation

@Jintao-Huang
Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the _swift_prepare_inputs method to the Qwen3_5Template class to ensure message content normalization aligns with Hugging Face's template rendering for Qwen3.5 and Qwen3.6. Specifically, it handles whitespace trimming for various roles and standardizes the formatting of reasoning blocks. A review comment suggests improving the robustness of the reasoning block parsing by ensuring both opening and closing tags are present before re-wrapping the content.

Comment thread swift/template/templates/qwen.py Outdated
elif role == 'assistant':
# HF applies `|trim` and re-wraps the <think>...</think> block with canonical newlines.
stripped = content.strip()
if '</think>' in stripped:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The current logic unconditionally adds a <think> tag if </think> is present, even if no <think> tag was opened. This could lead to malformed content if the model output is corrupted. It is safer to ensure both tags are present before attempting to re-wrap the reasoning block.

Suggested change
if '</think>' in stripped:
if '</think>' in stripped and '<think>' in stripped:

@Jintao-Huang Jintao-Huang merged commit e5cb8f1 into modelscope:main May 7, 2026
2 of 3 checks passed
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