Retrieved article excerpt
Open article · Retrieved 2026-10-21T02:29:04.680954+00:00
# ANE Fieldfare
**Gemma 4 26B-A4B at up to 100+ tokens/s on a 16 GB Mac. Using less than 2GB of RAM**
Using the Apple Neural Engine for prefill, speculative decoding on the GPU, and 13 GB of experts from the OS file cache.
| Setting | ANE Fieldfare | [Turbo Fieldfare](https://github.com/drumih/turbo-fieldfare) | llama.cpp |
| --- | --- | --- | --- |
| Greedy generation, math | **96.6 tok/s** | 24–25 tok/s | 5–9 tok/s |
| Generation with temperature 0.2 | **36-53 tok/s** | 21–25 tok/s | |
| TTFT, 3,015-token prompt | **10 s** | 48 s | ~110 s |
RSS is under 1GB for short prompts.
Measured on 2026-10-20 against Turbo Fieldfare's latest commit: greedy on this
repo's benchmark prompts, sampled on Turbo's own benchmark; first token
includes model load. Up to 99 tok/s is this repo's benchmark on code
([Performance](https://github.com/zw5/ane-fieldfare#performance)). llama.cpp runs Google's Q4\_0 GGUF, which is
over Metal's 12.7 GB limit on a 16 GB Mac, so even its best layer split pages
(`llama-bench`; first token estimated from its 24–32 tok/s prefill).
This repo builds upon [Drumih](https://github.com/drumih)'s work creating Turbo Fieldfare!
## Architecture
```
PROMPT (prefill) GENERATION (decode)
GPU attention, router, shared FFN GPU DFlash drafter drafts a block
│ │
GPU unpacks the next 4 INT4 experts ──┐ GPU the model verifies the whole block
ANE computes the previous 4 ◄────┘ in one pass, routing experts on the GPU
│ │
└───── 13 GB of experts, memory-mapped and zero-copy: the OS file cache is the expert cache
DFLASH -> Speculative decoding
```
- The file cache runs as the expert cache, with minor modifications from Turbo Fieldfare. Experts are zero-copy Metal buffers
over the mapped model file, so a 13 GB model runs in under 1 GB of process
memory on short prompts.
- **The Neural Engine does prefill.** It can't unpack 4-bit weights, so the GPU
unpacks the next 4 experts while the ANE computes the current ones: 1.7×
faster than the GPU alone on long prompts.
- **Speculation never leaves the GPU.** The drafter, the verify's expert
routing and the acceptance all run on the GPU, so the CPU waits once per
step and the GPU stays 93–95% busy.
The ANE path uses private Apple frameworks: a macOS update can break it
(`--backend metal` runs everything on the GPU), and it can't ship in App Store
apps.
## Requirements
- An Apple Silicon Mac.
- macOS 26 or later. Measured on macOS 27 build `26A5406e`.
- Xcode with Swift 6.2 or later.
- The model in `.gturbo` format, installed by `ANEFieldfareInstall` (see
[Quick start](https://github.com/zw5/ane-fieldfare#quick-start)) at `checkpoints/gturbo/gemma4.gturbo` (git
ignores `checkpoints/`). The installer streams
`mlx-community/gemma-4-26b-a4b-it-4bit` from Hugging Face at a pinned
revision, about 15 GB through range requests, and writes the ~14.3 GB
install directly, without a second copy of the checkpoint on disk.
- `z-lab/gemma-4-26B-A4B-it-DFlash` (dflash drafter) at
`checkpoints/dflash/gemma-4-26B-A4B-it-DFlash` (or beside the model), where
the CLI and the server find it. Without it the model still runs,
1.5–1.9× slower. The first run quantizes it to this runtime's 4-bit format into
`fieldfare-dflash-int4.bin` (242 MB) in the same directory.
## Quick start
```
Scripts/build.sh # builds the CLI, the server and the installer into .build/
# Download and install the model (resumable; set HF_TOKEN only if Hugging Face asks).
.build/swift-hotpath/release/ANEFieldfareInstall --output checkpoints/gturbo/gemma4.gturbo
.build/swift-hotpath/release/ANEFieldfareHotpathCLI \
--model checkpoints/gturbo/gemma4.gturbo \
--chat-prompt "What is the capital of France? Answer briefly." \
--temperature 0 --max-new 64
```
An interrupted install continues with `--resume` or is removed with
`--discard-partial`; `--verify-install --input-gturbo <dir>` re-checks an
install's files against its manifest. The optional image pack installs beside
the model with `--vision-output checkpoints/gturbo/gemma4.vision.gturbo --text-model checkpoints/gturbo/gemma4.gturbo`.
Speculative decoding is enabled whenever the drafter is installed, greedy or
sampled; image prompts and a repetition penalty decode without the drafter. The
prompt runs on the Neural Engine (`hybrid-ane`) unless you pass `--backend metal`.
`--help` lists every option, including `--image` for image input.
### Command line flags
| Option | What it does |
| --- | --- |
| `--backend hybrid-ane` | During prompt processing, the 8 chosen experts of every layer run on the ANE. Default. Needs the default `--expert-top-k 8`, no `--prefill-expert-cap` and prefill on; without them the CLI uses `metal`. If the ANE cannot be set up, startup fails rather than falling back. |
| `--backend metal` | Everything on the GPU. |
| `--fault-policy fail-closed` | If the ANE fails mid-request, stop with an error. Default. |
| `--fault-policy failover-metal` | If the ANE fails mid-request, stop using it and finish the request on the GPU, starting again from the layer that failed. |
| `--drafter <dir|off>` | The DFlash draft model for speculative decoding, if not in the default place; `off` decodes one token at a time. See [How it works](https://github.com/zw5/ane-fieldfare#speculative-decoding). |
| `--early-expert-read off|router|fitted` | Whether generation asks the SSD for next layer's likely experts ahead of time. Default `fitted`. |
| `--prefill-chunk-tokens <n|auto>` | How many prompt tokens are processed per pass. Default `auto`: the smallest size that covers the prompt. |
### Environment variables
| Variable | Effect |
| --- | --- |
| `ANE_FIELDFARE_HOTPATH_PROFILE=1` | Write a JSON timing profile to stderr, including which work ran on the ANE and any ANE failures. |
| `ANE_FIELDFARE_GPU_TRACE=<path>` | Record every GPU encoder's execution and the CPU's waits on one clock, and write a Chrome trace to `<path>` (open it at ui.perfetto.dev). `Scripts/profile/summarize.py <path>` prints GPU time per kernel and GPU idle time by what the CPU was doing. Costs no measurable speed. |
| `ANE_FIELDFARE_ANE_ROUTED_PREFILL_LAYERS=n` | Use the ANE for layers `0..<n` only. |
| `ANE_FIELDFARE_HOT_HEAD=0` | `ANEFieldfareBench` only: turn off the [hot-vocabulary shortcut](https://github.com/zw5/ane-fieldfare#hot-vocabulary-shortcut). |
| `ANE_FIELDFARE_HOST_ROUTED_VERIFY=1` | Plan every verify layer's experts on the CPU instead of routing them on the GPU. Slower; meant for checking the GPU routing. |
| `ANE_FIELDFARE_VERIFY_BIND_TOP=n` | How many of each verify row's guessed experts the GPU routing can use. Default 20. |
| `ANE_FIELDFARE_TEST_CHECKPOINT=<path>` | Model location for tests, if not the default. |
| `ANE_FIELDFARE_API_KEY=<key>` | Server only: require `Authorization: Bearer <key>`, like `--api-key`, without putting the key on the command line. |
## OpenAI-compatible server
`ANEFieldfareServer` serves the model over the OpenAI HTTP API, so chat apps
that speak it (Open WebUI, LibreChat, Jan, Msty, Chatbox, SillyTavern,
continue.dev, the `openai` SDKs) can use it. It keeps one model in memory and
generates through the same loop as the CLI: for the same prompt and settings
it returns the CLI's text.
```
Scripts/build.sh # also builds the server
.build/swift-hotpath/release/ANEFieldfareServer \
--model checkpoints/gturbo/gemma4.gturbo
# [server] listening on http://127.0.0.1:8080/v1 (model id gemma-4-26b-a4b-it)
curl http://127.0.0.1:8080/v1/chat/completions -H 'Content-Type: application/json' -d '{
"model": "gemma-4-26b-a4b-it", "temperature": 0, "stream": true,
"messages": [{"role": "user", "content": "What is the capital of France?"}]}'
```
Point a client at base URL `http://127.0.0.1:8080/v1` with any API key (or the
one given to `--api-key`). In Open WebUI: *Admin Settings → Connections →
OpenAI API → +*, URL `http://127.0.0.1:8080/v1` (from Open WebUI in Docker,
`http://host.docker.internal:8080/v1` with `--host 0.0.0.0`). Clients that
expect OpenRouter's base URL can use `http://127.0.0.1:8080/api/v1`.
| Server option | What it does |
| --- | --- |
| `--model <dir>` | The `.gturbo` model. Required. |
| `--drafter <dir|off>` | DFlash drafter, if not in the default place: greedy and sampled requests decode speculatively (not with a repetition penalty). `off` turns it off. |
| `--host <address>`, `--port <n>` | Where to listen. Default `127.0.0.1:8080`; `--host 0.0.0.0` for other machines. |
| `--max-context <n>` | Prompt plus completion limit in tokens. Default 32768. |
| `--model-id <id>` | The id `/v1/models` advertises. Default `gemma-4-26b-a4b-it`. Requests may name any model. |
| `--api-key <key>` | Require `Authorization: Bearer <key>` on `/v1` (not on `/health`). Also `ANE_FIELDFARE_API_KEY`. |
| `--max-queue <n>` | Requests that may wait while one generates. Default 8; beyond that, 503. |
| `--temperature`, `--top-k`, `--top-p`, `--max-tokens` | Defaults for requests that leave the field out. Default 0.2, 64, 0.95 (the CLI's), and the rest of the context. |
| `--backend`, `--fault-policy`, `--early-expert-read` | As for the CLI. |
**Endpoints.** `GET /v1/models`, `GET /v1/models/{id}`,
`POST /v1/chat/completions`, `POST /v1/completions` (raw prompt: `<bos>` plus
the text, like `--prompt`; or token IDs), `GET /health`; every `/v1` route also
under `/api/v1`. CORS is open (`Access-Control-Allow-Origin: *`, preflights
answered), so browser apps can call it.
**Request fields.** `messages` (`system`, `developer`, `user`, `assistant`;
string content or an array of `text` parts), `max_tokens` /
`max_completion_tokens` (clamped to the context), `temperature`, `top_p`,
`top_k` (0 or -1: off), `repetition_penalty`, `stop` (string or up to 16
strings, matched on the decoded text, also across token boundaries while
streaming), `seed`, `stream`, `stream_options.include_usage`, `n` (1 only).
Non-empty `tools`, a `response_format` other than `text`, and non-zero
`frequency_penalty` or `presence_penalty` are refused with 400; other fields,
`model` and `user` among them, are ignored. Responses carry `usage`, and a
llama.cpp-style `timings` object with tokens per second and the decode path.
Streams send a first chunk with `role`, content deltas, a chunk with
`finish_reason` (`stop` or `length`), the usage chunk if asked, and
`data: [DONE]`.
**Decoding.** As in the CLI: temperature 0 is greedy (with the
hot-vocabulary shortcut when no drafter is loaded), anything above it samples
on the GPU, and with a drafter loaded both decode speculatively, with the same
text for a given `seed` as without it. A request with a repetition penalty samples on the CPU, without
the drafter.
**Concurrency.** One generation runs at a time; others wait in order, up to
`--max-queue`, and further requests get `503` with `Retry-After`. A client that
disconnects cancels its generation (between tokens, or between prefill chunks)
or leaves the queue. The server keeps the last request's KV cache: when the
next request starts with the same tokens and decodes the same way (a chat
re-sending its history), only the new part of the prompt is prefilled.
**Errors** use OpenAI's shape, `{"error": {"message", "type", "param", "code"}}`: 400 for invalid requests, 401 for a missing or wrong key, 404, 405,
413 (`context_length_exceeded`) when the prompt does not fit, 503
(`server_busy`), 500.
**Limitations.** Text only: image parts are refused with a 400 (the CLI's
image path needs the vision pack, and is not wired to the API). No tool
calling, logprobs, `n` > 1, `echo` or JSON mode. `system` messages must come
before the conversation. A client that half-closes its socket after sending
a request is taken as gone. The listener speaks plain HTTP/1.1; put a TLS proxy
in front of it before exposing it beyond the machine.
`Scripts/server/