Repository navigation
Studio: never offer a calibration imatrix as a GGUF variant - #9409
Conversation
unsloth/Qwen3.8-27B-GGUF publishes its imatrix as imatrix_unsloth.gguf (most repos use imatrix_unsloth.dat or .gguf_file, which a GGUF listing never sees). Carrying a real .gguf suffix, it reached every GGUF surface as if it were weights: the chat model picker showed a ~13 MB row labelled GGUF, since the quant extractor finds no token in the name, and that row was downloadable and then unloadable. An imatrix holds per-tensor activation statistics for llama-quantize, not a model, and llama-server never opens one, so it is excluded outright rather than carried as a companion the way mmproj and the MTP drafter are: it is dropped from remote and local variant listings, from download plans, from the cache and inventory scans, from detect_gguf_model and from the diffusion LoRA pick. A copy an older build already fetched as a variant is reclaimed with the repo's last variant, since nothing can reach it from the UI any more. Matched on a leading or trailing stem token, never a substring, so a real model whose name contains the word stays selectable.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 45b94696b9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for expected in manifest.expected_files: | ||
| if not is_gguf_filename(expected.path): | ||
| continue | ||
| if is_imatrix_filename(expected.path): |
There was a problem hiding this comment.
Drop imatrix-only state entries instead of synthesizing a row
When an older Studio build left an interrupted manifest whose only expected file is imatrix_unsloth.gguf, this branch skips that file but leaves main_filename unset; the fallback below then creates <variant>.gguf and appends a zero-byte selectable variant. Consequently, offline or failed-metadata recovery still offers the calibration matrix that this change is intended to hide. Skip the entire stored variant when its manifest contains no eligible main GGUF.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and reachable: an older build offered the imatrix as its own variant, so a cancelled download of it can still be on disk, and this listing is the offline path that would show it again. Fixed in f4df486: a stored variant whose manifest names no eligible main GGUF is dropped instead of falling back to a synthetic .gguf, and the variant key itself is checked too, since a cancel marker carries no manifest to inspect. A real quant's marker-only row still stands so an interrupted download stays resumable. Both cases are locked by tests in test_imatrix_gguf_filtering.py that fail without the change.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 099836f7d9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| _is_gguf_filename(name) | ||
| and not _is_mmproj_filename(name) | ||
| and not _is_mtp_drafter_path(name) | ||
| and not _is_imatrix_filename(name) |
There was a problem hiding this comment.
Update the compatibility scanner's imatrix predicate
When an imatrix remains in an older HF cache or a local/LM Studio folder, the compatibility model routes still treat it as a primary weight: routes/models.py::_is_main_gguf_filename explicitly mirrors this helper but still excludes only mmproj and MTP, and its _is_model_directory likewise accepts any non-mmproj GGUF. Consequently /api/models/local can continue surfacing an imatrix-only directory or standalone imatrix as an unloadable GGUF model despite this new shared exclusion.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed: routes/models.py keeps its own _is_main_gguf_filename and _is_model_directory, and GET /models/local reads them through collect_local_models, so a standalone imatrix and an imatrix-only folder were still offered there. This PR is already merged, so the fix is in #9411: both now take the loader's _is_imatrix_path rather than a fourth copy of the rule, with a test that fails without it.
| # An imatrix is not adapter weights, and it would be the fallback pick below. | ||
| if not is_imatrix_filename(f) |
There was a problem hiding this comment.
Restrict imatrix filtering to GGUF fallback candidates
When a LoRA repository's valid root-level weight has a leading imatrix token, such as imatrix-tuned.safetensors, this pre-filter removes it even though the imatrix artifacts handled by this change are .dat/.gguf containers. If that is the repository's only weight, automatic LoRA resolution now raises FileNotFoundError; apply the predicate only while selecting GGUF fallback files rather than to the safetensors candidate list.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Agreed, the filter was wider than its purpose. An imatrix is a GGUF holding no adapter, so it belongs on the .gguf fallback pick only; a .safetensors is never one and should not have been filtered. Fixed in #9411, since this PR is merged.
Skipping the imatrix among a stored manifest's expected files left main_filename unset, so the synthetic <variant>.gguf fallback re-created the row at zero bytes. An older build could download the imatrix as a variant of its own, so its interrupted state is on disk and the offline listing is exactly where it would reappear. A cancel marker carries no manifest, so the stored variant key is checked too. A real quant's marker-only row still stands, or an interrupted download could not be resumed or deleted.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f4df486bbf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| gguf_files = [ | ||
| f | ||
| for f in _iter_gguf_files(run_dir) | ||
| if not _is_mmproj(f.name) and not _is_imatrix_path(f.name) |
There was a problem hiding this comment.
Filter imatrices from two-level exports too
When an export uses the supported {run}/{checkpoint}/ layout and the checkpoint contains only imatrix_unsloth.gguf, this root-level scan finds nothing because _iter_gguf_files is non-recursive, but the two-level branch below still sets has_gguf from the unfiltered file list and returns that imatrix as the model path. Apply the same imatrix exclusion when computing has_gguf and gguf_list, otherwise the exported-model picker can still expose an unloadable calibration file.
Useful? React with 👍 / 👎.
* Exclude the imatrix from the local models route too GET /models/local keeps its own copies of these predicates in routes/models.py, so #9409 left a standalone imatrix_unsloth.gguf, and an imatrix-only folder, still offered in the picker as loadable GGUF models. _is_main_gguf_filename and _is_model_directory now take the same _is_imatrix_path the loader uses instead of a fourth spelling of the rule. Narrow the diffusion LoRA filter to the .gguf fallback it was written for. An imatrix is a GGUF holding no adapter; a .safetensors never is, so filtering the whole listing also dropped safetensors candidates and a repo whose only weight led with the token resolved to FileNotFoundError. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Cover the Downloaded list, the surface a fetched imatrix comes back on * Keep an imatrix from making a folder look like a model The child scanners decide presence from any .gguf, not from the predicates, so a models dir or LM Studio folder holding only imatrix_unsloth.gguf published a row a loader cannot start. An interrupted download reaches that state easily: the imatrix is the smallest file in the repo. Presence now asks _servable_gguf_names, which drops an imatrix and keeps mmproj and MTP drafters. Those are companions of a real model and the scanners have always let them decide presence but never format, so that line stays where it is. * Pin where the imatrix rule stops: a config still lists its folder * Keep the recommended-folder probe mirroring the scanners _dir_has_downloaded_model exists so a Recommended chip never opens an empty picker, and it says so: weight detection mirrors the local scanner. Once the scanners stopped surfacing an imatrix-only folder, an unfiltered probe here advertised one. * Tighten the comments this PR adds --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
…uf (unslothai#14931) Fixes unslothai#14695 (the part of it Studio controls). ## Problem Since unslothai#9409, Studio treats any GGUF whose name ends in `-imatrix` as a llama-quantize calibration file and drops it from the variant menu, download plan and loader. That rule also matches a common naming convention for imatrix-weighted quants, `<model>-<QUANT>-imatrix.gguf`, so whole repos lose their real weights: | Repo | Variants listed on main | After this PR | |---|---|---| | `elvezjp/DeepSeek-V4.1-Flash-1017-ELVEZ-Q2-gguf` (unslothai#14695) | `DSpark` 7.9 GB, `Vision` 1.0 GB (main 366 GB weight hidden) | `IQ2_XXS` 365.7 GB, `DSpark`, `Vision` | | `Lewdiculous/Kunocchini-7b-128k-test-GGUF-Imatrix` | `F16` only | `F16`, `Q8_0`, `Q6_K`, ... (13) | | `FadedRedStar/Qwen3.5-4B-heretic-imatrix-GGUF` | none | `Q5_K_M`, `Q4_K_M`, `IQ4_NL` | | `jashepp/Ornith-1.5-35B-A3B-MXFP4_MOE_Hybrid-Imatrix-GGUF` | none | 3 MXFP4_MOE quants (18.5 to 20.7 GB) | In unslothai#14695 this hid the real model and left the 7.9 GB DSpark draft head as the only variant that fits a 32 GB Mac, which is what the reporter ended up loading. ## Fix llama.cpp only uses an imatrix while quantizing, so a quantized type label (`Q4_K_M`, `IQ2_XXS`, `Q8_0`, `MXFP4`, `TQ1_0`, ...) before the trailing `imatrix` token means imatrix-weighted weights, not calibration data. The trailing-token rule now skips such names. Float labels do not count (there is no imatrix-weighted F16), and the leading form (`imatrix.gguf`, `imatrix_unsloth.gguf`, `imatrix-fp16.gguf`) and `.imatrix` are unchanged. The canonical predicate and both mirrors (`utils/models/model_config.py`, `core/inference/llama_cpp.py`) change together; the existing three-copies agreement test covers the new names. Still recognised as an imatrix: `imatrix_unsloth.gguf`, `imatrix.gguf`, `imatrix-fp16.gguf`, `z-combined-imatrix.gguf`, `<model>.imatrix.gguf` (mradermacher), `<model>-BF16-imatrix.gguf`. ## Tests - `tests/test_imatrix_gguf_filtering.py`: new model and imatrix names, plus a remote-listing test for an imatrix-weighted repo. With the functional change reverted, 5 of the new cases fail; with it, all 56 pass. - 111 related backend test files (gguf, variants, drafters, inventory, picker, downloads, deletion, export): 4231 passed, 11 failed, the same 11 failing on the base commit (no `gguf` package and an unreleased diffusers pin in this environment). ## Before / after Model hub, `Lewdiculous/Kunocchini-7b-128k-test-GGUF-Imatrix` quant list (merge base 2eb94bc vs this PR, two fresh Studio installs). Before: only the F16 file (1 row). After: F16 plus the Q8_0 ... IQ4_XS imatrix-weighted quants (13 rows). 
The bug
Searching the chat model picker for
https://huggingface.co/unsloth/Qwen3.8-27B-GGUF/tree/mainreturns one row that is not a model: a ~13 MB entry labelled just GGUF. It isimatrix_unsloth.gguf, the repo's calibration importance matrix.Most of our GGUF repos publish it as
imatrix_unsloth.datorimatrix_unsloth.gguf_file, and neither suffix reaches a GGUF listing. Some repos publish the same file as a plain.gguf(unsloth/Qwen3.8-27B-GGUF,unsloth/Qwen3.5-122B-A10B-GGUF), and there it flowed through every GGUF surface as if it were weights. The quant extractor finds no quant token inimatrix_unsloth, so the row falls back to the bare "GGUF" label, and it is offered for download and then fails to load.Reproduced before the fix:
The fix
An imatrix holds per-tensor activation statistics for
llama-quantize.llama-servernever opens one, so it is not a selectable variant and, unlike mmproj or the MTP drafter, not a companion worth fetching either: it is excluded outright.is_imatrix_filenamejoinsis_mmproj_filename/is_mtp_drafter_pathinhub/utils/gguf.pyand is applied everywhere they are:pick_best_gguf, and the manifest-based partial listingbuild_gguf_variant_plans,is_main_gguf_variant_path), so no plan fetches one and the advertised download size does not include itdetect_gguf_modeland the local/remote best-GGUF picks inmodel_config.py, so a folder holding one cannot route it as the main model, including the copy an imatrix export leaves inexports/.ggufwas the last-resort candidateThe rule is spelled three times (hub,
utils/models/model_config.py,core/inference/llama_cpp.py) because utils cannot import hub and core avoids it, matching how the mmproj and MTP predicates are already mirrored. A test asserts the three copies agree on every name.Matching is anchored at a leading or trailing stem token, never a substring, so every published spelling is caught (
imatrix.gguf,imatrix_unsloth.gguf,imatrix_unsloth.gguf_file,<model>-imatrix.gguf,<model>.imatrix) while a real model whose name happens to contain the word (Qwen3-Imatrix-Tuned-Q4_K_M.gguf) stays selectable.After the fix the same repo lists 25 rows, all of them real quants, with no imatrix entry.
Tests
New
studio/backend/tests/test_imatrix_gguf_filtering.py(28 cases): every published spelling recognised, real weights untouched, the three predicate copies in agreement, and the imatrix absent from the remote listing, the local listing, the download plan anddetect_gguf_model.ruff check studiopasses. The GGUF, model, inventory, download, deletion, variant, quant, export, MTP, mmproj and LoRA suites run 4306 passed; the 12 remaining failures are pre-existing torchao/diffusers environment mismatches on this box and fail identically onmain.