-
Notifications
You must be signed in to change notification settings - Fork 40
Add support for Qwen3-4B-Instruct and add model-template mappings #85
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 all commits
795c156
33e1251
b3f4492
c445ff1
bc26dea
45bfb7b
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 | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||||||||||||||||||||||||||
| from dataclasses import dataclass | ||||||||||||||||||||||||||||||||||
| from typing import Dict | ||||||||||||||||||||||||||||||||||
| from constant import MODEL_TEMPLATE_MAP | ||||||||||||||||||||||||||||||||||
|
Contributor
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. 🛠️ Refactor suggestion Use package-relative import to avoid import errors with src/ layout. Direct -from constant import MODEL_TEMPLATE_MAP
+try:
+ from .constant import MODEL_TEMPLATE_MAP # package-relative
+except ImportError: # pragma: no cover
+ from constant import MODEL_TEMPLATE_MAP # fallback for direct execution📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @dataclass | ||||||||||||||||||||||||||||||||||
|
|
@@ -67,6 +68,25 @@ def register_template( | |||||||||||||||||||||||||||||||||
| stop_word="<|im_end|>", | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| register_template( | ||||||||||||||||||||||||||||||||||
| template_name="qwen3", | ||||||||||||||||||||||||||||||||||
| system_format="<|im_start|>system\n{content}<|im_end|>\n", | ||||||||||||||||||||||||||||||||||
| user_format="<|im_start|>user\n{content}<|im_end|>\n<|im_start|>assistant\n", | ||||||||||||||||||||||||||||||||||
| assistant_format="{content}<|im_end|>\n", | ||||||||||||||||||||||||||||||||||
| tool_format=( | ||||||||||||||||||||||||||||||||||
| "# Tools\n\n" | ||||||||||||||||||||||||||||||||||
| "You may call one or more functions to assist with the user query.\n\n" | ||||||||||||||||||||||||||||||||||
| "You are provided with function signatures within <tools></tools> XML tags:\n" | ||||||||||||||||||||||||||||||||||
| "<tools>\n{content}\n</tools>\n\n" | ||||||||||||||||||||||||||||||||||
| "For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n" | ||||||||||||||||||||||||||||||||||
| '<tool_call>\n{"name": <function-name>, "arguments": <args-json-object>}\n</tool_call>' | ||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||
| function_format="<tool_call>\n{content}\n</tool_call><|im_end|>\n", | ||||||||||||||||||||||||||||||||||
| observation_format="<|im_start|>user\n<tool_response>\n{content}\n</tool_response><|im_end|>\n<|im_start|>assistant\n", | ||||||||||||||||||||||||||||||||||
| system="You are a helpful assistant.", | ||||||||||||||||||||||||||||||||||
| stop_word="<|im_end|>", | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| register_template( | ||||||||||||||||||||||||||||||||||
| template_name="yi", | ||||||||||||||||||||||||||||||||||
| system_format="<|im_start|>system\n{content}<|im_end|>\n", | ||||||||||||||||||||||||||||||||||
|
|
@@ -182,3 +202,6 @@ def register_template( | |||||||||||||||||||||||||||||||||
| system=None, | ||||||||||||||||||||||||||||||||||
| stop_word="<|end|>", | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| for model_name, template_name in MODEL_TEMPLATE_MAP.items(): | ||||||||||||||||||||||||||||||||||
| template_dict[model_name] = template_dict[template_name] | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+206
to
+207
Contributor
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. 🛠️ Refactor suggestion Copy and validate when aliasing templates to avoid KeyError and shared-state bugs.
-for model_name, template_name in MODEL_TEMPLATE_MAP.items():
- template_dict[model_name] = template_dict[template_name]
+missing = []
+for model_name, template_name in MODEL_TEMPLATE_MAP.items():
+ base = template_dict.get(template_name)
+ if base is None:
+ missing.append((model_name, template_name))
+ continue
+ # copy to avoid shared object between aliases
+ template_dict[model_name] = replace(base)
+if missing:
+ raise KeyError(f"MODEL_TEMPLATE_MAP points to unknown template(s): {missing}")Add import (outside the changed hunk) to support replace: -from dataclasses import dataclass
+from dataclasses import dataclass, replace📝 Committable suggestion
Suggested change
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||
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.
🧩 Analysis chain
Add an upper bound to transformers to prevent future major‑version breakage.
Guard against a v5 jump changing APIs.
Apply:
Also, verify 4.51.x remains compatible with your pinned Torch (torch>=1.13.1) and accelerate (>=0.27.2); Transformers’ optional PyTorch features may expect newer Torch.
🌐 Web query:
💡 Result:
Short answer: Transformers 4.51.x requires Python >= 3.9 and is intended to be used with PyTorch 2.0 or newer (i.e., PyTorch 2.0+). [1][2]
Sources:
Add upper bound to transformers and resolve PyTorch/Python compatibility
Apply:
📝 Committable suggestion
🤖 Prompt for AI Agents