Repository navigation
refactor(lm): replace the GGUF file-name regexes with parsers - #340
Conversation
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]>
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
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]>
Stacked on #339 (base
fix/download-gguf-load-hint). Merge #339 first; GitHub then retargets this PR tomain.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.GGUF_COMPANION_NAME/(?:^|[-_.])(?:imatrix|mmproj|dflash|draft|mtp)(?:[-_.]|$)/imodel-discovery.tsisGgufCompanionName: split on-_.; a token equal to a companion word (any case)QWEN35_XL_GGUFmodel-discovery.tsisQwen35XlGgufName: the name ends withQ<digits>_K_XL/Q<digits>_K_M/ one of 11IQtags, at the start or after-_.BONSAI_PQ2_GGUFmodel-discovery.tsisBonsaiPq2GgufName: lower-case comparemodel-discovery.tsparseGgufFileName, moved unchanged/^dflash-.*\.gguf$/iscripts/benchmark-muse-gguf.tsstartsWith('dflash-') && endsWith('.gguf')model-discovery.tsre-exportsisGgufCompanionNameandparseGgufFileName, 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
packages/lm/__test__/gguf-name.test.ts(split names moved frommodel-discovery.test.ts, plus companion, Qwen3.5 XL, Bonsai cases).vp teston gguf-name, model-discovery, dashboard models, and the CLI download tests: 173 passed.yarn typecheckandvp lint --type-aware --type-checkare clean.Not GGUF names, so not changed:
PRIMARY_SAFETENSORS(model-discovery.ts), the safetensors shard regexes inpackages/server/src/host/checkpoint-files.tsandpackages/cli/src/commands/download-sync.ts.🤖 Generated with Claude Code