a8nova's picture
nnopt port: Bonsai-27B-llama.cpp
9d62c0e verified
|
Raw History Blame Contribute Delete
3.92 kB

Bonsai-27B (Q1_0) on Mac mini M2 Pro: faster decode on the PrismML llama.cpp fork (Metal)

  • Model: prism-ml/Bonsai-27B-gguf, Bonsai-27B-Q1_0.gguf (hybrid gated-delta-net + attention, 64 blocks).
  • Device: Mac mini (M2 Pro), Apple GPU, macOS on Apple silicon.
  • Runtime: the customer's PrismML llama.cpp fork (5ae2e169), Metal backend, with our patches (src/patches/0001-q1_0-lut-gemv.patch) and a small C++ runner over llama.h (src/runner.cpp).
  • Precision: Q1_0_g128 1-bit weights as published (reordered in memory at load), fp32 activations and accumulation, f16 KV cache. Processor: GPU, all layers.

Requirements

  • macOS on Apple silicon (arm64), Xcode command line tools (/usr/bin/clang, clang++), CMake >= 3.14, rsync, patch.
  • The customer's inputs folder (inputs/reference_code = the fork, inputs/weights/Bonsai-27B-Q1_0.gguf). build.sh finds it via $NNOPT_INPUTS_DIR, or in inputs/ or work/inputs/ next to this folder or any parent folder.

Build

bash build.sh        # copies the fork to build/llama-src, applies src/patches, builds bin/nnopt_runner (~30 s)

Deploy

bash deploy.sh DEST  # DEST/run.sh, DEST/nnopt_runner, DEST/port.json, DEST/Bonsai-27B-Q1_0.gguf (APFS clone)

Run

sh DEST/run.sh --prompt-file prompt.txt --max-new-tokens 128 [--ignore-eos] [--repeat R] --out out.json --metrics m.json
sh DEST/run.sh --score-tokens tokens.json --top-k 10 --out out.json --metrics m.json

Generation is greedy (argmax, ties to the lowest id), with the vocab's default special tokens and no chat template. out.json = {"prompt_tokens", "tokens", "text"}; m.json holds load_ms and per-run total_ms, ttft_ms and token_ms.

Check

nnopt-verify check --split public --bundle <work>/reference --port DEST --executor local

Measured (this Mac)

starting version this port
decode tok/s, kit bench (outside clock) 15.85 27.48
decode tok/s, kit sustained run (median) - 30.07
decode ms/token, in-process (p000, 128 tokens) ~63 33.1
public check - all metrics 1.0 (1185 positions)

Roofline: 54.6 tok/s (3.6 GB of weights per token at ~200 GB/s). Details, profile and what was tried: NOTES.md.

Known limits

  • Weights are read into Metal buffers (not mmapped) and repacked at load. Warm load takes ~1 s; the first launch after a build takes ~18 s while Metal compiles the shaders.
  • Speed work targets decode. Prefill uses the fork's kernels (adapted to the repacked layout, same speed).
  • The repacked Q1_0 layout is internal to this build's Metal kernels. Do not mix these patched libraries with an unpatched loader or mmap loading (the loader refuses mmap for Q1_0 Metal tensors).

Verified by nnopt

Passed prism-ml/Bonsai-27B-gguf on Mac mini (M2 Pro) (2026-10-16). nnopt built this folder from a clean copy, deployed it to the device and ran it on hidden inputs; the full report is report.html.

Check Measured Bar Result
Speed target: decode 29.4 tokens/s at least 19.0 tokens/s pass
Outputs match your reference code Next-token agreement 100.0% at least 98.0% (original precision) pass
Runs on llama.cpp src/runner.cpp:164: llama_model * model = llama_model_load_from_file(model_path.c_str(), mparams); the runtime you asked for pass
Speed This port Starting version Change
Prefill, tokens/s 86.0 87.3 1.0× slower
Decode, tokens/s 29.4 15.9 1.9× faster
Time to first token 1.82 s 1.80 s 1.0× slower
Load time 1.04 s 564 ms 1.8× slower
Peak memory 4,532 MB 4,208 MB 8% more
Measurement Median
Prefill 86.043 tokens/s
Decode 29.3804 tokens/s
Time to first token 1824.67 ms
Load time 1037.93 ms
Peak memory 4532.0 MB
Sustained speed after 11 min, % of start 100.0 %