[bugfix] fix qwen3_5 template#9279
Conversation
There was a problem hiding this comment.
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.
| elif role == 'assistant': | ||
| # HF applies `|trim` and re-wraps the <think>...</think> block with canonical newlines. | ||
| stripped = content.strip() | ||
| if '</think>' in stripped: |
There was a problem hiding this comment.
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.
| if '</think>' in stripped: | |
| if '</think>' in stripped and '<think>' in stripped: |
#9276