-
Couldn't load subscription status.
- 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?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -84,6 +84,9 @@ def parse( | |||||
| messages, tokenize=False, add_generation_prompt=False, **kwargs | ||||||
| ) | ||||||
|
|
||||||
| if self.chat_template.ignored_token: | ||||||
| conversation = conversation.replace(self.chat_template.ignored_token, "") | ||||||
|
|
||||||
| if not self.tokenizer.pad_token_id: | ||||||
| self.tokenizer.pad_token_id = self.tokenizer.unk_token_id | ||||||
|
|
||||||
|
|
@@ -122,6 +125,29 @@ def parse( | |||||
| return input_ids, loss_mask | ||||||
|
|
||||||
|
|
||||||
| class Qwen3ThinkingParser(GeneralParser): | ||||||
| def __init__(self, tokenizer: PreTrainedTokenizer, chat_template: ChatTemplate): | ||||||
| super().__init__(tokenizer, chat_template) | ||||||
|
|
||||||
| def parse( | ||||||
| self, | ||||||
| conversation: "Conversation", | ||||||
| max_length: int, | ||||||
| preformatted: bool = False, | ||||||
| **kwargs, | ||||||
| ) -> Dict[str, List[torch.Tensor]]: | ||||||
| if kwargs.get("enable_thinking", False): | ||||||
| self.assistant_message_separator = ( | ||||||
| f"{self.chat_template.end_of_turn_token}<|im_start|>assistant\n<think>\n" | ||||||
| ) | ||||||
| self.chat_template.ignored_token = None | ||||||
| else: | ||||||
| self.assistant_message_separator = ( | ||||||
| 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 commentThe reason will be displayed to describe this comment to others. Learn more. The Suggestion: return {"input_ids": input_ids, "loss_mask": loss_mask}Alternatively, update the return type annotation to
Suggested change
|
||||||
|
|
||||||
| class HarmonyParser(Parser): | ||||||
|
|
||||||
| def build_single_turn_prompt( | ||||||
|
|
||||||
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_tokenis not None or empty before callingreplace. This prevents potential errors if the token is not defined.