Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Add Qwen2.5 Coder model support to registry and chat templates (#4221)

Daniel Hanfa61ee46d729
diff --git a/tests/test_model_registry.py b/tests/test_model_registry.py
index 8552157620f..6c5aac52987 100644
--- a/tests/test_model_registry.py
+++ b/tests/test_model_registry.py
@@ -268,3 +268,13 @@ def test_unreachable_hub_skips_instead_of_reporting_missing(monkeypatch, make_er
monkeypatch.setattr(sys.modules[__name__], "HfApi", lambda: _FakeApi(error))
with pytest.raises(pytest.skip.Exception):
_test_model_uploaded(["unsloth/Qwen2.5-7B"])
+
+
+def test_qwen_2_5_coder_registered_without_dynamic_quants():
+ from unsloth.registry._qwen import Qwen_2_5_CoderMeta
+ from unsloth.registry.registry import _register_models
+
+ MODEL_REGISTRY.clear()
+ _register_models(Qwen_2_5_CoderMeta)
+ assert "unsloth/Qwen2.5-Coder-7B-Instruct-bnb-4bit" in MODEL_REGISTRY
+ assert not [k for k in MODEL_REGISTRY if "Coder" in k and k.endswith("unsloth-bnb-4bit")]
diff --git a/unsloth/chat_templates.py b/unsloth/chat_templates.py
index 83e4720e91b..7f9933ed96b 100644
--- a/unsloth/chat_templates.py
+++ b/unsloth/chat_templates.py
@@ -648,6 +648,19 @@ DEFAULT_SYSTEM_MESSAGE["qwen25"] = qwen25_default_system_message
CHAT_TEMPLATES["qwen2.5"] = (qwen25_template, qwen25_template_eos_token, False, qwen25_ollama,)
DEFAULT_SYSTEM_MESSAGE["qwen2.5"] = qwen25_default_system_message
+qwen25_coder_ollama = _ollama_template("qwen-25-coder")
+CHAT_TEMPLATES["qwen-2.5-coder"] = (qwen25_template, qwen25_template_eos_token, False, qwen25_coder_ollama,)
+DEFAULT_SYSTEM_MESSAGE["qwen-2.5-coder"] = qwen25_default_system_message
+
+CHAT_TEMPLATES["qwen-25-coder"] = (qwen25_template, qwen25_template_eos_token, False, qwen25_coder_ollama,)
+DEFAULT_SYSTEM_MESSAGE["qwen-25-coder"] = qwen25_default_system_message
+
+CHAT_TEMPLATES["qwen2.5-coder"] = (qwen25_template, qwen25_template_eos_token, False, qwen25_coder_ollama,)
+DEFAULT_SYSTEM_MESSAGE["qwen2.5-coder"] = qwen25_default_system_message
+
+CHAT_TEMPLATES["qwen25-coder"] = (qwen25_template, qwen25_template_eos_token, False, qwen25_coder_ollama,)
+DEFAULT_SYSTEM_MESSAGE["qwen25-coder"] = qwen25_default_system_message
+
# "{{ bos_token }}"\ # Phi-4 removes BOS?
# =========================================== Phi-4
phi4_template = \
diff --git a/unsloth/registry/REGISTRY.md b/unsloth/registry/REGISTRY.md
index a0b3d96cade..540572939c6 100644
--- a/unsloth/registry/REGISTRY.md
+++ b/unsloth/registry/REGISTRY.md
@@ -99,7 +99,7 @@ Prints the following (abridged) output:
- [x] MistralSmall
- [x] Qwen2.5
- [x] Qwen2.5-VL
- - [ ] Qwen2.5 Coder
+ - [x] Qwen2.5 Coder
- [x] QwenQwQ-32B
- [x] Deepseek v3
- [x] Deepseek R1
diff --git a/unsloth/registry/_qwen.py b/unsloth/registry/_qwen.py
index d754c633a96..31719cd95a1 100644
--- a/unsloth/registry/_qwen.py
+++ b/unsloth/registry/_qwen.py
@@ -3,6 +3,7 @@ from unsloth.registry.registry import ModelInfo, ModelMeta, QuantType, _register
_IS_QWEN_2_5_REGISTERED = False
_IS_QWEN_2_5_VL_REGISTERED = False
_IS_QWEN_QWQ_REGISTERED = False
+_IS_QWEN_2_5_CODER_REGISTERED = False
class QwenModelInfo(ModelInfo):
@@ -33,6 +34,13 @@ class QwenQVQPreviewModelInfo(ModelInfo):
return super().construct_model_name(base_name, version, size, quant_type, instruct_tag, key)
+class Qwen2_5CoderModelInfo(ModelInfo):
+ @classmethod
+ def construct_model_name(cls, base_name, version, size, quant_type, instruct_tag):
+ key = f"{base_name}{version}-Coder-{size}B"
+ return super().construct_model_name(base_name, version, size, quant_type, instruct_tag, key)
+
+
Qwen_2_5_Meta = ModelMeta(
org = "Qwen",
base_name = "Qwen",
@@ -78,6 +86,16 @@ QwenQVQPreviewMeta = ModelMeta(
is_multimodal = True,
quant_types = [QuantType.BNB],
)
+Qwen_2_5_CoderMeta = ModelMeta(
+ org = "Qwen",
+ base_name = "Qwen",
+ instruct_tags = [None, "Instruct"],
+ model_version = "2.5",
+ model_sizes = ["0.5", "1.5", "3", "7", "14", "32"],
+ model_info_cls = Qwen2_5CoderModelInfo,
+ is_multimodal = False,
+ quant_types = [QuantType.NONE, QuantType.BNB], # no *-unsloth-bnb-4bit Coder uploads exist
+)
def register_qwen_2_5_models(include_original_model: bool = False):
@@ -105,10 +123,19 @@ def register_qwen_qwq_models(include_original_model: bool = False):
_IS_QWEN_QWQ_REGISTERED = True
+def register_qwen_2_5_coder_models(include_original_model: bool = False):
+ global _IS_QWEN_2_5_CODER_REGISTERED
+ if _IS_QWEN_2_5_CODER_REGISTERED:
+ return
+ _register_models(Qwen_2_5_CoderMeta, include_original_model = include_original_model)
+ _IS_QWEN_2_5_CODER_REGISTERED = True
+
+
def register_qwen_models(include_original_model: bool = False):
register_qwen_2_5_models(include_original_model = include_original_model)
register_qwen_2_5_vl_models(include_original_model = include_original_model)
register_qwen_qwq_models(include_original_model = include_original_model)
+ register_qwen_2_5_coder_models(include_original_model = include_original_model)
if __name__ == "__main__":