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.

Make the registry's default quant_type usable (#9887)

Vineeth Sai Varikuntla11de7e72b554
diff --git a/tests/test_model_registry.py b/tests/test_model_registry.py
index 6c5aac52987..8277d2956d3 100644
--- a/tests/test_model_registry.py
+++ b/tests/test_model_registry.py
@@ -12,11 +12,17 @@ from huggingface_hub.errors import HfHubHTTPError, RepositoryNotFoundError
from unsloth.registry import register_models, search_models
from unsloth.registry._deepseek import register_deepseek_models
from unsloth.registry._gemma import register_gemma_models
-from unsloth.registry._llama import register_llama_models
+from unsloth.registry._llama import LlamaModelInfo, register_llama_models
from unsloth.registry._mistral import register_mistral_models
from unsloth.registry._phi import register_phi_models
from unsloth.registry._qwen import register_qwen_models
-from unsloth.registry.registry import MODEL_REGISTRY, QUANT_TAG_MAP, QuantType
+from unsloth.registry.registry import (
+ MODEL_REGISTRY,
+ QUANT_TAG_MAP,
+ ModelInfo,
+ QuantType,
+ register_model,
+)
MODEL_NAMES = [
"llama",
@@ -103,6 +109,35 @@ def test_all_model_registration():
assert not missing_models, f"Missing following models: {missing_models}"
+def test_unquantized_default_quant_type_is_usable():
+ assert ModelInfo.append_quant_type("Llama-3.1-8B") == "Llama-3.1-8B"
+ assert ModelInfo.append_quant_type("Llama-3.1-8B", None) == "Llama-3.1-8B"
+
+ assert ModelInfo.append_quant_type("Llama-3.1-8B", QuantType.NONE) == "Llama-3.1-8B"
+ assert (
+ ModelInfo.append_quant_type("Llama-3.1-8B", QuantType.BNB)
+ == "Llama-3.1-8B-" + QUANT_TAG_MAP[QuantType.BNB]
+ )
+
+ info = LlamaModelInfo(
+ org = "unsloth", base_name = "Llama", version = "3.1", size = 8, instruct_tag = "Instruct"
+ )
+ assert info.quant_type == QuantType.NONE
+ assert info.model_path == "unsloth/Llama-3.1-8B-Instruct"
+
+
+def test_register_model_defaults_to_no_quantization():
+ key = "unsloth/Llama-9.9-1B"
+ MODEL_REGISTRY.pop(key, None)
+ try:
+ register_model(LlamaModelInfo, org = "unsloth", base_name = "Llama", version = "9.9", size = 1)
+ assert key in MODEL_REGISTRY
+ assert MODEL_REGISTRY[key].quant_type == QuantType.NONE
+ assert key in [m.model_path for m in search_models(quant_types = [QuantType.NONE])]
+ finally:
+ MODEL_REGISTRY.pop(key, None)
+
+
def test_quant_type():
# NOTE: for org="unsloth" models, QuantType.NONE aliases QuantType.UNSLOTH
dynamic_quant_models = search_models(quant_types = [QuantType.UNSLOTH])
diff --git a/unsloth/registry/registry.py b/unsloth/registry/registry.py
index e853daf939c..143fbb8c472 100644
--- a/unsloth/registry/registry.py
+++ b/unsloth/registry/registry.py
@@ -44,6 +44,8 @@ class ModelInfo:
description: str = None
def __post_init__(self):
+ if self.quant_type is None:
+ self.quant_type = QuantType.NONE
self.name = self.name or self.construct_model_name(
self.base_name,
self.version,
@@ -60,7 +62,8 @@ class ModelInfo:
@staticmethod
def append_quant_type(key: str, quant_type: QuantType = None):
- if quant_type != QuantType.NONE:
+ # register_model passes the raw None default here, before __post_init__ normalizes it.
+ if quant_type is not None and quant_type != QuantType.NONE:
key = "-".join([key, QUANT_TAG_MAP[quant_type]])
return key