-
Notifications
You must be signed in to change notification settings - Fork 100
[Feature]Add Parser for Qwen3 think model #258
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @zyksir, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue with Qwen3 thinking models producing unwanted Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this 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 a new parser, Qwen3ThinkingParser, to handle Qwen3 thinking models, addressing an issue where unexpected <think> tags appeared when thinking was disabled. The changes include adding the new parser class, updating the preprocess_conversations function to use the new parser based on the chat_template.parser_type, and registering a new chat template named qwen3-thinking. The review focuses on ensuring the correctness and maintainability of the new parser and its integration.
| f"{self.chat_template.end_of_turn_token}<|im_start|>assistant\n" | ||
| ) | ||
| self.chat_template.ignored_token = "<think>\n\n</think>\n\n" | ||
| return super().parse(conversation, max_length, preformatted, **kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The super().parse method returns input_ids and loss_mask. However, the return type annotation Dict[str, List[torch.Tensor]] suggests a dictionary is expected. This discrepancy could lead to confusion or errors if the caller expects a dictionary. Consider updating the return type annotation or modifying the return statement to return a dictionary.
Suggestion:
return {"input_ids": input_ids, "loss_mask": loss_mask}Alternatively, update the return type annotation to Tuple[torch.Tensor, torch.Tensor] to match the actual return type.
| return super().parse(conversation, max_length, preformatted, **kwargs) | |
| return {"input_ids": input_ids, "loss_mask": loss_mask} |
| messages, tokenize=False, add_generation_prompt=False, **kwargs | ||
| ) | ||
|
|
||
| if self.chat_template.ignored_token: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a check to ensure self.chat_template.ignored_token is not None or empty before calling replace. This prevents potential errors if the token is not defined.
if self.chat_template.ignored_token and self.chat_template.ignored_token != "":
conversation = conversation.replace(self.chat_template.ignored_token, "")| if self.chat_template.ignored_token: | |
| if self.chat_template.ignored_token and self.chat_template.ignored_token != "": | |
| conversation = conversation.replace(self.chat_template.ignored_token, "") |
|
I think the implementation of adding an ignore_token is concise and reasonable. That's great! |
Motivation
In the previous PR (#182), @jiapingW discovered that for some Qwen3 thinking models, the output was not as expected — an unexpected
<think>\n\n</think>\n\nappeared when enable_thinking was set to False.This PR creates a new Parser for Qwen3 thinking models. For the non-thinking model(e.g
Qwen/Qwen3-30B-A3B-Instruct-2507), you can go with the oldqwenparser; while for the new thinking models likeQwen/Qwen3-30B-A3B, you can useqwen3-thinkingparser.Modifications
Related Issues
Accuracy Test
The following code is used for test.
This is the result:
Benchmark & Profiling
Checklist