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.

Fix packed and grouped Q2 GGUF variant detection (#7033)

Lee Jackson46588f341fe2
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py
index de10ecb908d..55643f02562 100644
--- a/studio/backend/core/inference/llama_cpp.py
+++ b/studio/backend/core/inference/llama_cpp.py
@@ -3098,9 +3098,9 @@ _GGUF_KNOWN_QUANT_RE = re.compile(
r"(UD-)?"
r"(MXFP[0-9]+(?:_[A-Z0-9]+)*"
r"|IQ[0-9]+_[A-Z]+(?:_[A-Z0-9]+)?"
- r"|TQ[0-9]+_[0-9]+"
+ r"|P?TQ[0-9]+_[0-9]+"
r"|Q[0-9]+_K_[A-Z]+"
- r"|Q[0-9]+_[0-9]+"
+ r"|P?Q[0-9]+_[0-9]+(?:_G[0-9]+)?"
r"|Q[0-9]+_K"
r"|BF16|F16|F32)",
re.IGNORECASE,
diff --git a/studio/backend/hub/services/models/gguf_variants.py b/studio/backend/hub/services/models/gguf_variants.py
index 0dc6dc5fcbd..62e5bfc551f 100644
--- a/studio/backend/hub/services/models/gguf_variants.py
+++ b/studio/backend/hub/services/models/gguf_variants.py
@@ -844,9 +844,9 @@ _KNOWN_QUANT_RE = re.compile(
r"(UD-)?"
r"(MXFP[0-9]+(?:_[A-Z0-9]+)*"
r"|IQ[0-9]+_[A-Z]+(?:_[A-Z0-9]+)?"
- r"|TQ[0-9]+_[0-9]+"
+ r"|P?TQ[0-9]+_[0-9]+"
r"|Q[0-9]+_K_[A-Z]+"
- r"|Q[0-9]+_[0-9]+"
+ r"|P?Q[0-9]+_[0-9]+(?:_G[0-9]+)?"
r"|Q[0-9]+_K"
r"|BF16|F16|F32)"
r"(-[0-9]+(?:\.[0-9]+)?bpw)?",
diff --git a/studio/backend/hub/tests/test_model_services.py b/studio/backend/hub/tests/test_model_services.py
index f946fa09188..6504c6bfa0f 100644
--- a/studio/backend/hub/tests/test_model_services.py
+++ b/studio/backend/hub/tests/test_model_services.py
@@ -427,6 +427,12 @@ class TestExtractQuantToken:
def test_ud_prefix_preserved(self):
assert gguf.extract_quant_token("Foo-BF16-UD-Q4_K_XL.gguf") == "UD-Q4_K_XL"
+ def test_packed_and_grouped_quant_variants_do_not_collapse(self):
+ assert gguf.extract_quant_token("Ternary-Bonsai-1.7B-PQ2_0.gguf") == "PQ2_0"
+ assert gguf.extract_quant_token("Ternary-Bonsai-1.7B-Q2_0.gguf") == "Q2_0"
+ assert gguf.extract_quant_token("Ternary-Bonsai-1.7B-Q2_0_g64.gguf") == "Q2_0_g64"
+ assert gguf.extract_quant_token("Ternary-Bonsai-2-27B-PTQ1_0.gguf") == "PTQ1_0"
+
def test_precision_infix_variants_do_not_collapse(self):
labels = {
gguf.extract_quant_label("Foo-BF16-Q4_K_M.gguf"),
@@ -2691,6 +2697,21 @@ def test_gguf_variant_requirements_include_split_files_and_preferred_mmproj():
)
+def test_gguf_variant_requirements_keep_packed_q2_files_separate():
+ requirements = gguf_variants._build_gguf_variant_requirements(
+ [
+ _sibling("Ternary-Bonsai-1.7B-PQ2_0.gguf", 10, "pq"),
+ _sibling("Ternary-Bonsai-1.7B-Q2_0.gguf", 20, "q2"),
+ _sibling("Ternary-Bonsai-1.7B-Q2_0_g64.gguf", 30, "q2g64"),
+ ]
+ )
+
+ assert set(requirements) == {"pq2_0", "q2_0", "q2_0_g64"}
+ assert requirements["pq2_0"].target_filenames == ("Ternary-Bonsai-1.7B-PQ2_0.gguf",)
+ assert requirements["q2_0"].target_filenames == ("Ternary-Bonsai-1.7B-Q2_0.gguf",)
+ assert requirements["q2_0_g64"].target_filenames == ("Ternary-Bonsai-1.7B-Q2_0_g64.gguf",)
+
+
def test_qwen38_flash_next_plan_includes_the_loaders_nested_mtp_choice():
requirements = gguf_variants._build_gguf_variant_requirements(
[
diff --git a/studio/backend/hub/utils/gguf.py b/studio/backend/hub/utils/gguf.py
index 37bd07e69f6..7b775925a14 100644
--- a/studio/backend/hub/utils/gguf.py
+++ b/studio/backend/hub/utils/gguf.py
@@ -78,9 +78,9 @@ _GGUF_QUANT_RE = re.compile(
r"(UD-)?"
r"(MXFP[0-9]+(?:_[A-Z0-9]+)*"
r"|IQ[0-9]+_[A-Z]+(?:_[A-Z0-9]+)?"
- r"|TQ[0-9]+_[0-9]+"
+ r"|P?TQ[0-9]+_[0-9]+"
r"|Q[0-9]+_K_[A-Z]+"
- r"|Q[0-9]+_[0-9]+"
+ r"|P?Q[0-9]+_[0-9]+(?:_G[0-9]+)?"
r"|Q[0-9]+_K"
r"|BF16|F16|F32)",
re.IGNORECASE,
diff --git a/studio/backend/tests/test_gguf_variant_rows.py b/studio/backend/tests/test_gguf_variant_rows.py
index 02db53adcce..9717dad7fe7 100644
--- a/studio/backend/tests/test_gguf_variant_rows.py
+++ b/studio/backend/tests/test_gguf_variant_rows.py
@@ -142,6 +142,19 @@ def test_loader_mirror_agrees_with_the_hub_key():
assert [_gguf_variant_key(p) for p in corpus] == [gguf_variant_key(p) for p in corpus]
+def test_packed_and_grouped_quants_keep_their_own_key_in_both_copies():
+ # prism-ml/Ternary-Bonsai-*-gguf ships all three beside each other.
+ files = {
+ "Ternary-Bonsai-8B-PQ2_0.gguf": "PQ2_0",
+ "Ternary-Bonsai-8B-Q2_0.gguf": "Q2_0",
+ "Ternary-Bonsai-8B-Q2_0_g64.gguf": "Q2_0_g64",
+ "Ternary-Bonsai-2-27B-PTQ1_0.gguf": "PTQ1_0",
+ }
+ for path, key in files.items():
+ assert gguf_variant_key(path) == key
+ assert _gguf_variant_key(path) == key
+
+
# --------------------------------------------------------------------------------------
# Rows
# --------------------------------------------------------------------------------------
diff --git a/studio/backend/utils/models/model_config.py b/studio/backend/utils/models/model_config.py
index 23b4842aa2c..d90f4ceb32f 100644
--- a/studio/backend/utils/models/model_config.py
+++ b/studio/backend/utils/models/model_config.py
@@ -2698,9 +2698,9 @@ def _extract_quant_label(filename: str) -> str:
r"(UD-)?" # Optional UD- prefix (Ultra Discrete)
r"(MXFP[0-9]+(?:_[A-Z0-9]+)*" # MXFP variants: MXFP4, MXFP4_MOE
r"|IQ[0-9]+_[A-Z]+(?:_[A-Z0-9]+)?" # IQ variants: IQ4_XS, IQ4_NL, IQ1_S
- r"|TQ[0-9]+_[0-9]+" # Ternary quant: TQ1_0, TQ2_0
+ r"|P?TQ[0-9]+_[0-9]+" # Ternary quant: TQ1_0, TQ2_0
r"|Q[0-9]+_K_[A-Z]+" # K-quant: Q4_K_M, Q3_K_S
- r"|Q[0-9]+_[0-9]+" # Standard: Q8_0, Q5_1
+ r"|P?Q[0-9]+_[0-9]+(?:_G[0-9]+)?" # Standard/Packed: Q8_0, PQ2_0, Q2_0_g64
r"|Q[0-9]+_K" # Short K-quant: Q6_K
r"|BF16|F16|F32)" # Full precision
# Optional bits-per-weight modifier so repos shipping several files at one base quant
@@ -2730,9 +2730,9 @@ _GGUF_KNOWN_QUANT_RE = re.compile(
r"(UD-)?"
r"(MXFP[0-9]+(?:_[A-Z0-9]+)*"
r"|IQ[0-9]+_[A-Z]+(?:_[A-Z0-9]+)?"
- r"|TQ[0-9]+_[0-9]+"
+ r"|P?TQ[0-9]+_[0-9]+"
r"|Q[0-9]+_K_[A-Z]+"
- r"|Q[0-9]+_[0-9]+"
+ r"|P?Q[0-9]+_[0-9]+(?:_G[0-9]+)?"
r"|Q[0-9]+_K"
r"|BF16|F16|F32)",
re.IGNORECASE,
diff --git a/studio/frontend/src/features/chat/api/chat-adapter.ts b/studio/frontend/src/features/chat/api/chat-adapter.ts
index c57f07ec266..e6fa4647312 100644
--- a/studio/frontend/src/features/chat/api/chat-adapter.ts
+++ b/studio/frontend/src/features/chat/api/chat-adapter.ts
@@ -2274,7 +2274,7 @@ const MAX_AUTO_LOAD_ATTEMPTS = 3;
const MAX_AUTO_VALIDATE_FAILURES = 12;
const BIG_ENDIAN_GGUF_FILENAME_RE = /(^|[-_])be(?:[._-]|$)/gi;
const GGUF_KNOWN_QUANT_RE =
- /(UD-)?(MXFP[0-9]+(?:_[A-Z0-9]+)*|IQ[0-9]+_[A-Z]+(?:_[A-Z0-9]+)?|TQ[0-9]+_[0-9]+|Q[0-9]+_K_[A-Z]+|Q[0-9]+_[0-9]+|Q[0-9]+_K|BF16|F16|F32)/i;
+ /(UD-)?(MXFP[0-9]+(?:_[A-Z0-9]+)*|IQ[0-9]+_[A-Z]+(?:_[A-Z0-9]+)?|P?TQ[0-9]+_[0-9]+|Q[0-9]+_K_[A-Z]+|P?Q[0-9]+_[0-9]+(?:_G[0-9]+)?|Q[0-9]+_K|BF16|F16|F32)/i;
type AutoLoadCandidate = {
id: string;
diff --git a/studio/frontend/src/features/model-picker/model-config/model-identity.ts b/studio/frontend/src/features/model-picker/model-config/model-identity.ts
index 886e94bae9f..b8d2df1e1d2 100644
--- a/studio/frontend/src/features/model-picker/model-config/model-identity.ts
+++ b/studio/frontend/src/features/model-picker/model-config/model-identity.ts
@@ -113,7 +113,7 @@ export function ggufVariantFromStorageKey(key: string): string | null {
const BPW_SUFFIX = /-[0-9]+(?:\.[0-9]+)?bpw$/i;
// One source for the anchored test and the scan below. Mirrors _GGUF_QUANT_RE in gguf.py.
const QUANT_TOKEN_SOURCE =
- "(UD-)?(MXFP[0-9]+(?:_[A-Z0-9]+)*|IQ[0-9]+_[A-Z]+(?:_[A-Z0-9]+)?|TQ[0-9]+_[0-9]+|Q[0-9]+_K_[A-Z]+|Q[0-9]+_[0-9]+|Q[0-9]+_K|BF16|F16|F32)";
+ "(UD-)?(MXFP[0-9]+(?:_[A-Z0-9]+)*|IQ[0-9]+_[A-Z]+(?:_[A-Z0-9]+)?|P?TQ[0-9]+_[0-9]+|Q[0-9]+_K_[A-Z]+|P?Q[0-9]+_[0-9]+(?:_G[0-9]+)?|Q[0-9]+_K|BF16|F16|F32)";
const KNOWN_QUANT = new RegExp(`^${QUANT_TOKEN_SOURCE}$`, "i");
const QUANT_TOKEN = new RegExp(QUANT_TOKEN_SOURCE, "gi");
const MAX_QUANT_SUFFIX_LEN = 64;
diff --git a/unsloth_cli/commands/start.py b/unsloth_cli/commands/start.py
index d7e654e7826..dcdb1b174f4 100644
--- a/unsloth_cli/commands/start.py
+++ b/unsloth_cli/commands/start.py
@@ -2231,9 +2231,9 @@ _QUANT_LABEL_RE = re.compile(
r"(UD-)?"
r"(MXFP[0-9]+(?:_[A-Z0-9]+)*"
r"|IQ[0-9]+_[A-Z]+(?:_[A-Z0-9]+)?"
- r"|TQ[0-9]+_[0-9]+"
+ r"|P?TQ[0-9]+_[0-9]+"
r"|Q[0-9]+_K_[A-Z]+"
- r"|Q[0-9]+_[0-9]+"
+ r"|P?Q[0-9]+_[0-9]+(?:_G[0-9]+)?"
r"|Q[0-9]+_K"
r"|BF16|F16|F32)"
r"(-[0-9]+(?:\.[0-9]+)?bpw)?",
diff --git a/unsloth_cli/tests/test_start.py b/unsloth_cli/tests/test_start.py
index 6bf9d2e7eb5..bf75ac561f6 100644
--- a/unsloth_cli/tests/test_start.py
+++ b/unsloth_cli/tests/test_start.py
@@ -9798,3 +9798,14 @@ def test_openclaw_memory_search_clears_a_stale_external_fallback(
config = json.loads(config_path.read_text())
assert config["memory"]["search"]["fallback"] == "none"
assert config["memory"]["search"]["provider"] == "openai-compatible"
+
+
+def test_direct_gguf_labels_keep_packed_and_grouped_quants():
+ # Mirrors model_config._extract_quant_label: prism-ml/Ternary-Bonsai-*-gguf ships all three.
+ for name, label in (
+ ("Ternary-Bonsai-8B-PQ2_0.gguf", "PQ2_0"),
+ ("Ternary-Bonsai-8B-Q2_0.gguf", "Q2_0"),
+ ("Ternary-Bonsai-8B-Q2_0_g64.gguf", "Q2_0_g64"),
+ ("Ternary-Bonsai-2-27B-PTQ1_0.gguf", "PTQ1_0"),
+ ):
+ assert start._direct_gguf_variant_labels(name)[1] == label