Skip to content

metal: open an mlx-community folder as downloaded (-m <folder>, --hf), with no prepare step - #880

Merged
midagedev merged 6 commits into
mainfrom
mac-dopen
Oct 27, 2026
Merged

midagedev merged 6 commits into
mainfrom
mac-dopen

Conversation

@midagedev

Copy link
Copy Markdown
Owner

What

On a Mac, bloomery-serve-metal and generate_metal open an mlx-community 4-bit folder as downloaded, with no
bloomery-prepare step: --hf mlx-community/<repo> or -m <folder>. This is the CUDA side's principle (a checkpoint
folder as downloaded) applied to Metal.

  • model_hf::ModelFile / Weights (new): one owner for "this path is a GGUF split or a checkpoint folder".
    Weights::bytes(name) lends a split's mapped bytes (no new copy) or gives the folder's normalised part. An unknown
    name or an empty directory is refused by name.
  • Metal loader: reads each site through Weights and writes its spans straight into the site's buffer.
    Session::open_model and instance_of_model are new; open(path) and instance_of(path) wrap them.
  • Binaries: model_arg names the model once (-m, --hf, BLOOMERY_REF_MODEL). The served alias defaults to the
    folder's or the repo's name instead of a fixed qwen35moe.
  • Docs: docs/mac.md, docs/contrib/mac.md and README give the MLX path as --hf or -m. prepare stays, to
    write one split.

Mapping the folder in place is not possible. The folder stores codes, scales and biases as three planes, and the kernels
read 36-byte interleaved blocks; the tensors' offsets are also unaligned. So the open repacks once, the same bytes
prepare writes.

Evidence (second M1 Pro, [dev])

  • New e2e clause m_mlx_folder. On both fixture rows (qwen35moe, qwen3moe), the MLX folder gives the same plan lines,
    24 ids and first-step logits, bit for bit, as its prepared split. Mutants M-a, M-b and M-c are each red on both rows.
  • model-hf's hw_a_* tests hold every tensor's bytes from the folder equal to its split's. lab-metal-e2e now runs
    them.
  • just lab-metal and just lab-metal-e2e rc 0. Clippy -D warnings on the three builds. Metal lib 82 passed,
    model-hf lib 81 passed.
  • Real folders:
    • The Qwen3-30B-A3B 4-bit folder gives the same first 8 ids as its split, through both -m and --hf (from the hub
      cache).
    • So does Qwen3.6-35B-A3B 4-bit.
    • A bloomery-serve-metal -m <folder> chat reply equals generate_metal's text on the same prompt.
  • 30B open: 11.3 s warm from the folder, against 36.6 s from its split, on the same machine in the same order. Peak RSS
    is 17.4 GB.
  • Box, fixture tier, --round-ledger: gate-model-hf, gate-prepare and gate-prepare-corpus, red 0. tools/recipes.py reach finds no gate that reads model_file.rs or lib.rs through a dependency. The two read it as their own target.
    check-levers is ok.

AI use: written and checked with Claude Code.

🤖 Generated with Claude Code

midagedev and others added 5 commits October 28, 2026 00:56
…ights reads either's tensors by name

One owner for the choice the Metal open and the CUDA side both make. Under
a split the bytes are the mapped run (no new copy); under a folder they are
the folder's normalised part. An unknown name or an empty directory is
refused by name.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…as downloaded

The loader reads each site through Weights (a split's mapped bytes, or the
folder's parts) and writes its spans straight into the site's buffer.
Session::open_model and instance_of_model are new; open and instance_of wrap
them over a path. The e2e gate's m_mlx_folder clause holds each fixture
row's MLX folder to its prepared split (plan lines, 24 ids, the first step's
logits bit for bit), and lab-metal-e2e runs model-hf's fixture tests first.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-m or --hf, with no prepare step

model_arg owns the naming: -m, --hf and BLOOMERY_REF_MODEL name a model once,
--hf resolves a repo into the hub cache, and the served alias defaults to the
folder's or the repo's name. docs/mac.md gives the MLX path as --hf or -m and
leaves prepare as the way to write a split.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added documentation Improvements or additions to documentation tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo labels Oct 27, 2026
github-actions[bot]
github-actions Bot previously approved these changes Oct 27, 2026

@github-actions github-actions Bot 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.

Verdict: CLEAN: I built no failure path that the code does not block, and I found no proven duplicate, unneeded element or moved gate.

Non-blocking

⚠ Fetch events are hand-formatted as record lines: crates/metal/src/model_arg.rs:82 prints hf set …, hf checkpoint …, hf file … and the others as strings. crates/gpu-gates/src/model_file/fetch.rs:40 prints the same events through the Kinds HF_SET, HF_CHECKPOINT and the rest. If a Kind changes its keys, the Metal lines drift with no gate noticing. Direction: use the Kinds if bloomery-metal can take that dependency without CUDA. If it cannot, say so in the module doc.

⚠ A second owner of "path is a split or a folder": crates/model-hf/src/model_file.rs:63 decides is_dir(), then folder::open or Split::open, with the error texts checkpoint folder {path}: … and open {path}: …. crates/gpu-gates/src/model_file.rs:77 (header, read_folder) makes the same decision with the same texts. The PR body calls ModelFile "one owner". Direction: a later change moves header onto ModelFile::open, or a sentence says why the two stay apart.

⚠ crates/metal/src/bin/generate_metal.rs:826 lists "--ctx", "-m", "--hf" as a literal beside PATH_FLAGS. A new path spelling would be refused as a generation flag under --plan. Build the list from PATH_FLAGS.

⚠ Question: Sources::GgufOrCheckpoint (crates/metal/src/model_arg.rs:67) fetches any safetensors repo before the Metal check can refuse its architecture. Does --hf <bf16 repo> download the whole repo first and then refuse by name?

Checked

  • Duplicates: 14 new items checked. Hits: the two ⚠ above. dryer found 0 pairs.
  • Complexity: open_model_as (new, 17) is the old open_as body moved. generate, plan_run and open each gain one branch. mac::main +1 is one match arm. No split needed.
  • Silent failure: 7 sites followed. Each ends in a named refusal or a bounds check.
  • Hot path: load time only. No performance finding.
  • Tests: for m_mlx_folder, a loader that drops a span or reorders planes turns the bit-exact logits clause red. For a_split_lends_its_mapped_bytes, a copy turns ptr::eq red.
  • Gates: no pin moved. The new hw_a_ tests are #[ignore]d. Escape catalog: no match.

Notes

  • Evidence is from an M1 Pro, not an NVIDIA card. The PR changes no CUDA path.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

…ias is the model's name

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

@github-actions github-actions Bot 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.

Verdict: CLEAN: the new commit only lowers two model-tax counts, and both new counts match the code.

Since the last review:

  • ⚠ Fetch events hand-formatted in model_arg.rs: still open. The new commit does not touch it.
  • ⚠ Second owner of "split or folder" (model_file.rs and gpu-gates): still open.
  • ⚠ --ctx, -m, --hf literal beside PATH_FLAGS in generate_metal.rs: still open.
  • ⚠ Question on GgufOrCheckpoint fetching a whole repo before the architecture refusal: no answer yet.

Checked

  • Duplicates: no new items in this commit.
  • Gates: tools/model-tax.tsv:136 and :137 fall (3 to 1, 2 to 1). The ratchet is two-sided, and a fall needs no PIN. I counted the family token lines in the PR tree. bloomery_serve_metal.rs has 1 code line (line 51). generate_metal.rs has 1 (line 115). Both match.
  • Complexity: no code change in this commit.
  • Silent failure, hot path, escape catalog: nothing in scope.

Notes

  • Evidence is from an M1 Pro, not an NVIDIA card. The PR changes no CUDA path.

🔨 Shingler, bloomery's review bot: approves a clean pull request and requests changes on a must-fix (how it works)

@midagedev
midagedev merged commit 196ecb8 into main Oct 27, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation tools Tools, recipes, CI and the toolchain: tools/, justfile, .github/, Cargo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant