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.

Studio: list imatrix-weighted quants named <model>-<QUANT>-imatrix.gguf (#14931)

Daniel Han43eca729b8d3
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py
index a07f70a22a1..bc7ae70924f 100644
--- a/studio/backend/core/inference/llama_cpp.py
+++ b/studio/backend/core/inference/llama_cpp.py
@@ -3435,6 +3435,10 @@ def _drafter_path_kind(path: str) -> Optional[str]:
_IMATRIX_TOKEN_RE = re.compile(r"^imatrix(?:[._\-]|$)|[._\-]imatrix$", re.IGNORECASE)
+# Mirrors hub.utils.gguf._IMATRIX_WEIGHTED_RE.
+_IMATRIX_WEIGHTED_RE = re.compile(
+ r"[._\-](?:I?Q[0-9]+_|P?TQ[0-9]+_|(?:MX|NV)FP[0-9])[^/]*[_\-]imatrix$", re.IGNORECASE
+)
def _is_companion_gguf_path(path: str) -> bool:
@@ -3455,7 +3459,8 @@ def _is_companion_gguf_path(path: str) -> bool:
return True
# Mirrors hub.utils.gguf.is_imatrix_filename: an imatrix is a valid GGUF container
# holding calibration statistics, so only the name rules it out.
- if _IMATRIX_TOKEN_RE.search(Path(p).stem):
+ stem = Path(p).stem
+ if _IMATRIX_TOKEN_RE.search(stem) and not _IMATRIX_WEIGHTED_RE.search(stem):
return True
if _DSPARK_BEFORE_QUANT_RE.search(Path(p).name):
return True
diff --git a/studio/backend/hub/utils/gguf.py b/studio/backend/hub/utils/gguf.py
index 3fe107cd28c..89e9bafd582 100644
--- a/studio/backend/hub/utils/gguf.py
+++ b/studio/backend/hub/utils/gguf.py
@@ -93,13 +93,21 @@ def is_mmproj_filename(filename: str) -> bool:
# Anchored at an END of the stem, never a substring, for the reason is_mtp_drafter_path documents: a name that merely contains the word (Qwen3-Imatrix-Tuned-Q4_K_M.gguf) is a real model, while every published imatrix leads or closes with it.
_IMATRIX_TOKEN_RE = re.compile(r"^imatrix(?:[._\-]|$)|[._\-]imatrix$", re.IGNORECASE)
+# llama.cpp reads an imatrix only to quantize, so a quant label before a trailing token marks imatrix-weighted
+# weights (Lewdiculous `<model>-Q4_K_M-imatrix.gguf`), not the calibration file. Float labels do not count, nor does
+# `.imatrix`: mradermacher names its calibration file `<model>.imatrix.gguf`, and model names carry `mxfp4` / `q4_0`.
+_IMATRIX_WEIGHTED_RE = re.compile(
+ r"[._\-](?:I?Q[0-9]+_|P?TQ[0-9]+_|(?:MX|NV)FP[0-9])[^/]*[_\-]imatrix$", re.IGNORECASE
+)
def is_imatrix_filename(path: str) -> bool:
- """True for a calibration imatrix: ``imatrix.gguf``, ``imatrix_unsloth.gguf``, ``imatrix_unsloth.dat``, ``<model>-imatrix.gguf``, ``<model>.imatrix``. It holds activation statistics for llama-quantize, not a model, and llama-server never opens one, so it is neither a selectable variant nor a companion to fetch: unlike mmproj and the MTP drafter it is excluded outright, everywhere they are. Most repos spell it .dat or .gguf_file, which no GGUF listing sees; the ones that publish imatrix_unsloth.gguf (unsloth/Qwen3.8-27B-GGUF) put a valid GGUF container carrying no model in front of the variant menu, download and loader. CANONICAL COPY. Two mirrors must change in lockstep: utils/models/model_config.py ``_is_imatrix_path`` (utils cannot import hub) and core/inference/llama_cpp.py ``_is_companion_gguf_path`` (core avoids hub imports)."""
+ """True for a calibration imatrix: ``imatrix.gguf``, ``imatrix_unsloth.gguf``, ``imatrix_unsloth.dat``, ``<model>-imatrix.gguf``, ``<model>.imatrix``; never ``<model>-Q4_K_M-imatrix.gguf``, which is imatrix-weighted weights. It holds activation statistics for llama-quantize, not a model, and llama-server never opens one, so it is neither a selectable variant nor a companion to fetch: unlike mmproj and the MTP drafter it is excluded outright, everywhere they are. Most repos spell it .dat or .gguf_file, which no GGUF listing sees; the ones that publish imatrix_unsloth.gguf (unsloth/Qwen3.8-27B-GGUF) put a valid GGUF container carrying no model in front of the variant menu, download and loader. CANONICAL COPY. Two mirrors must change in lockstep: utils/models/model_config.py ``_is_imatrix_path`` (utils cannot import hub) and core/inference/llama_cpp.py ``_is_companion_gguf_path`` (core avoids hub imports)."""
name = path.replace("\\", "/").rsplit("/", 1)[-1]
stem = name.rsplit(".", 1)[0] if "." in name else name
- return bool(_IMATRIX_TOKEN_RE.search(stem)) or name.lower().endswith(".imatrix")
+ if _IMATRIX_TOKEN_RE.search(stem) and not _IMATRIX_WEIGHTED_RE.search(stem):
+ return True
+ return name.lower().endswith(".imatrix")
# dspark and dflash are the same DeepSeek V4 Flash drafter: the folder it ships in and the architecture it reports.
diff --git a/studio/backend/tests/test_imatrix_gguf_filtering.py b/studio/backend/tests/test_imatrix_gguf_filtering.py
index 2287829eb6a..ebeeabc7e5f 100644
--- a/studio/backend/tests/test_imatrix_gguf_filtering.py
+++ b/studio/backend/tests/test_imatrix_gguf_filtering.py
@@ -36,6 +36,14 @@ IMATRIX_NAMES = [
"Qwen3.8-27B.imatrix",
"Qwen3.8-27B-imatrix.gguf",
"quants/imatrix_unsloth.gguf",
+ "imatrix-fp16.gguf",
+ "z-combined-imatrix.gguf",
+ "Qwen3.5-9B-NEO-IMATRIX-MAX-MTP.imatrix.gguf",
+ # A float label is no quant: llama.cpp has no imatrix-weighted F16.
+ "Qwen3-8B-BF16-imatrix.gguf",
+ # mradermacher's calibration file, even when the model name carries a quant-like token.
+ "GPT-oss-20B-RoleplaySFT-mxfp4.imatrix.gguf",
+ "gemma-4-12B-it-qat-q4_0-unquantized-uncensored-heretic-v3.imatrix.gguf",
]
MODEL_NAMES = [
@@ -44,6 +52,11 @@ MODEL_NAMES = [
# The word inside a name is not the file: only a leading or trailing token is.
"Qwen3-Imatrix-Tuned-Q4_K_M.gguf",
"imatrixed-model-Q8_0.gguf",
+ # Imatrix-weighted quants named for it (#14695): a quant label before the trailing token.
+ "Kunocchini-7b-128k-test-Q4_K_M-imatrix.gguf",
+ "Qwen3.5-4B-heretic-IQ4_NL-imatrix.gguf",
+ "DeepSeek-V4.1-Flash-1017-IQ2_XXS-Q2_K-imatrix.gguf",
+ "Ornith-1.5-35B-A3B-MXFP4_MOE_Q8_0-Imatrix.gguf",
]
@@ -82,6 +95,24 @@ def test_remote_listing_drops_the_imatrix_row(monkeypatch):
assert [v.quant for v in variants] == ["UD-Q4_K_XL"]
+def test_remote_listing_keeps_imatrix_weighted_quants(monkeypatch):
+ info = SimpleNamespace(
+ siblings = [
+ SimpleNamespace(rfilename = "Kunocchini-7b-Q4_K_M-imatrix.gguf", size = 4_368_438_976),
+ SimpleNamespace(rfilename = "Kunocchini-7b-Q8_0-imatrix.gguf", size = 7_695_857_856),
+ SimpleNamespace(rfilename = "imatrix-fp16.gguf", size = 7_100_000),
+ ]
+ )
+ api = SimpleNamespace(model_info = lambda *a, **k: info)
+ monkeypatch.setattr("huggingface_hub.HfApi", lambda token = None: api)
+
+ variants, _has_vision, _siblings = list_gguf_variants("Lewdiculous/Kunocchini-7b-GGUF-Imatrix")
+ assert sorted(v.filename for v in variants) == [
+ "Kunocchini-7b-Q4_K_M-imatrix.gguf",
+ "Kunocchini-7b-Q8_0-imatrix.gguf",
+ ]
+
+
def test_the_imatrix_is_neither_planned_nor_downloaded():
siblings = [
SimpleNamespace(rfilename = "Qwen3.8-27B-UD-Q4_K_XL.gguf", size = 17_559_178_144),
diff --git a/studio/backend/utils/models/model_config.py b/studio/backend/utils/models/model_config.py
index f7970827d81..9efe3c6e875 100644
--- a/studio/backend/utils/models/model_config.py
+++ b/studio/backend/utils/models/model_config.py
@@ -1923,8 +1923,11 @@ def _is_mmproj(filename: str) -> bool:
return "mmproj" in filename.lower()
-# Mirrors hub.utils.gguf._IMATRIX_TOKEN_RE (utils cannot import hub).
+# Mirrors hub.utils.gguf._IMATRIX_TOKEN_RE and _IMATRIX_WEIGHTED_RE (utils cannot import hub).
_IMATRIX_TOKEN_RE = re.compile(r"^imatrix(?:[._\-]|$)|[._\-]imatrix$", re.IGNORECASE)
+_IMATRIX_WEIGHTED_RE = re.compile(
+ r"[._\-](?:I?Q[0-9]+_|P?TQ[0-9]+_|(?:MX|NV)FP[0-9])[^/]*[_\-]imatrix$", re.IGNORECASE
+)
def _is_imatrix_path(path: str) -> bool:
@@ -1939,7 +1942,9 @@ def _is_imatrix_path(path: str) -> bool:
"""
name = path.replace("\\", "/").rsplit("/", 1)[-1]
stem = name.rsplit(".", 1)[0] if "." in name else name
- return bool(_IMATRIX_TOKEN_RE.search(stem)) or name.lower().endswith(".imatrix")
+ if _IMATRIX_TOKEN_RE.search(stem) and not _IMATRIX_WEIGHTED_RE.search(stem):
+ return True
+ return name.lower().endswith(".imatrix")
# Mirrors hub.utils.gguf._DRAFTER_KINDS. dflash/ holds real weights, so it is a drafter by prefix only.