Skip to content

Latest commit

 

History

History
225 lines (186 loc) · 17.8 KB

mac.md

File metadata and controls

225 lines (186 loc) · 17.8 KB

bloomery on Apple Silicon

bloomery runs on a Mac's GPU through its own Metal backend: bloomery-serve-metal serves the llama-server HTTP API, and generate_metal runs one prompt from the command line. The host side is Rust; the kernels are Metal Shading Language. Two architectures run on a build after 0.3.9: qwen35moe (Qwen3.6-35B-A3B and files with its shapes) and qwen3moe (Qwen3-30B-A3B); a build after 0.3.10 adds lfm3 (LFM3-1.7B) (which files). The release carries a signed and notarized Apple Silicon build; building from source works too. The port's map and design are in contrib/mac.md and issue #593.

What you need

  • An Apple Silicon Mac with macOS 26.2 or newer; an older macOS is refused by name at the start (crates/metal/src/device.rs). Run on an M1 Pro and an M4 Pro 48 GB here, and on an M3 Ultra and an M5 Ultra by @avlp12 (#593).
  • Memory: after the open, the model holds 20.3 GB (MLX 4-bit) or 21.8 GB (Q4_K_M) of device memory at a 4,096-row context, measured on the M4 Pro. A 48 GB Mac is tested. A 32 GB Mac (M1 Pro) opened and decoded two other Q4_K_M files of this shape (below). The GPU working set Metal reports was 0.78 × RAM on the three Macs measured (24.96 GiB on an M1 Pro 32 GB, 37.44 GiB on an M4 Pro 48 GB); above 48 GB it is unverified.
  • To build from source: rustup, whose cargo comes first in PATH (Homebrew's rust builds with its stable compiler and fails on the pinned crates). rust-toolchain.toml pins the toolchain (stable 1.99.1), and rustup installs it on the first build. The Metal backend links no CUDA code, so plain cargo builds it. Xcode's Metal toolchain is optional: with xcrun metal the build writes a metallib, and without it the kernels compile from their embedded source when the binary starts (the release's binaries do this). Every number and gate here ran the source path; the metallib path builds, and its gates have not run on the maintainers' Macs. If you have the toolchain (xcodebuild -downloadComponent MetalToolchain), please run just lab-metal and report the output (why: contrib/mac.md, section 1.3).

Install

brew install midagedev/tap/bloomery
# or the installer: the latest release, sha256-checked, symlinks into ~/.local/bin
curl -fsSL https://raw.githubusercontent.com/midagedev/bloomery/main/tools/release/install.sh | sh

Both install bloomery-serve-metal, generate_metal and the converter as bloomery-prepare. The tarball bloomery-<version>-macos-arm64-metal.tar.gz on the releases page holds the same three binaries under bin/ (the converter as prepare). The commands below spell the source build's target/release/ paths; a Homebrew binary runs by its name, and an installer one as ~/.local/bin/<name> unless ~/.local/bin is on your PATH.

If Homebrew stops with "Your Command Line Tools are too outdated", update the Command Line Tools in Software Update, or use the installer line, which needs no build tools. The formula has no bottle, so Homebrew checks the build tools before it installs it. This was seen on macOS 27.0.1 with Command Line Tools 26.5.

Build from source

git clone https://github.com/midagedev/bloomery && cd bloomery
cargo build --release -p bloomery-metal --bin bloomery-serve-metal --bin generate_metal \
  -p bloomery-model-hf --bin prepare

Which files run

File State
Qwen3.6-35B-A3B, an MLX 4-bit folder verified on the 4-layer fixture split; the numbers are below
Qwen3.6-35B-A3B, Q4_K_M GGUF runs, unverified
Ornith-1.5-35B, Q4_K_M runs, unverified, text only: it has Qwen3.6's shapes, and its next-token layer is not read
MiniCPM-V 4.7 35B-A3B, Q4_K_M runs, unverified, text only: its mmproj is not read. Release 0.3.9 refuses it: qwen35moe arena: a vocabulary of 248144; the head reads 248320
Sage-A1.5, Q4_K_M runs, unverified; no Mac run is recorded on this page. It has Qwen3.6's shapes
Qwen3-30B-A3B-Instruct-2507, an MLX 4-bit folder verified on the 4-layer fixture split, on a build after 0.3.9, text only. Release 0.3.9 refuses it: architecture qwen3moe
Qwen3-30B-A3B-Instruct-2507, Q4_K_M runs, unverified, text only
Qwen3-Coder-30B-A3B-Instruct, an MLX 4-bit folder verified on a build after 0.3.10, text only, on Qwen3-30B-A3B's 4-layer fixture split: it has those shapes (qwen3moe), and the gate does not open its folder. Its XML tool calls parse into OpenAI tool_calls
Qwen3.6-35B-A3B UD-Q4_K_XL runs, unverified, text only. Release 0.3.9 refuses it: its Q8_0, Q5_K and f32 tensors
Qwen3.8-27B, an MLX 4-bit folder verified on a build after 0.3.10, text only, on a 4-layer cut of the folder in its stored bits (three delta layers, one attention layer, a dense FFN in each): its logits at positions 0 to 3 match mlx-lm's in f32 within 0.01
LFM3-1.7B, an MLX 4-bit folder verified on a build after 0.3.10, text only, on the whole folder: its logits at positions 0 to 3 match mlx-vlm's lfm3 in f32 within 0.06, and at seven steps from 255 to 599 of a 600-id walk (past its 256-key sliding window) within 0.02, with the same argmax

The mat-vec kernels run Q4_K, Q5_K, Q6_K, Q8_0 and MLX 4-bit weights, and f32 at the delta layers' ssm_alpha and ssm_beta. The gate verifies the MLX 4-bit path on the 4-layer fixture splits of Qwen3.6-35B-A3B and Qwen3-30B-A3B: their logits at positions 0 to 3 match mlx-lm's in f32 within 0.01. It opens no full folder. A full folder opens with the same code path. A GGUF file runs, unverified. A shared expert may have another type than its routed stacks. The router and the shared-expert gate may be F32 or MLX 8-bit, which the open dequantizes. Any other type is refused when the file opens, and the error names the tensor. A file whose shapes the kernels take but no build has registered compiles its kernels when it opens, and the server says that no gate checked that shape. The evidence for each row is in contrib/mac.md, section 1.1.

Get a model

  • An MLX 4-bit folder opens as downloaded, with no conversion step first. --hf mlx-community/<repo> fetches the repo into the cache ($BLOOMERY_CACHE, else ~/.cache/bloomery/hf) and opens it; -m <folder> opens a folder you already have. Three folders run:

    The open picks the map by the folder's model_type, keeps MLX's 4-bit and 8-bit weights as they are stored, and checks the tokenizer against the folder's. It writes nothing to disk.

  • A Q4_K_M GGUF opens directly, for example Qwen3.6-35B-A3B-Q4_K_M.gguf from lmstudio-community/Qwen3.6-35B-A3B-GGUF, by -m or by --hf owner/name:Q4_K_M.

prepare is optional. It writes a folder as one GGUF split, for those who want a single file. A split and its folder open with the same weights. The split is the folder's size (19.5 GB or 17.2 GB), and the conversion needs that much free disk plus about 10 %.

target/release/prepare PATH/Qwen3.6-35B-A3B-4bit --plan            # prints the plan, writes nothing
target/release/prepare PATH/Qwen3.6-35B-A3B-4bit OUT/qwen36-mlx4    # writes OUT/qwen36-mlx4-00001-of-00001.gguf

A quick check from the command line (the rates print on stderr, decode_tok_s=):

target/release/generate_metal --hf mlx-community/Qwen3-30B-A3B-Instruct-2507-4bit \
  --prompt "The capital of France is" -n 32
target/release/generate_metal -m PATH/Qwen3-30B-A3B-Instruct-2507-4bit --prompt "The capital of France is" -n 32

BLOOMERY_REF_MODEL names the model too, as the CUDA binaries read it. The model is named once: -m beside --hf, either flag twice, or a flag that differs from the variable is refused by name.

generate_metal --ignore-eos stops nothing at an end-of-generation id (off by default; the picks stay the device's argmax, so a decode timed on real text is not cut short), and --repeat N runs the prompt N times on one open (the session reset the server takes between runs), each run with its own summary block; a run whose ids differ from the first's ends the process with a named error.

generate_metal --draft lookup (off by default) runs the loop over the lookup draft: a pass proposes the one id the context's n-grams name and verifies it with the token at the position in one pass of two rows, keeping the rows the model's own argmax agrees with. The draft runs behind the width chooser the CUDA family's lookup runs behind (runtime::width::Choosing): BLOOMERY_MTP_WIDTH=cost (unset) reads each step's and each verify's wall off the host clock and verifies a proposal only while the rows the proposals keep repay the verify's extra wall, a step in its place otherwise; BLOOMERY_MTP_WIDTH=fixed verifies every proposal, the same-binary arm. The ids are the plain run's, bit for bit, in both modes, so --print-ids of the runs is one compare. Only a dense model whose layers the two-row pass serves takes it (a dense feed-forward block, attention and delta layers, 4-bit weights); any other file is refused by name before the run, and BLOOMERY_MTP_WIDTH set beside no --draft is refused by name. The run's summary adds the accept counts and the verify pass's wall beside the step's, and under cost the chooser's gate (draft_gate, draft_closed, draft_costs, draft_a, draft_rates), development-loop numbers. A pass that verifies no proposal is a host-fed step, so no token a chained step ran ahead is dropped by a verify that follows. With --profile [N] the run adds the verify's own profile: vprof lines (each group of N two-row verifies on a command buffer of its own, GPU time and bytes, --profile-layers a layer each), vtimes lines (N verifies as the session runs them, one command buffer per verify: the buffers, the host's waits, the GPU's gaps between buffers and the wall split by what ran in it) and one vcompare line.

To learn whether a model opens before it loads: generate_metal [-m PATH | --hf REPO] --plan [--ctx C] reads only the header and tensor table, a folder's or a GGUF file's. It prints every refusal, not only the first, the bytes the open would allocate, the device's working set and the host's free memory. It exits 0 when the header's checks pass, 3 when it is refused and 64 when the header cannot be read; exit 0 does not prove the load fits at run time. With --hf the fetch comes first, and it downloads what the cache lacks. A 24 MB cut of a Hub GGUF file is enough.

Serve

target/release/bloomery-serve-metal --hf mlx-community/Qwen3.6-35B-A3B-4bit --port 8080
# or a folder or a GGUF file you have
target/release/bloomery-serve-metal -m PATH/Qwen3.6-35B-A3B-4bit --port 8080

curl -s http://127.0.0.1:8080/v1/chat/completions -H 'Content-Type: application/json' \
  -d '{"messages": [{"role": "user", "content": "What is the capital of France?"}], "max_tokens": 256}'

The model thinks first: its reasoning comes back in reasoning_content, so leave max_tokens room for the answer. /health, /v1/models, /v1/chat/completions and /completion answer as llama-server's do, and /v1/messages as Anthropic's, so Claude Code runs on the model: claude-code.md.

The flags it takes: -m/--model or --hf (one of the two), --host, --port, --ctx (also --ctx-size and -c; unset, the smaller of 32,768 and the file's context_length), --chat-template-file, --alias (unset, the file's general.name, else the folder's name, else the repo's), --queue-depth, --api-key and --api-key-file, and the speculative drafts below. Any other flag, --parallel, -ngl, --mmproj and --flash-attn among them, is refused by name with exit 64.

--draft lookup and --draft mtp --mtp SIDECAR (off by default) serve with a draft, as generate_metal --draft runs it: the shared window (serve::TargetEngine::drafted over runtime::Speculative behind the width chooser, two rows a pass), BLOOMERY_MTP_WIDTH=cost|fixed as above. A greedy request is verified in passes and returns the plain server's ids, bit for bit; a request that samples runs plain steps. The lookup draft needs no model: its context follows the target by position, so a request cut back to a checkpoint and one that samples both keep drafting. The MTP draft needs the sidecar folder; it rejoins a request that cuts back to a checkpoint because each checkpoint a prompt call takes keeps the target's hidden row of the position before it (one row of hidden values, written to the step arena by the cut), and it stays off after a step that reads the logits row until the next reset. --draft mtp without --mtp, --mtp without --draft mtp, --draft lookup with --mtp, any other --draft word (DSpark has no Metal draft model) and BLOOMERY_MTP_WIDTH beside no draft are refused by name with exit 64, and a file the two-row pass does not serve before the server listens. /props' engine.draft names the draft, and each request's passes are one draft: line on stderr when the next request opens.

What it does and does not do yet

  • One slot: the server runs one sequence. A request keeps the prefix it shares with the slot back to the last checkpoint of the model's recurrent state; a checkpoint is taken at each message start, so a follow-up turn reads only its new messages. Any other prompt runs from position 0. generate_metal --mtp SIDECAR (off by default) opens the MTP draft layer of a Qwen3.5-family file beside the model: the folder of mlx-community/Qwen3.8-27B-MTP-4bit (MLX's folders strip mtp.*, so it is a separate download of 239 MB). --draft-step-times [N] times N draft steps, and --mtp-check DIR/FAMILY holds the draft step to a tools/mlx-logits.py mtp-dump reference. --draft mtp (with --mtp) runs the decode loop over that draft: the shared MTP window (runtime::mtp) with the session as its host behind the width chooser, one proposed id a pass, verified in a pass of two rows. The ids are the plain run's; the summary adds draft_accept_rate beside the lookup draft's lines.

  • A long prompt runs in batched passes (flash attention over the pass, the experts over its rows); decode runs one id a step.

  • No saved prompt cache across slots, no slot files, no embeddings side model (the 501 of /v1/embeddings and of a slot action says the server has none and names no flag), no image input (MiniCPM-V's mmproj is not read). The server drafts only under --draft lookup|mtp (above); a request that samples is never drafted by the MTP layer.

  • On an M5 (Metal 4, GPU family 17 or newer) the device picks the neural accelerators' tensor-op GEMMs for prompts (gemm_path=tensor in the stats); M1 to M4 run the SIMD-group GEMMs (gemm_path=simdgroup). On an M5 Ultra the tensor path took a 2,048-row prompt pass's GEMM class from 203.51 to 92.73 ms (@avlp12, #593). Its sums run in another order, so a greedy answer can differ from an M1–M4's after many tokens.

Numbers

Development-loop numbers from one M4 Pro (48 GB, 20-core GPU, macOS 27.0.1), 2026-10-25, Qwen3.6-35B-A3B, three rounds, tok/s. The Mac has no timing runner (no lease, no witness blocks), so these are not landing evidence.

File Prompt, 512 ids Prompt, 4,096 ids Decode, depth about 0
MLX 4-bit, converted by prepare 943.0 1,076.5 101.2
Q4_K_M GGUF 905.3 1,044.5 85.6

mlx-lm and llama.cpp ran on the same files in the same sitting; their rows, every command and flag, and the per-round tables are in rig-log.

One more Mac, a development-loop number: an Apple M1 Pro 32 GB, macOS 27.0.1, generate_metal --prompt "The capital of France is" -n 32, greedy, with a download running on the same Mac. MiniCPM-V 4.7 and Ornith-1.5-35B (Q4_K_M) each decoded at 43.4 tok/s (PR #805's comment has the commands and output). It is a different chip and different files from the table above.

Contributors' Macs: measured by @avlp12 on an M3 Ultra and an M5 Ultra, 2026-10-25, at main bd0c61345 (its crates/metal is 0.3.9's), Qwen3.6-35B-A3B Q4_K_M, generate_metal --tokens <seeded random ids> -n 128 --ctx 8192, the mean of two runs after one unscored run, tok/s. The M5 Ultra runs the tensor-op GEMMs, the M3 Ultra the SIMD-group ones. Chat: bloomery-serve-metal -c 8192, greedy, a 3,982-id first turn, TTFT on the client. Their conditions, the engines they ran beside it and the per-op pass times are on #593.

Mac Prompt, 512 ids Prompt, 4,096 ids Decode after 512 ids Chat: first turn TTFT, second turn TTFT
M3 Ultra 2,570.4 3,300.0 141–142 1.26 s, 0.12 s
M5 Ultra 4,248.9 5,971.8 211–212 0.70 s, 0.08 s