A research release from Luoke Labs: an experiment in running a 31B dense model on the Apple Neural Engine (ANE), not a model used in our products. Code: luokelabs/gemma4-31b-ane. 16K weights: Hugging Face.
Conclusions
- Faster decode, cooler, and under half the energy: On a 32 GB Mac mini (M6), running the 31B target on the ANE with Google’s lightweight QAT MTP drafter on the GPU decodes 16 short prompts at 26.1 tok/s — more than 31% faster than MLX (19.9 tok/s) and llama.cpp (19.7 tok/s) on the same machine. Over 25 minutes nonstop (1024-token answers), the ANE setup holds 24.4 tok/s vs 17.6 tok/s on MLX (39% faster), drawing 21.8 W vs 39.2 W, 0.92 J vs 2.24 J/token (59% less energy), and peaking at 70.3 °C vs 81.5 °C with no throttling on either side.
- Large-block prefill flips end-to-end latency in ANE’s favor: Adding 32/64-token prefill entries, 4K/8K/16K context tiers, 2048-key blocked global attention, and 128-channel grouped LUT repacking (cutting wired memory by 4.6 GB with zero quality loss) lifts prefill from 54–66 tok/s to 220–254 tok/s. End-to-end turnaround on 500–1000 token prompts drops to 15.7 s (4K) / 16.5 s (16K) vs 20.5 s on MLX (20–24% faster), while 1K–15K prefill matches the GPU (±5%) at ~35% less energy per prompt token (108–125 mJ vs 155–194 mJ).
- Close to the 4.5-bit GPU build in quality, with clear practical limits: On a 160-item pilot, the ANE build (~3.8 bits/weight) gets 4 fewer items right than the same-checkpoint 4.5-bit MLX GPU build (IFEval 82.8% vs 85.9%, HumanEval+ 90.6% vs 93.8%, CMMLU 67.2% vs 68.8%), and is on par with the community ANE benchmark Qwen3.8-27B. Heavy GPU compute running alongside cuts ANE speed roughly in half (shared memory bandwidth), and wired memory estimates rule out 24 GB Macs.
Data
Summary numbers are available in benchmarks.csv. Below are the measured results across decode and energy, per-task speed, prefill and end-to-end latency, quality, memory packing, and GPU concurrency.
Decode speed, power, and 25-minute sustained run
| Benchmark and setup | Decode speed (tok/s) | Machine power (W) | GPU part (W) | Energy per token (J) | Peak chip temp (°C) |
|---|---|---|---|---|---|
| Short 16 prompts · ANE + MTP | 26.1 | 18.8 | 0.6 | 0.77 | — |
| Short 16 prompts · GPU MLX + MTP | 19.9 | 39.4 | 17.9 | 2.00 | — |
| Short 16 prompts · GPU llama.cpp + MTP (6 drafts) | 19.7 | 34.7 | — | 1.92 | — |
| Short 16 prompts · ANE no drafter | 8.6 | 18.5 | 0.0 | 2.17 | — |
| Short 16 prompts · GPU MLX no drafter | 8.2 | 24.3 | 6.4 | 2.99 | — |
| Short 16 prompts · GPU llama.cpp no drafter | 8.0 | 25.1 | — | 3.23 | — |
| Sustained 25 min (1024 tokens) · ANE + MTP (35 rounds) | 24.4 | 21.8 | 0.8 | 0.92 | 70.3 |
| Sustained 25 min (1024 tokens) · GPU MLX + MTP (26 rounds) | 17.6 | 39.2 | 17.3 | 2.24 | 81.5 |
Without a drafter, the ANE (8.6 tok/s) and both GPU engines (8.2 / 8.0 tok/s) run at nearly the same pace. Speculative decoding changes the balance because verifying 8 tokens in one ANE pass takes almost the same time as verifying 1 (128 ms vs 114 ms): decode is bound by reading 10+ GB of weights from memory, not compute. The 0.3 GB MTP drafter proposes 7 tokens in 22–24 ms on the GPU while drawing just 0.6 W on the GPU rail, letting the ANE emit multiple tokens per weight read.
One sharp gotcha: the drafter must match the target’s quantization build. Pairing our QAT target with the generic MTP drafter yielded only 1.33 accepted draft tokens per round (61% first-token hit rate). Switching to the QAT-specific MTP drafter jumped acceptance to 3.49 tokens/round (83% first-token hit rate, 4.98 on code), pushing ANE well past the GPU.
Per-task speed and variance
Because ANE throughput rides on draft acceptance, prompt-to-prompt variance is much wider than on the GPU: standard deviation across the 16 prompts is 10.0 tok/s (range 12.5–43.4) for ANE + MTP vs 3.7 tok/s (12.9–25.2) for GPU + MTP. Breaking results out by task gives a clearer picture:
| Task category | Short decode ANE (tok/s) | Short decode GPU MLX (tok/s) | Long decode 1024 tokens ANE / GPU (tok/s) | Long decode energy ANE / GPU (J/tok) |
|---|---|---|---|---|
| Code | 37.3 | 22.9 | 34–37 / 21 | 0.63 / 1.88 |
| Math | 33.5 | 22.5 | 35–44 / 20–22 | 0.58 / 1.84 |
| English | 22.1 | 18.9 | 17–19 / 15 | 1.23 / 2.65 |
| Chinese | 15.1 | 15.3 | 15–19 / 13–16 | 1.35 / 2.71 |
On short 128-token Chinese replies, lower draft hit rates leave ANE tied with the GPU; on 1024-token replies, ANE pulls ahead in Chinese as well while using half the energy per token.
Prefill, end-to-end turnaround, and long context
Early builds exported only 1-token and 8-token entry points per chunk, pinning prefill at 54–66 tok/s. As a result, average end-to-end time on 500–1000 token prompts was 23.7 s (slower than MLX at 20.5 s), and a 15K prompt took 277 s to ingest.
Adding 32/64-token prefill entries, 4K/8K/16K context tiers, and 2048-key blocked global attention cut average end-to-end turnaround across six 500–1000 token prompts (max 512 output tokens) to 15.7 s (4K m3u2-4k) and 16.5 s (released 16K m3k-16k), comfortably ahead of MLX (20.5 s).
| Prompt length | ANE prefill first run (s) | ANE prefill back-to-back (s) | GPU MLX prefill (s) | ANE prefill energy (mJ/tok) | GPU prefill energy (mJ/tok) | Decode ANE / GPU (tok/s) |
|---|---|---|---|---|---|---|
| 1K | 4.3 | 4.5 | 4.5 | 108 | 155 | 32.1 / 17.8 |
| 4K | 16.8 | 17.1 | 17.4 | 114 | 179 | 21.4 / 14.3 |
| 8K | 34.2 | 38.1 | 35.5 | 121 | 190 | 20.5 / 13.8 |
| 15K | 69.6 | 75.1 | 71.4 | 125 | 194 | 20.1 / 11.2 |
| 6 prompts of 500–1000 tokens total | — | 19.2 | 19.5 | 98 | 151 | 20.5 / 19.9 |
Long-prompt prefill speed is on par with the GPU (±5%: slightly faster from an idle machine, slightly slower back-to-back), while using roughly 35% less energy per prompt token (38% less minus the 2.27 W idle baseline) — about 1/8 the energy per token of decode. Needle-in-a-haystack passcodes from 1K to 15K were recalled 100% on both sides.
With prefix KV reuse (disk snapshots for system prompts or multi-turn state retention), a 1000-token reference snapshot is ~904 MB (0.12–0.15 s to save); restoring it and prefilling a new question takes 0.28–0.38 s vs 4.2 s full prefill (11–15× faster, token-for-token identical), and multi-turn follow-ups on turns 2–3 drop to 0.25–0.26 s (18–19× faster).
Output quality
At 16-bit, Gemma 4 31B weighs ~62 GB, so fitting into 32 GB requires 3–4 bit quantization. Because the ANE’s lookup-table format is coarser than GPU group quantization, we ran GPTQ error compensation (ref64 KL 0.529 → 0.331), layer-wise distillation (0.214), and whole-model distillation (0.164 with 92.2% top-1 agreement when layers 36–59 were 6-bit). Swapping layers 36–59 to Hadamard-rotated 3-bit vector LUTs for speed yields the released mixed build m3 (layers 0–35 at 4-bit, layers 36–59 at 3-bit, ~3.8 bits/weight).
| Model and setup | Avg bits/weight | ref64 KL | IFEval strict prompt (%) | HumanEval+ (%) | CMMLU Chinese (%) |
|---|---|---|---|---|---|
| Gemma 4 31B · GPU MLX QAT | 4.5 | 0.172 | 85.9 | 93.8 | 68.8 |
| Gemma 4 31B · ANE release (16K) | 3.8 | 0.220 | 82.8 | 90.6 | 67.2 |
| Qwen3.8-27B · ANE (ANEMLL Forge) | 3.17 | — | 81.3 | 81.3 | 65.6 |
| Qwen3.8-27B · GPU MLX | 4.5 | — | 79.7 | 81.3 | 75.0 |
The 160-item scores were measured on the 4K build carrying the exact same weights; re-checking ref64 on the 16K release gives KL 0.2202 (vs 0.2196 at 4K, both 59/64 top-1), with minimum hidden-state cosine between 64-token prefill and step-by-step decode of 0.9996 (4K) and 0.9953 (16K). Against the 4.5-bit GPU build, the GPU wins 4 more items out of 160 (IFEval +2, HumanEval+ +1, CMMLU +1): close, slightly lower, and not a same-bit comparison.
One unexpected finding: repacking LUTs saves 4.6 GB with zero quality loss
Initially, ANE wired memory looked invariant to bit width: packing the same 6-layer chunk as per-tensor scalar 3-bit, 4-bit, or 6-bit held an identical 2.06 GB in wired memory, while smaller-on-disk 3-bit vector LUT (VQ) held 2.38 GB. The ANE compiler expands per-tensor 4-bit LUTs to roughly 6.5 bits in resident memory.
| Packing format and scope | Disk size (GB) | ANE wired loaded (GB) | ANE wired running (GB) |
|---|---|---|---|
| One 6-layer chunk · scalar 3 / 4 / 6-bit (per-tensor LUT) | 1.40 | 2.06 | 2.06 |
| One 6-layer chunk · vector 3-bit (VQ) | 1.10 | 2.38 | 2.38 |
| One 6-layer chunk · 4-bit repeated per 128 channels (16K front) | 1.40 | 1.73 | 1.73 |
| Full model 4K + v32 · per-tensor LUT (before) | 17.0 | 23.8 | 25.4 |
| Full model 4K + v32 · first 36 layers repeated per 128 channels (after) | 17.0 | 19.0 | 20.8 |
Keeping every weight value in layers 0–35 bit-identical and simply repeating the same 16-entry LUT every 128 output channels (LUT_GROUP=128) makes the ANE pack weights at true 4-bit: quality is unchanged (KL 0.2196, 59/64 top-1), while running wired memory drops by 4.6 GB. That headroom is what allowed 16K context and large-block prefill to fit inside 32 GB (the released m3k-16k wires ~19.8 GB after load, leaving 3.8–4.8 GB free while running with MTP).
Running alongside a saturated GPU job
With another process saturating the GPU in a continuous FP16 4096×4096 matmul loop (18.8 TFLOPS alone) while ANE inference runs:
| Workload | GPU idle | GPU saturated | Change (%) |
|---|---|---|---|
| ANE + MTP decode (tok/s) | 26.1 | 11.2 | -57 |
| ANE alone (no GPU use, tok/s) | 8.6 | 4.5 | -48 |
| GPU matmul (with ANE + MTP, TFLOPS) | 18.8 | 12.1 | -36 |
| GPU matmul (with ANE alone, TFLOPS) | 18.8 | 13.7 | -27 |
Even the pure ANE run drops nearly in half, most likely because streaming 10+ GB of weights per decode step contends with the GPU over unified memory bandwidth (estimate, not verified). Running the LLM on the ANE does not leave the GPU free for other heavy compute.
Method
Model rewrite and runtime design
- Hardware and software: Mac mini (M6 32 GB), macOS 27.0.1; Core AI (
coreai-torch0.4.2,coreai-opt0.2.1,coreai-core1.0.0b2). GPU baselines:mlx-vlm0.7.12 /mlx0.32.4 (4-bit affine, group 64, converted from the same QAT checkpoint) andllama.cppb12651 (Google’s official QATQ4_0GGUF + unsloth MTP GGUF,--spec-type draft-mtp -fa on). - Full ANE placement and fp16 safety: The 60 layers (50 sliding-window layers of size 1024 + 10 K/V-shared global layers) are split into 10 chunks of 6 layers plus 1 output head (262K vocab), for 11 Core AI
.aimodelpackages — all confirmedfullyPlacedOnANE. Linear layers are rewritten as 1×1 convolutions in(1, C, 1, T)layout, and RMSNorm scales inputs down before squaring. Chaining all 60 unquantized fp16 layers on the ANE matches PyTorch fp32 with a minimum layer cosine of 0.9997 and no overflow. - Swift bridge and GPU pre-warming: Core AI’s Python binding allocated new output buffers on every call without freeing them (crashing after ~125 steps). The runtime instead uses the Swift bridge from ANEMLL Forge, binding IOSurface buffers once in place. Because the GPU clocks down while idling during the ANE verify (stretching draft time from 28 ms to 50 ms), the runtime dispatches a tiny GPU warm-up 95 ms into verify (
PREWARM_MS=95) and runs 30 warm-up draft tokens at startup (WARM=30) so MLX compiles shapes ahead of time. - Prefill and context-tier constraints: A Core AI chunk keeps at most 7 fast entry points on the ANE; an 8th exported function silently falls off the ANE (100+ ms/call, +~5 GB wired memory). Likewise,
T=48falls back to the GPU (260 ms), so prefill usesT=32/64. Global attention at 16K stores K pre-transposed and computes scores in 2048-key blocks (15.6 ms → 5.8 ms/call). Shared-weight 4K/8K/16K tiers keep short prompts fast, copying global KV into larger buffers only when length crosses 4096 tokens.
Measurement protocol
- Speed: Greedy decoding with thinking disabled across 16 short prompts (4 each of code, math, English, Chinese; 128 tokens), 6 end-to-end prompts (English, Chinese, code at 500 and 1000 tokens; max 512 output), and 4 long-context prompts (WikiText-2 at 1K/4K/8K/15K with an embedded passcode and summary request; max 128 output). Decode speed is timed from first to last token; end-to-end from request submission to last token.
- Power and temperature: On M6, per-unit CPU/ANE readings from
powermetricsandmactopare zero, so whole-machine power (SMC sensor, idle 2.08–2.85 W, not subtracted unless noted) is sampled every 0.5 s viamactop0.2.7 and integrated strictly over decode or prefill intervals. - Quality: Next-token KL divergence and top-1 agreement against fp32 PyTorch on
ref64(64 chat positions), plus a fixed-seed 160-item task pilot (64 IFEval, 32 HumanEval+, 64 CMMLU, greedy, thinking off).
Reproduce
Requirements: a 32 GB Apple silicon Mac, macOS 27 (with Core AI), Xcode Command Line Tools (swiftc), Python 3.13 (brew install [email protected] or uv, which setup.sh uses automatically), and at least 30 GB of free disk space (~16 GB model plus 20–30 GB Core AI compile cache).
git clone https://github.com/luokelabs/gemma4-31b-ane && cd gemma4-31b-ane
scripts/setup.sh # venv, tested ANEMLL Forge commit, Swift bridge
scripts/download.sh # downloads 16K ANE model (~16 GB) + MTP drafter (~0.3 GB)
export MTP_MLX=$PWD/models/gemma-4-31B-it-qat-assistant-4bit-mlx
.venv/bin/python chat.py models/gemma-4-31B-it-ane-16k
First load compiles the chunks for the ANE (several minutes, once per macOS build); subsequent loads take seconds. If the download stalls, stop and rerun scripts/download.sh to skip already-fetched files.
To reproduce the end-to-end, long-context, and ref64 KL checks:
export PREWARM_MS=95 MLX_CACHE=268435456 WARM=30 ND_ZH=3
.venv/bin/python ane_run.py models/gemma-4-31B-it-ane-16k eval/prompts/e2e_prompts.json --max 512 --out logs/e2e.json
.venv/bin/python ane_run.py models/gemma-4-31B-it-ane-16k eval/prompts/long_prompts.json --max 128 --out logs/long.json
REF64_DIR=models/gemma-4-31B-it-ane-16k/eval .venv/bin/python eval/validate.py models/gemma-4-31B-it-ane-16k
The full quantization and distillation chain (GPTQ → layer-wise distillation → end-to-end distillation, ~1–2 days) is documented in docs/quantization.md and scripts/build_16k.sh inside the repository.
Limitations
- Single machine: All measurements were taken on one M6 32 GB Mac mini. Because ANE-to-GPU compute and bandwidth ratios shift significantly across Apple silicon generations, results do not extrapolate directly to other M-series chips or iPhones.
- Tight 32 GB headroom: Running with MTP leaves 3.8–4.8 GB free on the 16K release (~2.9 GB on the fastest 4K build); wired memory estimates indicate 24 GB Macs will not fit (not tested). Below ~15 GB free disk, macOS evicts fresh Core AI compile caches and loading fails with
nilError; keep 30+ GB free and prune orphan caches after rebuilds. - Occasional ANE wake-up stalls: Individual prefill calls occasionally take 300–900 ms instead of ~100 ms, mostly on the first chunk after ≥ 0.3 s of ANE idle (adding 0–2 s to long prompts). Input data, memory pinning, and 19 user system services were ruled out; a 100 ms keep-alive slows real MTP decode by 2–4% and stays off by default.
- Scope and cross-round caveats: Greedy decoding only (speculative verify is exact for greedy). The 160-item task pilot is a small sample and was not rerun on the 16K build (verified via
ref64KL 0.2202 vs 0.2196 on identical weights), nor was the 25-minute sustained run. Short decode speed (26.1 tok/s) and power (18.8 W / 0.77 J) come from the isolated rerun and round 1 (24.45 tok/s) respectively. Concurrency was tested only under full GPU saturation, not light GPU loads.
Changelog
- 2026-11-27: First version, combining quantization, speculative decoding, large-block prefill, and prefill power measurements alongside the open-source code and 16K model release.