Skip to content

fix(cli): print one load or convert hint per GGUF model, not per shard - #339

Merged
Brooooooklyn merged 5 commits into
mainfrom
fix/download-gguf-load-hint
Nov 9, 2026
Merged

Brooooooklyn merged 5 commits into
mainfrom
fix/download-gguf-load-hint

Conversation

@Brooooooklyn

@Brooooooklyn Brooooooklyn commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem

After mlx download model -m unsloth/Qwen3.8-Flash-Next-GGUF -g "*UD-Q4_K_XL*" the CLI printed:

To convert GGUF to MLX SafeTensors format:
  mlx convert -i .../UD-Q4_K_XL/...-00001-of-00004.gguf -o <dir>-mlx
  mlx convert -i .../UD-Q4_K_XL/...-00002-of-00004.gguf -o <dir>-mlx
  ... one line per shard

Each line is wrong:

Fact Where
mlx convert reads only the file it is given, so shard 1 alone gives a model with only its own tensors crates/mlx-core/src/utils/gguf.rs convert_gguf_to_safetensors_inner; docs/convert-quantize.md trap #13
Shards 2..N have no general.architecture (llama.cpp split puts metadata in split 0 only) checked on the real Flash Next shard headers
All lines share one -o, so each run replaces the last one packages/cli/src/commands/convert.ts commitStagedOutput
qwen4exp / deepseek41 need no conversion: the native loader opens shard 00001 and reads the other shards qwen4_exp/weights.rs index_gguf; docs/qwen38-flash-next.md

Fix

ggufNextSteps() replaces the per-file loop:

weightFiles → ggufLoadEntries()  one entry per split set (shard 00001) or single file
            → readGgufArchitecture(entry)
            → family in ggufArchitectures (split sets: only when ggufDiscovery.split)?
                 yes        → "Load directly: <path>"  (+ --assets-repo note when config.json/tokenizer.json are missing for requiresAssets families)
                 no, split  → llama-gguf-split --merge, then mlx convert
                 no, single → mlx convert, own -o per model when there are several
            → split set with missing shards → "Incomplete split GGUF" line

Output for the Flash Next download now:

Load directly (no conversion needed):
  ~/.mlx-node/models/qwen3.8-flash-next-gguf/UD-Q4_K_XL/Qwen3.8-Flash-Next-UD-Q4_K_XL-00001-of-00004.gguf (reads the other 3 shard(s) beside it)

Only the printed hint changes. Download, sync, and marker logic are not touched.

Split-name parser (no regex)

parseGgufFileName() in packages/lm/src/model-discovery.ts reads <stem>-NNNNN-of-NNNNN.gguf right to left (5-digit count, -of-, 5-digit ordinal, -). Anything else is a single file.

Call site Before After
CLI hint (ggufLoadEntries) new regex parser
Discovery (supportedGgufName) /-(\d{5})-of-(\d{5})\.gguf$/i parser, same rules (shard 00001, 1..1024, ggufDiscovery.split)

New discovery test: only shard 00001 of a qwen4exp split set is listed; a clef split set and an -00002-of-00001 name are refused.

Other GGUF-name regexes stay (QWEN35_XL_GGUF, BONSAI_PQ2_GGUF, GGUF_COMPANION_NAME): they match quant tags or tokens, not split names.

Tests

  • New __test__/cli/download-gguf-next-steps.test.ts: split collapse, direct split load (qwen4exp), merge path (qwen35 split), gemma4 assets note, unique -o per variant, unreadable header fallback, incomplete split.
  • vp test on the 4 download test files: 75 passed. yarn typecheck and vp lint --type-aware --type-check are clean.

Not in this PR (found during research)

mlx serve model discovery scans <modelsDir>/<entry>/*.gguf only one level deep, so the nested layout <modelsDir>/qwen3.8-flash-next-gguf/UD-Q4_K_XL/*.gguf that mlx download creates is not found (packages/lm/src/model-discovery.ts modelFileInventory). This needs a separate decision.

🤖 Generated with Claude Code

After a GGUF download the CLI printed `mlx convert -i <shard> -o <dir>-mlx`
once per weight file. For a split set that is wrong in three ways:
`mlx convert` reads only the file it is given, shards 2..N carry no
architecture, and every line shared one output dir, so each run replaced
the previous one. Qwen3.8 Flash Next (and DeepSeek V4.1 Flash) also need no
conversion: their native loader opens shard 00001 and reads the rest.

`ggufNextSteps` now collapses each split set to shard 00001, reads the
GGUF architecture, and prints:
- "Load directly" for families listed in `ggufArchitectures` (split sets
  only when the family allows splits), with an `--assets-repo` note when a
  family needs config.json + tokenizer.json beside the file
- merge-then-convert for split sets with no split-aware loader
- one convert line per model, with its own output dir when there are several
- an "incomplete split" line when the selection lacks shards

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@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: 69b45eb2-eb08-45bb-ab66-7a08d431f81a

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

@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-09T01:43:11.459505Z 225eb9e New commits
ℹ️ 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: db8f02b7d5

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

Brooooooklyn and others added 3 commits November 7, 2026 17:22
…sets-repo

--assets-repo writes config.json/tokenizer.json to the output root, but the
gemma4/muse loaders read them beside the GGUF. For a GGUF in a variant
subfolder the old note sent the user to a fix that leaves loading broken.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…a regex

parseGgufFileName reads <stem>-NNNNN-of-NNNNN.gguf right to left: fixed
five-digit count, '-of-', five-digit ordinal, '-'. Anything else is a single
file. It also refuses an empty stem, which the old pattern accepted.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The split-name regex in supportedGgufName did the same job as the CLI's
new parser. The parser now lives in model-discovery.ts (exported from
@mlx-node/lm and the model-discovery subpath) and both call sites use it.

Rules are unchanged: a split name must be shard 00001 of 1..1024 shards,
and a family needs ggufDiscovery.split for more than one shard. The parser
now accepts an empty stem, as resolve_gguf_shards and the old regex did.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Brooooooklyn
Brooooooklyn added this pull request to stack #349 November 9, 2026 02:47
@Brooooooklyn
Brooooooklyn merged commit b432f9e into main Nov 9, 2026
10 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/download-gguf-load-hint branch November 9, 2026 05:43
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