Skip to content

Fix duplicate GGUF rows in custom model folders - #9975

Merged
mahiatlinux merged 22 commits into
unslothai:mainfrom
Imagineer99:fix/studio-custom-gguf-dedup
Aug 30, 2026
Merged

mahiatlinux merged 22 commits into
unslothai:mainfrom
Imagineer99:fix/studio-custom-gguf-dedup

Conversation

@Imagineer99

Copy link
Copy Markdown
Member

Summary

  • prevent a custom GGUF model directory from also appearing as individual LM Studio compatibility rows
  • suppress only immediate child GGUF files when a complete grouped directory already represents them
  • preserve partial cache rows and the standard publisher/model LM Studio layout

Reproduction

Register a custom scan root containing model-name/model-q4_k_m.gguf. Before this change the picker shows both the model-name group and the nested GGUF file as separate top-level models. After this change it shows only the grouped model and keeps the GGUFs available as variants.

Regression coverage

A deterministic baseline/fix matrix covered 11 layouts including loose GGUFs, direct model roots, grouped variants, standard LM Studio publisher/model folders, mixed formats, safetensors, symlinks, and overlapping custom roots.

Tests

  • 279 passed in studio/backend/hub/tests/test_model_services.py
  • 43 passed in studio/backend/tests/test_local_model_format.py
  • ruff check on the changed service and tests
  • git diff --check

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-08-30T01:15:59.096821Z a2933c6 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6b3cbecec8

ℹ️ 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".

@mahiatlinux
mahiatlinux self-requested a review August 29, 2026 21:05
@mahiatlinux

Copy link
Copy Markdown
Contributor

Before and after

Before this PR, scanning a custom root that contained one grouped GGUF checkpoint plus its LM Studio-style loose files returned the directory row and duplicate Q4/Q8 file rows. The isolated pre-fix matrix reproduced the reported duplicate in 10 of 15 discovery cases. The original PR removed the basic duplicate, but still failed 4 of 15 cases and could hide two legitimate checkpoints that happened to share a quant label.

After the fixes, custom discovery selects one directory row only when the files are variants of the same checkpoint. Distinct loose checkpoints remain separate, and split shards collapse only when the loader confirms a complete colocated split. The shared rules now feed the Hub inventory, the compatibility models route, and the local auto-switch resolver.

Issues found and fixed

  • Distinct checkpoints sharing Q4_K_M, ambiguous names, or case/punctuation differences were collapsed. gguf_checkpoint_family() and should_group_local_gguf_files() now preserve exact checkpoint identity while grouping real quant variants (studio/backend/hub/utils/gguf.py:459-504).
  • Parent, child, overlapping, symlinked, and Windows-junction roots could emit the same physical model more than once. Physical filesystem identity and grouped-row suppression now account for lexical and resolved ancestry (studio/backend/hub/utils/gguf.py:474-483, 507-626).
  • Direct roots containing complete split GGUFs emitted one row per shard and reported one-shard size. They now use the loader's colocated_split_shards() decision and sum the complete set (studio/backend/hub/utils/gguf.py:629-683). Incomplete and noncanonical split-like files stay separate.
  • Nested roots could suppress legitimate loose models, especially independent models under quant-named directories. Suppression now requires matching physical files and checkpoint families (studio/backend/hub/utils/gguf.py:557-624, 721-789).
  • Companion files could create false model rows. MTP drafters, big-endian companions, mmproj, imatrix, and AppleDouble files are excluded from group ownership (studio/backend/hub/utils/gguf.py:537-555).
  • Deduplication was inconsistent across current and older Studio paths. The shared helpers are applied by Hub inventory (studio/backend/hub/services/models/local_inventory.py:812, 854-900), the compatibility route (studio/backend/routes/models.py:1142, 1158-1194), and auto-switch indexing (studio/backend/core/inference/local_model_resolver.py:458-471).
  • Ollama tags sharing one blob, identical tags in separate stores, and an LM Studio publisher literally named ollama could collide. Compatibility inventory now combines semantic Ollama identity with the physical linked blob only for real Ollama link layouts (studio/backend/routes/models.py:1160-1173).
  • The filesystem-heavy final dedupe ran inline in an async inventory path. It now runs in the existing worker-thread boundary (studio/backend/hub/services/models/local_inventory.py:925-950).
  • Tightening split suffixes to five digits regressed existing terminal three-digit MTP shard families, while anchoring the marker at the filename end regressed supported pre-quant split names. Three-or-more digit markers remain one family in both positions; two-digit lookalikes stay independent (studio/backend/hub/utils/gguf.py:75, studio/backend/utils/models/model_config.py:2395).

Verification

  • Reproduction: pre-fix 15-case matrix, 10 failures and 4 passes with one platform-only skip; original PR, 4 failures and 11 passes; final candidate, all relevant cases pass.
  • Local focused tests: 328 Hub discovery/service tests passed; 321 compatibility, loading, MTP, and pre-quant split tests passed; 3 resolver overlap/loading tests passed.
  • Selection/loading paths: verified list_local_gguf_variants(), detect_gguf_model(), _find_local_gguf_by_variant(), compatibility inventory, and auto-switch indexing against real temporary filesystem layouts.
  • Covered grouped variants, legitimate loose models, direct roots, LM Studio publisher/model layouts, overlapping and nested roots, symlinks, renamed symlinks, mixed GGUF/safetensors, partial directories, complete/incomplete splits, MTP and big-endian companions, and quant-named independent checkpoints.
  • Platform matrix: Linux, macOS, and Windows on Python 3.10 and 3.13. Windows uses a real NTFS junction probe. POSIX symlinks and Windows separators are covered. WSL-relevant POSIX and Windows-spelled path handling is covered without claiming a real WSL runner.
  • Backwards compatibility: current Hub inventory, the older compatibility route, direct custom-root records, LM Studio layouts, and the existing three-digit MTP family behavior are covered.
  • Static checks: Ruff, git diff --check, and Python compilation passed.
  • Hardware and browser behavior are unchanged. Full UI and inference workflows were still run as part of the final fork CI; no PR-specific browser or GPU failure was found.
  • Focused fork CI: PR 9975 custom GGUF focused CI, all six Linux, macOS, and Windows jobs passed on Python 3.10 and 3.13.
  • Final full fork CI for source HEAD a2933c6bc6c50fb2587990b481122a04f99eb91a: fork PR checks. All 17 workflows completed: 12 passed, the conditional Kaggle GPU workflow skipped, and four reproduced failures already present on upstream main. Backend has the same CPU/source/dependency failures as upstream main; Core has the same unsloth_zoo MLX failures as upstream main; the UI MCP button failure matches the staging-base upstream run; and the macOS tiny-model nondeterminism matches current upstream main. The macOS and UI failures were rerun and reproduced unchanged. The earlier PR-specific pre-quant resolver failure is absent.

@mahiatlinux

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: a2933c6bc6

ℹ️ 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".

@mahiatlinux mahiatlinux left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reviewed and fixed, LGTM. full fork CI results

@mahiatlinux
mahiatlinux merged commit f6294f8 into unslothai:main Aug 30, 2026
37 of 46 checks passed
@mahiatlinux

Copy link
Copy Markdown
Contributor

Line-count breakdown

  • 969 of 1,353 added lines (72%) are tests. They do not run in Studio.
  • 334 lines implement the shared GGUF filesystem and deduplication rules.
  • 50 lines connect those rules to the three existing discovery/loading paths.
  • 7 lines were deleted.

This is not 1,353 lines of runtime behavior. The production diff is 384 additions and 7 deletions. The size comes mainly from regression coverage for custom roots, LM Studio layouts, overlapping and nested roots, symlinks and Windows junctions, split shards, companion files, mixed formats, partial directories, and distinct checkpoints sharing a quant label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants