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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: never offer a calibration imatrix as a GGUF variant (#9409)
Daniel Hana4d85244e876
diff --git a/studio/backend/core/inference/diffusion_lora.py b/studio/backend/core/inference/diffusion_lora.pyindex 7fe3db50db6..5f517926e93 100644--- a/studio/backend/core/inference/diffusion_lora.py+++ b/studio/backend/core/inference/diffusion_lora.py@@ -274,9 +274,16 @@ def _pick_repo_weight_file(repo_id: str, hf_token: Optional[str]) -> str:"""Pick the single LoRA weight file in an HF repo (prefer safetensors)."""from huggingface_hub import HfApi- from hub.utils.gguf import drop_shadowed_appledouble_names+ from hub.utils.gguf import drop_shadowed_appledouble_names, is_imatrix_filename- files = drop_shadowed_appledouble_names(list(HfApi(token = hf_token).list_repo_files(repo_id)))+ files = [+ f+ for f in drop_shadowed_appledouble_names(+ list(HfApi(token = hf_token).list_repo_files(repo_id))+ )+ # An imatrix is not adapter weights, and it would be the fallback pick below.+ if not is_imatrix_filename(f)+ ]safes = [f for f in files if f.lower().endswith(".safetensors") and "/" not in f]if len(safes) == 1:return safes[0]diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.pyindex 403c3b7ffdd..0b18745222c 100644--- a/studio/backend/core/inference/llama_cpp.py+++ b/studio/backend/core/inference/llama_cpp.py@@ -1962,9 +1962,12 @@ def _drafter_path_kind(path: str) -> Optional[str]:return None+_IMATRIX_TOKEN_RE = re.compile(r"^imatrix(?:[._\-]|$)|[._\-]imatrix$", re.IGNORECASE)++def _is_companion_gguf_path(path: str) -> bool:- """True for a non-main GGUF: vision mmproj, or a separate drafter (repo-root- ``mtp-*.gguf``, the ``MTP/`` subdir copies for Gemma 4, the ``dspark/``+ """True for a non-main GGUF: vision mmproj, a calibration imatrix, or a separate+ drafter (repo-root ``mtp-*.gguf``, the ``MTP/`` subdir copies for Gemma 4, the ``dspark/``drafters for DeepSeek V4 Flash). Mirrors hub.utils.gguf so variant resolutionnever picks a companion as the main model -- a Gemma ``Q8_0`` request must notresolve to ``MTP/...-Q8_0-MTP.gguf``, which sorts ahead of the real weight.@@ -1976,6 +1979,10 @@ def _is_companion_gguf_path(path: str) -> bool:return Falseif "mmproj" in p: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):+ return Truereturn _drafter_path_kind(path) is not Nonediff --git a/studio/backend/core/inference/openai_auto_download.py b/studio/backend/core/inference/openai_auto_download.pyindex 53b1ceb3ac0..96c302220d0 100644--- a/studio/backend/core/inference/openai_auto_download.py+++ b/studio/backend/core/inference/openai_auto_download.py@@ -258,8 +258,8 @@ def _auth_denied(repo_id: str, hf_token: Optional[str]) -> bool:def _gguf_variants(siblings, repo_id: str = "") -> dict[str, int]:"""Quant label -> bytes the download will actually fetch.- Mirrors list_gguf_variants for the selectable labels: companions (mmproj/MTP)- and big-endian builds are not quants, and sharded quants sum across shards.+ Mirrors list_gguf_variants for the selectable labels: companions (mmproj/MTP),+ calibration imatrices and big-endian builds are not quants, and sharded quants sum across shards.Bytes come from the download plan, which folds companions back into everyquant, so the disk reserve is measured against what the worker fetches."""@@ -269,6 +269,7 @@ def _gguf_variants(siblings, repo_id: str = "") -> dict[str, int]:from utils.models.model_config import (_extract_quant_label,_is_big_endian_gguf_path,+ _is_imatrix_path,_is_mmproj,_is_mtp_drafter,)@@ -298,7 +299,12 @@ def _gguf_variants(siblings, repo_id: str = "") -> dict[str, int]:# key the whole stem, so advertising ours dispatches an unresolvable variant.quant = canonical_quant_label(name) or quant# The endian test reads a quant TOKEN, so it gets the label, not the path-qualified key.- if _is_mmproj(name) or _is_mtp_drafter(name) or _is_big_endian_gguf_path(name, label):+ if (+ _is_mmproj(name)+ or _is_mtp_drafter(name)+ or _is_imatrix_path(name)+ or _is_big_endian_gguf_path(name, label)+ ):continueplan = plans.get(quant.lower())if plan is not None:diff --git a/studio/backend/hub/services/models/common.py b/studio/backend/hub/services/models/common.pyindex 4c96cfd2ea5..404d052b5d1 100644--- a/studio/backend/hub/services/models/common.py+++ b/studio/backend/hub/services/models/common.py@@ -20,6 +20,7 @@ from hub.schemas.inventory import (from hub.utils.gguf import (gguf_variant_key,is_gguf_filename as _is_gguf_filename,+ is_imatrix_filename as _is_imatrix_filename,is_mmproj_filename as _is_mmproj_filename,is_mtp_drafter_path as _is_mtp_drafter_path,)@@ -66,7 +67,7 @@ _HF_CACHE_MODEL_FILE_PROBE_LIMIT = 2000def _is_model_directory(d: Path) -> bool:- """True when *d* has a config plus real weights; excludes mmproj GGUFs and non-weight ``.bin`` files (``tokenizer.bin``) to avoid false positives."""+ """True when *d* has a config plus real weights; excludes mmproj GGUFs, calibration imatrices and non-weight ``.bin`` files (``tokenizer.bin``) to avoid false positives."""def _is_weight_file(f: Path) -> bool:if is_appledouble_metadata(f):@@ -75,7 +76,11 @@ def _is_model_directory(d: Path) -> bool:if suffix == ".safetensors":return Trueif suffix == ".gguf":- return "mmproj" not in f.name.lower() and not _is_mtp_drafter_path(f.name)+ return (+ "mmproj" not in f.name.lower()+ and not _is_mtp_drafter_path(f.name)+ and not _is_imatrix_filename(f.name)+ )if suffix == ".bin":name = f.name.lower()return (@@ -550,7 +555,10 @@ def _classify_non_gguf_model_format(def _is_main_gguf_filename(name: str) -> bool:return (- _is_gguf_filename(name) and not _is_mmproj_filename(name) and not _is_mtp_drafter_path(name)+ _is_gguf_filename(name)+ and not _is_mmproj_filename(name)+ and not _is_mtp_drafter_path(name)+ and not _is_imatrix_filename(name))diff --git a/studio/backend/hub/services/models/deletion.py b/studio/backend/hub/services/models/deletion.pyindex 2d992875c40..0bb040381fe 100644--- a/studio/backend/hub/services/models/deletion.py+++ b/studio/backend/hub/services/models/deletion.py@@ -41,6 +41,7 @@ from hub.services import resolve_destructive_repo_idsfrom hub.services.models import cache_inventory, downloads, gguf_variantsfrom hub.services.models.common import (_is_gguf_filename,+ _is_imatrix_filename,_is_main_gguf_filename,_is_mmproj_filename,)@@ -296,9 +297,15 @@ def _delete_gguf_variant_from_repos(target_repo,# Companions: mmproj and the drafters Studio downloads (MTP with# every variant, DSpark on opt-in). No main GGUF is left, so they- # cannot be launched; reclaim them with the last variant.+ # cannot be launched; reclaim them with the last variant. An imatrix+ # joins them: no longer offered as a variant, so a copy an older build+ # fetched as one would be unreachable from the UI.lambda name: _is_gguf_filename(name)- and (_is_mmproj_filename(name) or _is_reclaimable_drafter_path(name)),+ and (+ _is_mmproj_filename(name)+ or _is_reclaimable_drafter_path(name)+ or _is_imatrix_filename(name)+ ),)for snap, _blob, name in companion_matches:try:diff --git a/studio/backend/hub/services/models/gguf_variants.py b/studio/backend/hub/services/models/gguf_variants.pyindex 8be32660ec4..6d616ddab2f 100644--- a/studio/backend/hub/services/models/gguf_variants.py+++ b/studio/backend/hub/services/models/gguf_variants.py@@ -50,6 +50,7 @@ from hub.utils.paths import (# Loader's normalizer, not the hub's: they disagree on WSL, and only it names what the load opens.from utils.paths import normalize_path as _loader_normalize_pathfrom hub.services.models.common import (+ _is_imatrix_filename,_is_mmproj_filename,_is_mtp_drafter_path,_iter_gguf_paths,@@ -516,6 +517,10 @@ def _local_main_gguf_blobs_by_quant(normalized = str(path).replace("\\", "/")if not hashes:continue+ if _is_imatrix_filename(normalized):+ # Not a companion either: nothing fetches an imatrix, so a stale copy+ # on disk must not vouch for a variant's blobs.+ continueif _is_mmproj_filename(normalized) or _is_mtp_drafter_path(normalized):companion_blobs.setdefault(normalized, set()).update(str(blob) for blob in hashes if blob@@ -724,6 +729,7 @@ def _direct_gguf_loads(path: Path) -> bool:return not (_is_mmproj_filename(path.name)or _is_mtp_drafter_path(context)+ or _is_imatrix_filename(path.name)or is_big_endian_gguf_path(context, _extract_quant_label(context))or is_appledouble_metadata(path))@@ -1399,7 +1405,11 @@ async def get_gguf_variants_answer(continuekey = rel.lower()by_filename[key] = max(by_filename.get(key, 0), size)- if _is_mmproj_filename(f.name) or _is_mtp_drafter_path(rel):+ if (+ _is_mmproj_filename(f.name)+ or _is_mtp_drafter_path(rel)+ or _is_imatrix_filename(f.name)+ ):continueq = gguf_variant_key(rel)if is_big_endian_gguf_path(rel, extract_quant_label(rel)):diff --git a/studio/backend/hub/utils/gguf.py b/studio/backend/hub/utils/gguf.pyindex fbbffc7e41f..a963022a6b5 100644--- a/studio/backend/hub/utils/gguf.py+++ b/studio/backend/hub/utils/gguf.py@@ -89,6 +89,33 @@ def is_mmproj_filename(filename: str) -> bool:return "mmproj" in filename.lower()+# 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)+++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).+ """+ 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")++# Separate-file drafter kinds. dspark and dflash are the same DeepSeek V4 Flash# drafter: the folder it ships in and the architecture it reports._DRAFTER_KINDS = ("mtp", "dspark", "dflash")@@ -289,6 +316,7 @@ def pick_best_gguf(filenames: list[str]) -> Optional[str]:if is_gguf_filename(name)and not is_mmproj_filename(name)and not is_mtp_drafter_path(name)+ and not is_imatrix_filename(name)and not is_big_endian_gguf_path(name, extract_quant_label(name))]if not gguf_files:@@ -849,10 +877,16 @@ def list_partial_gguf_variants_from_state(main_filename: Optional[str] = Nonesize_bytes = 0companion_bytes = 0+ imatrix_only = Falseif manifest is not None:for expected in manifest.expected_files:if not is_gguf_filename(expected.path):continue+ if is_imatrix_filename(expected.path):+ # A manifest predating this filtering can still name one; it is+ # neither weights nor a companion, so it counts towards neither size.+ imatrix_only = True+ continueif is_mtp_drafter_path(expected.path):# Downloaded with every variant (like mmproj) but not a# selectable quant; count it so the shown download size@@ -867,6 +901,13 @@ def list_partial_gguf_variants_from_state(main_filename = expected.pathsize_bytes += max(0, int(expected.size or 0))if main_filename is None:+ # An older build could download the imatrix as a variant of its own, so its+ # interrupted state is still on disk. Naming the synthetic file after the+ # variant would put that row back in the menu, at zero bytes, on exactly the+ # offline path this listing serves. Only when NOTHING eligible was found:+ # a marker-only quant keeps its synthetic row so it can be resumed or deleted.+ if imatrix_only or is_imatrix_filename(variant):+ continuemain_filename = f"{variant}.gguf"variants.append(GgufVariantInfo(@@ -972,7 +1013,7 @@ def list_gguf_variants(continueif not _is_selectable_repo_gguf(repo_id, filename):continue- if is_mtp_drafter_path(filename):+ if is_mtp_drafter_path(filename) or is_imatrix_filename(filename):continueif is_mmproj_filename(filename):has_vision = True@@ -1038,6 +1079,8 @@ def list_local_gguf_variants(for file in sorted(iter_gguf_files(root, recursive = True)):if h3_bundle_repo and not _is_selectable_repo_gguf(h3_bundle_repo, file.name):continue+ if is_imatrix_filename(file.name):+ continueif is_mmproj_filename(file.name):# An empty projector is an interrupted download; an audio-only one is not vision.try:diff --git a/studio/backend/hub/utils/gguf_plan.py b/studio/backend/hub/utils/gguf_plan.pyindex 01287f66cc9..4e1f22f558b 100644--- a/studio/backend/hub/utils/gguf_plan.py+++ b/studio/backend/hub/utils/gguf_plan.py@@ -15,6 +15,7 @@ from hub.utils.gguf import (is_big_endian_gguf_path,drop_shadowed_appledouble_siblings,is_gguf_filename,+ is_imatrix_filename,is_mmproj_filename,is_mtp_drafter_path,)@@ -82,6 +83,7 @@ def is_main_gguf_variant_path(path: str, variant: str) -> bool:is_gguf_filename(path)and not is_mmproj_filename(path)and not is_mtp_drafter_path(path)+ and not is_imatrix_filename(path)# The endian predicate reads a quant TOKEN, so it gets the label: handed the qualified key# it cannot see a parent-only quant and drops the file, leaving the plan with no main# files at all and an interrupted download with no hashes to resume against.@@ -243,7 +245,9 @@ def build_gguf_variant_plans(siblings: Sequence) -> dict[str, GgufVariantPlan]:# Companions are folded into every plan below; keep them out of the# quant grouping so a drafter never lands in a variant's main files# (the root mtp-*.gguf carries a quant label, e.g. Q8_0).- if is_mmproj_filename(name) or is_mtp_drafter_path(name):+ # An imatrix leaves entirely rather than joining companions_expected: no+ # variant needs llama-quantize's calibration data downloaded.+ if is_mmproj_filename(name) or is_mtp_drafter_path(name) or is_imatrix_filename(name):continuequant = gguf_variant_key(name).lower()# The endian predicate reads a quant TOKEN -- it decides whether the quant came from thediff --git a/studio/backend/hub/utils/inventory_scan.py b/studio/backend/hub/utils/inventory_scan.pyindex 710a1d63b54..a71959f52da 100644--- a/studio/backend/hub/utils/inventory_scan.py+++ b/studio/backend/hub/utils/inventory_scan.py@@ -32,6 +32,7 @@ from hub.utils.gguf import (gguf_variant_key,is_big_endian_gguf_path,is_gguf_filename,+ is_imatrix_filename,is_mmproj_filename,is_mtp_drafter_path,)@@ -783,7 +784,12 @@ def _completed_gguf_variants(snapshot_dir: Optional[Path]) -> set[str]:except OSError:continuerel = path.relative_to(snapshot_dir).as_posix()- if not is_gguf_filename(rel) or is_mmproj_filename(rel) or is_mtp_drafter_path(rel):+ if (+ not is_gguf_filename(rel)+ or is_mmproj_filename(rel)+ or is_mtp_drafter_path(rel)+ or is_imatrix_filename(rel)+ ):continue# Metadata vouching for a quant marks a torn snapshot ready: a set whose sidecars are# all present but whose weights are not answers the shard count exactly as the realdiff --git a/studio/backend/tests/test_imatrix_gguf_filtering.py b/studio/backend/tests/test_imatrix_gguf_filtering.pynew file mode 100644index 00000000000..1335b002e32--- /dev/null+++ b/studio/backend/tests/test_imatrix_gguf_filtering.py@@ -0,0 +1,184 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""A calibration imatrix is not a model, so no GGUF surface may offer one.++unsloth/Qwen3.8-27B-GGUF publishes imatrix_unsloth.gguf beside the weights (most+repos use the .dat / .gguf_file spellings the Hub does not list as GGUF). Carrying+a real .gguf suffix, it reached the chat model picker as an unlabelled ~13 MB row+called "GGUF", downloadable and then unloadable.+"""++from __future__ import annotations++import os+import sys+from pathlib import Path+from types import SimpleNamespace++import pytest++_BACKEND_DIR = str(Path(__file__).resolve().parent.parent)+if _BACKEND_DIR not in sys.path:+ sys.path.insert(0, _BACKEND_DIR)++from core.inference.llama_cpp import _is_companion_gguf_path+from hub.utils.gguf import (+ is_imatrix_filename,+ list_gguf_variants,+ list_local_gguf_variants,+ list_partial_gguf_variants_from_state,+ pick_best_gguf,+)+from hub.utils.gguf_plan import build_gguf_variant_plans, is_main_gguf_variant_path+from utils.models.model_config import _is_imatrix_path, detect_gguf_model++IMATRIX_NAMES = [+ "imatrix_unsloth.gguf",+ "imatrix_unsloth.dat",+ "imatrix_unsloth.gguf_file",+ "imatrix.gguf",+ "IMATRIX_UNSLOTH.GGUF",+ "Qwen3.8-27B.imatrix",+ "Qwen3.8-27B-imatrix.gguf",+ "quants/imatrix_unsloth.gguf",+]++MODEL_NAMES = [+ "Qwen3.8-27B-UD-Q4_K_XL.gguf",+ "BF16/Qwen3.8-27B-BF16-00001-of-00002.gguf",+ # 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",+]++[email protected]("name", IMATRIX_NAMES)+def test_every_published_imatrix_spelling_is_recognized(name):+ assert is_imatrix_filename(name)+ assert _is_imatrix_path(name)++[email protected]("name", MODEL_NAMES)+def test_real_weights_are_not_mistaken_for_an_imatrix(name):+ assert not is_imatrix_filename(name)+ assert not _is_imatrix_path(name)++[email protected]("name", IMATRIX_NAMES + MODEL_NAMES)+def test_the_three_copies_of_the_predicate_agree(name):+ # hub cannot be imported from utils and core avoids importing it, so the rule is+ # spelled three times; a drift here is a file one surface hides and another loads.+ expected = is_imatrix_filename(name)+ assert _is_imatrix_path(name) is expected+ if name.lower().endswith(".gguf"):+ assert _is_companion_gguf_path(name) is expected+++def test_remote_listing_drops_the_imatrix_row(monkeypatch):+ info = SimpleNamespace(+ siblings = [+ SimpleNamespace(rfilename = "Qwen3.8-27B-UD-Q4_K_XL.gguf", size = 17_559_178_144),+ SimpleNamespace(rfilename = "imatrix_unsloth.gguf", size = 13_642_656),+ ]+ )+ api = SimpleNamespace(model_info = lambda *a, **k: info)+ monkeypatch.setattr("huggingface_hub.HfApi", lambda token = None: api)++ variants, _has_vision, _siblings = list_gguf_variants("unsloth/Qwen3.8-27B-GGUF")+ assert [v.quant for v in variants] == ["UD-Q4_K_XL"]+++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),+ SimpleNamespace(rfilename = "imatrix_unsloth.gguf", size = 13_642_656),+ ]+ plans = build_gguf_variant_plans(siblings)++ assert list(plans) == ["ud-q4_k_xl"]+ plan = plans["ud-q4_k_xl"]+ # Not a main file and not a companion folded into the plan: llama-quantize reads an+ # imatrix, llama-server never does, so no variant needs it on disk.+ assert plan.target_filenames == ("Qwen3.8-27B-UD-Q4_K_XL.gguf",)+ assert plan.download_size_bytes == 17_559_178_144+ assert not is_main_gguf_variant_path("imatrix_unsloth.gguf", "ud-q4_k_xl")+++def test_local_listing_and_load_path_skip_the_imatrix(tmp_path):+ (tmp_path / "Qwen3.8-27B-UD-Q4_K_XL.gguf").write_bytes(b"GGUF" + b"0" * 64)+ imatrix = tmp_path / "imatrix_unsloth.gguf"+ imatrix.write_bytes(b"GGUF" + b"0" * 8)+ (tmp_path / "config.json").write_text("{}", encoding = "utf-8")++ variants, _has_vision = list_local_gguf_variants(os.fspath(tmp_path))+ assert [v.quant for v in variants] == ["UD-Q4_K_XL"]++ assert pick_best_gguf(["imatrix_unsloth.gguf", "Qwen3.8-27B-UD-Q4_K_XL.gguf"]) == (+ "Qwen3.8-27B-UD-Q4_K_XL.gguf"+ )+ # Pointed at directly it is not a model either, so a folder scan cannot route it.+ assert detect_gguf_model(os.fspath(imatrix)) is None+ assert detect_gguf_model(os.fspath(tmp_path)) == os.fspath(+ tmp_path / "Qwen3.8-27B-UD-Q4_K_XL.gguf"+ )+++def _state_sources(monkeypatch, manifests, markers, manifest_for):+ from hub.utils import download_manifest++ monkeypatch.setattr(+ download_manifest,+ "iter_variant_manifests",+ lambda *_a, **_k: iter([(v, Path(f"{v}.json")) for v in manifests]),+ )+ monkeypatch.setattr(+ download_manifest,+ "iter_variant_markers",+ lambda *_a, **_k: iter([(v, Path(f"{v}.marker")) for v in markers]),+ )+ monkeypatch.setattr(+ download_manifest, "read_manifest", lambda _t, _r, variant, **_k: manifest_for(variant)+ )+++def test_interrupted_imatrix_state_does_not_come_back_as_a_row(monkeypatch):+ # An older build offered the imatrix as a variant, so a cancelled download of it can+ # still be on disk. Skipping only its expected file left main_filename unset, and the+ # synthetic "<variant>.gguf" fallback put the row back at zero bytes on exactly the+ # offline path this listing serves.+ manifest = SimpleNamespace(+ expected_files = [SimpleNamespace(path = "imatrix_unsloth.gguf", size = 13_642_656)]+ )+ _state_sources(+ monkeypatch,+ manifests = ["imatrix_unsloth"],+ markers = [],+ manifest_for = lambda _variant: manifest,+ )++ variants, _has_vision = list_partial_gguf_variants_from_state("unsloth/Qwen3.8-27B-GGUF")+ assert variants == []+++def test_a_marker_only_imatrix_variant_is_dropped_but_a_real_quant_survives(monkeypatch):+ # A cancel marker carries no manifest at all, so the filtered-file check above cannot+ # see it; the stored variant key is the only evidence. A real quant in the same state+ # must keep its synthetic row, or an interrupted download becomes unresumable.+ _state_sources(+ monkeypatch,+ manifests = [],+ markers = ["imatrix_unsloth", "UD-Q4_K_XL"],+ manifest_for = lambda _variant: None,+ )++ variants, _has_vision = list_partial_gguf_variants_from_state("unsloth/Qwen3.8-27B-GGUF")+ assert [v.quant for v in variants] == ["UD-Q4_K_XL"]+ assert variants[0].filename == "UD-Q4_K_XL.gguf"+++def test_an_imatrix_only_folder_offers_no_model(tmp_path):+ (tmp_path / "imatrix_unsloth.gguf").write_bytes(b"GGUF" + b"0" * 8)++ assert list_local_gguf_variants(os.fspath(tmp_path)) == ([], False)+ assert detect_gguf_model(os.fspath(tmp_path)) is Nonediff --git a/studio/backend/utils/models/model_config.py b/studio/backend/utils/models/model_config.pyindex d9bcd97837f..4fd8b37c1f1 100644--- a/studio/backend/utils/models/model_config.py+++ b/studio/backend/utils/models/model_config.py@@ -1474,6 +1474,25 @@ def _is_mmproj(filename: str) -> bool:return "mmproj" in filename.lower()+# Mirrors hub.utils.gguf._IMATRIX_TOKEN_RE (utils cannot import hub).+_IMATRIX_TOKEN_RE = re.compile(r"^imatrix(?:[._\-]|$)|[._\-]imatrix$", re.IGNORECASE)+++def _is_imatrix_path(path: str) -> bool:+ """True for a calibration imatrix published beside the weights+ (``imatrix_unsloth.gguf``, ``imatrix.gguf``, ``<model>.imatrix``).++ Activation statistics for llama-quantize, not a model, so it is excluded+ everywhere mmproj is: a GGUF-suffixed one is a valid container that a+ size-ranked scan would otherwise hand to llama-server.++ Mirrors hub.utils.gguf.is_imatrix_filename.+ """+ 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")++# Mirrors hub.utils.gguf._DRAFTER_KINDS. dflash/ holds real weights, so it is a drafter by prefix only._DRAFTER_KINDS = ("mtp", "dspark", "dflash")_DRAFTER_DIR_KINDS = ("mtp", "dspark")@@ -2207,6 +2226,7 @@ def detect_gguf_model(path: str, model_root: Optional[str] = None) -> Optional[sif (_is_mmproj(p.name)or _is_local_mtp_drafter(p, root, rel)+ or _is_imatrix_path(p.name)or _is_big_endian_gguf_path(rel, quant)# Pointed at directly, a sidecar bypasses the scan that would have skipped it.# Identified positively so an unreadable file still reaches the lock window below.@@ -2231,6 +2251,7 @@ def detect_gguf_model(path: str, model_root: Optional[str] = None) -> Optional[sif (_is_mmproj(f.name)or _is_local_mtp_drafter(f, root, context_rel)+ or _is_imatrix_path(f.name)or _is_big_endian_gguf_path(context_rel, quant)):continue@@ -2734,6 +2755,10 @@ def list_gguf_variants(# MTP drafters are speculative-decoding companions, not quants.if _is_mtp_drafter(fname):continue+ # An imatrix is calibration data, not a quant: listed, it becomes an+ # unlabelled ~13 MB row (unsloth/Qwen3.8-27B-GGUF ships imatrix_unsloth.gguf).+ if _is_imatrix_path(fname):+ continuelabel = _extract_quant_label(fname)if _is_big_endian_gguf_path(fname, label):@@ -2825,6 +2850,8 @@ def list_local_gguf_variants(# Recurse so variant-specific subdirs (``BF16/...gguf``) are picked up. Result filenames# keep the relative subpath so ``_find_local_gguf_by_variant`` can locate the file again.for f in sorted(_iter_gguf_files(p, recursive = True)):+ if _is_imatrix_path(f.name):+ continueif _is_mmproj(f.name):has_vision = Truecontinue@@ -2924,7 +2951,7 @@ def _find_local_gguf_by_variant(owned = []for f in _iter_gguf_files(p, recursive = True):rel = f.relative_to(p).as_posix()- if _is_mmproj(f.name) or _is_local_mtp_drafter(f, root, rel):+ if _is_mmproj(f.name) or _is_local_mtp_drafter(f, root, rel) or _is_imatrix_path(f.name):continuequant = _extract_quant_label(rel)fallback_variant = re.sub(r"-\d{3,}-of-\d{3,}$", "", rel.rsplit(".", 1)[0])@@ -2966,7 +2993,12 @@ def _detect_gguf_from_hf_cache(repo_id: str) -> Optional[str]:for f in _iter_gguf_files(snap, recursive = True):rel = f.relative_to(snap).as_posix()quant = _extract_quant_label(rel)- if _is_mmproj(f.name) or _is_mtp_drafter(rel) or _is_big_endian_gguf_path(rel, quant):+ if (+ _is_mmproj(f.name)+ or _is_mtp_drafter(rel)+ or _is_imatrix_path(f.name)+ or _is_big_endian_gguf_path(rel, quant)+ ):continuerel_files.append(rel)if rel_files:@@ -3000,6 +3032,7 @@ def detect_gguf_model_remote(repo_id: str, hf_token: Optional[str] = None) -> Opif (_is_mmproj(fname)or _is_mtp_drafter(fname)+ or _is_imatrix_path(fname)or _is_big_endian_gguf_path(fname, quant)):continue@@ -3249,8 +3282,13 @@ def scan_exported_models(if not run_dir.is_dir():continue- # Flat GGUF export (exports/...-gguf/); mmproj files aren't loadable as main models.- gguf_files = [f for f in _iter_gguf_files(run_dir) if not _is_mmproj(f.name)]+ # Flat GGUF export (exports/...-gguf/); neither mmproj files nor the imatrix an+ # imatrix export leaves beside the weights are loadable as main models.+ gguf_files = [+ f+ for f in _iter_gguf_files(run_dir)+ if not _is_mmproj(f.name) and not _is_imatrix_path(f.name)+ ]if gguf_files:base_model = Noneexport_meta = run_dir / "export_metadata.json"