Skip to content

By PromptFission2 min read

nanoattention runs a model from Zig and Metal, with Lean proofs that say what they do not prove

A single-sequence inference engine for Apple Silicon reports 120 tokens per second on an M3 Ultra, checks some kernel properties in Lean, and lists the limits of both claims.


nanoattention, from GitHub user justrach with commits co-authored by blackfloofi, is an inference engine for Apple Silicon that runs Flint, a model from Recursive, without MLX, PyTorch or CUDA. Zig handles the bookkeeping, Metal shaders do the math, and a set of Lean proofs covers parts of the plumbing. The README is unusually careful about how far each claim goes.

How it works

The split is simple. Zig memory-maps the checkpoint, owns the buffers and the key-value cache, and schedules the model. Metal kernels do attention, the packed quantized projections, expert routing and the vocabulary head. The weights are loaded as sharded 4-bit and 8-bit safetensors and are never expanded to 32-bit floats. The README puts the download at about 22.58 GB in five shards.

Sessions are saved as JSONL with a cache per layer, so a new request that shares a token prefix with an old one reuses that work. Layers that only look at nearby tokens get a sliding ring cache. Layers that look at everything keep the full prefix.

Then there is Lean, a proof assistant. The project writes contracts for its kernels in Lean and generates bindings that tie them to the Zig and Metal code. According to the README, Lean proves selected integer properties: the order of the execution plan, index bounds, and that packed 4-bit values are reconstructed correctly. It then says what is not proved: floating-point equivalence, whole-shader correctness, GPU memory behavior, forward progress, or speed. For those it leans on tests, including a recorded comparison against MLX that covers every greedy token choice through 28,623 cached tokens.

The numbers, and their fences

All figures are the author’s, on an M3 Ultra with 60 GPU cores and 256 GB of memory.

Test Decode speed
Short coding prompt, 21-token prefix 120.40 tok/s
Random token IDs, 16K context filled 106.09 tok/s
Random token IDs, 32K context filled 93.19 tok/s
Stock MLX FP32, short context 96.84 tok/s
Stock MLX BF16, short context 91.96 tok/s

That looks like a win over MLX at short context, and the README declines to call it one. It describes the measurements as historical and not paired, and says they are not a claim of overall MLX parity. It also says its serial prefill, the step that reads the prompt, is substantially slower than MLX’s batched version. So the engine may type faster and read slower.

The limits list is long: one sequence at a time, greedy sampling only, no native tokenizer, Apple Silicon only. Support for Inkling 2 Mini is marked experimental, with MLX parity not yet passed.

Try it yourself

The repo lists an Apple Silicon Mac, Xcode or its command-line tools, Zig 0.17.0, Lean 4.35.0 and Python 3.9 or later. zig build -Doptimize=ReleaseSafe produces a flint binary, and a Python script handles tokenizing and chat. The code is MIT, with adapted pieces keeping their original Apache-2.0 and MIT terms. Weights are not bundled. One oddity: the README still says the repository is private, though the page is public. It has 11 commits, dated November 20 to 22.

We have not built or run nanoattention. This is based on the README and the commit history.