Skip to content

refactor(lm): replace the GGUF file-name regexes with parsers - #340

Merged
Brooooooklyn merged 1 commit into
fix/download-gguf-load-hintfrom
refactor/gguf-name-parsers
Nov 9, 2026
Merged

Brooooooklyn merged 1 commit into
fix/download-gguf-load-hintfrom
refactor/gguf-name-parsers

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Contributor

Stacked on #339 (base fix/download-gguf-load-hint). Merge #339 first; GitHub then retargets this PR to main.

What

Every GGUF file-name rule now lives in one native-free module, packages/lm/src/gguf-name.ts. No regex is left for GGUF names.

Old regex Where New parser
GGUF_COMPANION_NAME /(?:^|[-_.])(?:imatrix|mmproj|dflash|draft|mtp)(?:[-_.]|$)/i model-discovery.ts isGgufCompanionName: split on - _ .; a token equal to a companion word (any case)
QWEN35_XL_GGUF model-discovery.ts isQwen35XlGgufName: the name ends with Q<digits>_K_XL / Q<digits>_K_M / one of 11 IQ tags, at the start or after - _ .
BONSAI_PQ2_GGUF model-discovery.ts isBonsaiPq2GgufName: lower-case compare
split name (from #339) model-discovery.ts parseGgufFileName, moved unchanged
/^dflash-.*\.gguf$/i scripts/benchmark-muse-gguf.ts startsWith('dflash-') && endsWith('.gguf')

model-discovery.ts re-exports isGgufCompanionName and parseGgufFileName, so the CLI and dashboard imports do not change.

Same behavior

A one-off check compared old regex vs new parser on 6,431,258 generated names (tags, case mixes, separators, /, split suffixes, extensions): 0 differences. The check is not committed, so the repo holds no copy of the old regexes.

Tests

  • New packages/lm/__test__/gguf-name.test.ts (split names moved from model-discovery.test.ts, plus companion, Qwen3.5 XL, Bonsai cases).
  • vp test on gguf-name, model-discovery, dashboard models, and the CLI download tests: 173 passed. yarn typecheck and vp lint --type-aware --type-check are clean.

Not GGUF names, so not changed: PRIMARY_SAFETENSORS (model-discovery.ts), the safetensors shard regexes in packages/server/src/host/checkpoint-files.ts and packages/cli/src/commands/download-sync.ts.

🤖 Generated with Claude Code

New native-free module packages/lm/src/gguf-name.ts holds every GGUF name
rule; model-discovery re-exports the public ones, so callers keep their
imports.

- isGgufCompanionName: tokens split on - _ . ; a token equal to
  imatrix/mmproj/dflash/draft/mtp (any case) marks a companion
- isQwen35XlGgufName: the name ends with Q<digits>_K_XL, Q<digits>_K_M, or
  one of 11 IQ tags, at the name start or after - _ .
- isBonsaiPq2GgufName: exact lower-case compare
- parseGgufFileName: moved here unchanged
- scripts/benchmark-muse-gguf.ts: dflash prefix by startsWith/endsWith

Same results as the old regexes on 6.4M generated names (one-off check).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T14:38:02.496522Z dea54fb PR opened
ℹ️ 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.

@coderabbitai

coderabbitai Bot commented Nov 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0704dc08-d1ee-4ffd-b38a-0d4eacffe417

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@Brooooooklyn
Brooooooklyn merged commit 225eb9e into fix/download-gguf-load-hint Nov 9, 2026
1 check passed
@Brooooooklyn
Brooooooklyn deleted the refactor/gguf-name-parsers branch November 9, 2026 01:41
Brooooooklyn added a commit that referenced this pull request Nov 9, 2026
Stacked on #340, which is stacked on #339. Merge in order: #339, #340,
then this PR. CI runs only on PRs to `main`, so this PR gets CI after
GitHub retargets it.

## Problem

`mlx download model -m unsloth/Qwen3.8-Flash-Next-GGUF -g
"*UD-Q4_K_XL*"` keeps repo paths:

```
<modelsDir>/qwen3.8-flash-next-gguf/
  README.md, .mlx-download-complete.json
  UD-Q4_K_XL/Qwen3.8-Flash-Next-UD-Q4_K_XL-0000{1..4}-of-00004.gguf
```

`discoverLocalChatModels` read only `<modelsDir>/*.gguf` and
`<modelsDir>/<repo>/*.gguf`. For this layout the repo folder has no
config.json, so it was skipped and the model was invisible to `mlx
serve`, `mlx agent`, and the dashboard coding-agent list. With a root
config.json (from `--assets-repo`), the repo folder itself was
registered as a model with no weights. DeepSeek V4.1 Flash uses the same
layout.

## Fix

Only the folder branch of `discoverLocalChatModels` changes
(`packages/lm/src/model-discovery.ts`):

```
<modelsDir>/<repo>/
  primary safetensors        → as before (config.json path); never searched deeper
  top-level target GGUF      → as before
  else → scan <repo>/<variant>/*.gguf   (one level, sorted, no dot-folders)
           a variant target found → list it; <repo> itself is not a model
           none, root has a GGUF (mmproj only) → skipped, as before
           none                 → config.json path, as before
```

- Names: the file stem, as before. A clash gets the `<repo>-` prefix, as
before.
- Sidecars (`requiresAssets`, Gemma4/Muse) are still checked beside the
GGUF, which matches the loader.
- An unreadable variant folder is reported through `onEntryFailure` and
does not hide its siblings.

## Real check

Discovery over my real `~/.mlx-node/models` (75 models), old vs new: one
added line, nothing else changed.

```
> Qwen3.8-Flash-Next-UD-Q4_K_XL-00001-of-00004  qwen3.8-flash-next-gguf/UD-Q4_K_XL/...-00001-of-00004.gguf  qwen4_exp
```

## Tests

9 new cases in `packages/lm/__test__/model-discovery.test.ts`: Flash
Next layout, root config.json, mmproj-only root, two variants with a
clashing name, depth limit and top-level priority, skipped folders (MTP,
dot, assets, safetensors-owned), symlinked and dangling variant links,
Gemma sidecars beside the variant, unreadable variant. 7 of them fail on
the old code; the other 2 are guards.

`vp test` on model-discovery, gguf-name, agent models, server discover,
dashboard models: 161 passed. `yarn typecheck` and `vp lint --type-aware
--type-check` are clean.

## Not in this PR

The dashboard catalog checks (`isModelPresent`, `isModelInstalled` in
`packages/dashboard/src/models.ts`) read only the model folder's top
level. No catalog entry is nested today, so nothing is wrong now. They
need the same rule if Flash Next or DeepSeek V4.1 Flash joins the
catalog.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

1 participant