Inference Server on an M4 Pro: The Practical 26x Speedup
Athrael's course Introduction to GPU Inference has a lesson called "Your first inference server". You install narwhal-inference and start a router with four llama.cpp engines: two do prefill and two do decode. The engines serve ERNIE-4.5-0.3B at 4-bit, and you load-test them with 2,000 prompts. The lesson lists Linux and WSL2 as supported. It does not list macOS. I ran it on my MacBook (Apple M4 Pro, 24 GB) anyway, to see how far it gets.
In short, it runs on the M4 only inside an x86 Linux container under Rosetta, at about 4% of the lesson's throughput. The same model on native llama.cpp with Metal matches the lesson's per-token decode speed from a single engine.

The commands have moved since the lesson was written
The lesson uses narwhal dev setup and narwhal dev up. In narwhal-inference 0.50.0, both stop with an error:
narwhal: dev setup: narwhal dev setup is retired; run narwhal deploy init --target local
The current flow is narwhal deploy init --target local, then narwhal deploy plan, narwhal deploy run and narwhal deploy down, each with --target local. dev ask and dev watch work as the lesson describes.
macOS is refused in the code, and the binaries are x86 only
On the Mac itself, deploy init stops at once:
narwhal: deploy init: the local target runs on Linux, and on Windows under WSL2
The check is a sys.platform.startswith("linux") test in narwhal/dev/downloads.py, so it is not a soft warning. Removing that check would not help. The lesson's ERNIE template pins llama.cpp build b12365 as Ubuntu x86_64 archives only: CPU, CUDA 12.8 and CUDA 13.5. It pins no arm64 build and no Metal build.
Workaround: a linux/amd64 container under Rosetta
Docker Desktop on Apple Silicon can run --platform linux/amd64 containers through Rosetta, and that was enough to get the lesson running:
docker run --rm -it --platform linux/amd64 -v $PWD:/work -w /work python:3.12-slim bash
apt-get update && apt-get install -y libgomp1 # the CPU llama-server needs it
pip install narwhal-inference==0.50.0
narwhal deploy init --target local # 18 s: llama.cpp b12365 CPU build + 229 MiB GGUF
narwhal deploy run --target local # 42 s to a ready router on :18000
narwhal dev ask "What is the capital of France?"
On my first attempt, deploy run failed with libgomp.so.1: cannot open shared object file. Slim images do not ship OpenMP. A minimal Ubuntu install would probably hit the same error.
The single question worked:
{"status": "answered", "reply": "The capital of France is Paris.",
"ttft_s": 1.1421, "output_tokens": 8, "tokens_per_second": 10.7,
"engines": {"prefill": "n2", "decode": "n3"}}
The prefill/decode split works as the lesson describes: n2 computed the prompt's KV cache, and n3 restored it and generated the reply.
The load test under emulation
I started narwhal dev watch and then the lesson's --repeat 2000 --concurrency 8 --max-tokens 200. The controller still did the thing the lesson is about. Decode filled up, so it moved engines between roles:
role switches 3 n2 to decode n3 to prefill n3 to decode
controller held at 1P:3D instead of 2P:2D: first token timeout ...
The engines changed roles while the model stayed loaded, which is the lesson's hot swap. The numbers, though, were far from the lesson's:
| Lesson (recorded run) | M4 Pro, x86 under Rosetta (Narwhal, 4 engines) | |
|---|---|---|
| TTFT median | 92 ms | 2.2–2.4 s |
| TPOT median | 4.9 ms | ~330 ms |
| Throughput | 22.5 req/s | ~0.4–0.5 req/s (~23 output tok/s) |
| Failures | not stated | 2 of ~210 |
At 0.4 req/s, the full 2,000 prompts would take about 80 minutes, so I stopped after about 210. The x86 CPU build runs through Rosetta, runs on CPU only, and shares a Docker VM with 7.7 GB of RAM. These numbers measure the emulation, not the M4.
What the M4 does natively
Homebrew's llama.cpp (build 12774, Metal) loads the same GGUF file that Narwhal downloaded. With llama-bench:
| Test | Metal | CPU only (-ngl 0) |
|---|---|---|
| Prefill, 64-token prompt | 6,233 tok/s | 899 tok/s |
| Prefill, 512-token prompt | 10,045 tok/s | — |
| Decode, 200 tokens | 499 tok/s | 342 tok/s |
Next I ran one native llama-server -np 8 (8 parallel slots on one engine, no router, no disaggregation). I load-tested it with the lesson's shape (2,000 requests, concurrency 8, 200 max tokens) using a small streaming client that measures TTFT and TPOT per request:
| Lesson (Narwhal, 4 engines) | M4 Pro native Metal (1 llama-server) | |
|---|---|---|
| TTFT median / p95 | 92 ms / — | 18.7 ms / 24.1 ms |
| TPOT median / p95 | 4.9 ms / — | 4.94 ms / 5.74 ms |
| Throughput | 22.5 req/s | 10.6 req/s |
| Failures | — | 0 of 2,000 |
The two setups are not directly comparable. The lesson's figures come from the author's own run, on unspecified hardware, measured at the router. Mine come from one engine, measured at the client, with my own four prompts. Per-token decode speed is the same, and time to first token is lower on the Mac because there is no router hop and no KV handoff. The lesson's fleet gets twice the requests per second. That gap is the lesson's point: separate decode engines add decode capacity, and one engine's slots cannot.
Update: Narwhal running natively on the M4 Pro
After writing this, I patched Narwhal to run the local inference server natively on Apple Silicon. The patch adds a Metal build of the same llama.cpp release and macOS versions of the Linux-only process and memory checks. It is open as Narwhal pull request #924. With it, the unchanged lesson flow on the M4 Pro served 2,000 requests at 22.4 requests per second, with TTFT p50 78 ms and TPOT p50 5.3 ms and no failures. That is level with the lesson's recorded 22.5 requests per second. The controller again moved an engine from prefill to decode.
Inference server terms in two minutes
If the lesson is your first contact with LLM serving, these five terms carry the rest of this post.
- Prefill is the pass over the whole prompt. The engine computes attention keys and values for every prompt token at once, so prefill is compute-bound and fast per token. On the M4 Pro, Metal prefilled a 512-token prompt at about 10,000 tokens per second.
- Decode produces the reply one token at a time. Each step reads the full model weights and the growing cache, so decode is bound by memory bandwidth, and it is where most of a long reply's time goes.
- KV cache is the keys and values that prefill computed. Decode needs it, so in a split fleet the cache has to move from the prefill engine to the decode engine. Narwhal saves the slot's cache on one engine and restores it on another.
- TTFT (time to first token) is how long a user waits before the first word appears. It covers queueing, routing, prefill and any KV handoff.
- TPOT (time per output token) is the gap between tokens once streaming starts. 5 ms per token is about 200 tokens per second for a single request.
Disaggregation, the idea the lesson teaches, runs prefill and decode on different engines so that each can be sized for its own bottleneck. The router decides how many engines play each role, and Narwhal's controller changes that split while the fleet runs.
Why the emulated fleet is so slow
The container numbers are not a verdict on Narwhal. Three things stack up:
- Translated x86 code. The pinned llama.cpp build is an Ubuntu x86_64 binary, so every instruction goes through Rosetta inside Docker's Linux VM.
- CPU only. Docker on macOS gives containers no access to the Apple GPU, so the Metal backend is out of reach from inside the container no matter which build you pin.
- One small VM. Docker Desktop's VM had 14 CPUs and 7.7 GB of RAM, and four engines plus the router shared it.
Put together, the same GGUF ran at about 330 ms per output token in the container and 4.94 ms natively, a gap of roughly 67x per token and 26x in requests per second.
Reading the controller in narwhal dev watch
The most useful thing the emulated run showed was not a number but the controller explaining itself. narwhal dev watch redraws each engine's role, its requests in flight, TTFT and TPOT at the median and 95th percentile, throughput, and every role switch. Under the 2,000-prompt load, it printed lines like these:
role switches 3 n2 to decode n3 to prefill n3 to decode
controller held at 1P:3D instead of 2P:2D: first token timeout 13.1 s ago: re-collecting one evidence window
controller held at 1P:3D instead of 2P:2D: decode profile does not cover proposed work
Read in order, they tell the story the lesson describes. The fleet starts at two prefill and two decode engines. Short prompts with 200-token replies pile work onto decode, so the controller moves an engine from prefill to decode. It then holds at one prefill and three decode engines instead of going back to 2P:2D, and it says why: a recent first-token timeout, and a decode profile that does not yet cover the work it would propose. It waits for another evidence window before changing roles again.
That is the lesson's real payload, and it survives emulation intact. The latencies are slow, but the decisions and the reasons for them are the same ones you would see on a GPU fleet.
How the speedup figures were computed
Both figures compare the same model file and the same request shape (concurrency 8, up to 200 output tokens):
- 26x is requests per second: 10.6 natively against about 0.4 in the container.
- 67x is median TPOT: about 330 ms in the container against 4.94 ms natively.
The container figures come from narwhal dev watch at the router, over the roughly 210 requests that finished before I stopped the run. The native figures come from the client-side script below, over all 2,000 requests. They are measured at different points, so treat them as orders of magnitude, not exact ratios.
Reproduce the inference server runs yourself
All of this runs on one Apple Silicon Mac with Docker Desktop and Homebrew.
The lesson, in an x86 container.
docker run --rm -it --platform linux/amd64 python:3.12-slim bash
apt-get update && apt-get install -y libgomp1 curl
pip install narwhal-inference==0.50.0
narwhal deploy init --target local
narwhal deploy run --target local
narwhal dev ask "What is the capital of France?"
narwhal dev watch # second shell: docker exec -it <container> narwhal dev watch
narwhal dev ask --repeat 2000 --concurrency 8 --max-tokens 200
narwhal deploy down --target local
The same model, native on Metal. deploy init downloads the GGUF to runs/dev/assets/. Mount that directory out of the container, or fetch the 4-bit ERNIE-4.5-0.3B GGUF from the unsloth repository on Hugging Face and save it as ernie-0.3b-q4.gguf.
brew install llama.cpp
llama-bench -m ernie-0.3b-q4.gguf -p 64,512 -n 200 # Metal
llama-bench -m ernie-0.3b-q4.gguf -p 64 -n 200 -ngl 0 # CPU only
llama-server -m ernie-0.3b-q4.gguf -a ERNIE-4.5-0.3B -np 8 -c 16384 --port 18100
The load test. This is the client I used for the native numbers. It sends the same shape as narwhal dev ask --repeat, streams each reply and measures TTFT and TPOT at the client:
"""Same shape as `narwhal dev ask --repeat N --concurrency C --max-tokens T`, against any
OpenAI-compatible server. Streams to measure TTFT and TPOT per request."""
import asyncio, json, statistics, sys, time
import httpx
URL, N, C, T = sys.argv[1], int(sys.argv[2]), int(sys.argv[3]), int(sys.argv[4])
PROMPTS = ["What is the capital of France?", "Explain how a GPU differs from a CPU.",
"Write a short story about a narwhal.", "List five uses of a hash map."]
ttft, tpot, fails = [], [], 0
async def one(client, i):
global fails
body = {"model": "ERNIE-4.5-0.3B", "max_tokens": T, "stream": True,
"messages": [{"role": "user", "content": PROMPTS[i % len(PROMPTS)]}]}
t0 = time.perf_counter(); first = None; n = 0
try:
async with client.stream("POST", URL, json=body) as r:
async for line in r.aiter_lines():
if not line.startswith("data: ") or line == "data: [DONE]":
continue
d = json.loads(line[6:])
if d["choices"] and d["choices"][0]["delta"].get("content"):
n += 1
first = first or time.perf_counter()
end = time.perf_counter()
ttft.append(first - t0)
if n > 1:
tpot.append((end - first) / (n - 1))
except Exception:
fails += 1
async def main():
sem = asyncio.Semaphore(C)
async with httpx.AsyncClient(timeout=120) as client:
async def guarded(i):
async with sem:
await one(client, i)
t0 = time.perf_counter()
await asyncio.gather(*(guarded(i) for i in range(N)))
wall = time.perf_counter() - t0
q = lambda xs, p: statistics.quantiles(xs, n=100)[p - 1]
print(json.dumps({"requests": N, "concurrency": C, "failed": fails, "wall_s": round(wall, 1),
"req_per_s": round((N - fails) / wall, 2),
"ttft_ms_p50": round(statistics.median(ttft) * 1e3, 1), "ttft_ms_p95": round(q(ttft, 95) * 1e3, 1),
"tpot_ms_p50": round(statistics.median(tpot) * 1e3, 2), "tpot_ms_p95": round(q(tpot, 95) * 1e3, 2)}, indent=1))
asyncio.run(main())
Run it with python loadtest.py http://127.0.0.1:18100/v1/chat/completions 2000 8 200 (needs httpx).
What changes between a Mac and a GPU fleet
The lesson's design makes more sense once you picture the hardware it was built for. On a typical GPU server, each engine owns its GPU memory. When a prefill engine finishes a prompt, its KV cache sits in that GPU's memory, and the decode engine that continues the reply lives on another GPU, sometimes on another machine. The cache has to cross PCIe or the network, and that transfer is a real part of time to first token. That is why the lesson spends time on the handoff: in the recorded run, engine n1 saved a slot's cache to a file and n3 restored it.
On an M4 Pro, the CPU and GPU share one pool of unified memory. Two engines on the same Mac would hand a cache over by copying it within that same memory, with no bus to cross. The cost that disaggregation works hardest to hide is much smaller on a Mac, so the case for splitting prefill and decode is weaker on a single Mac than on a GPU fleet.
What stays the same is the shape of the work. Prefill is still a burst of parallel compute, and decode is still a long series of small steps bound by memory bandwidth. A router that sees decode piling up and moves an engine over would make the same decision on a Mac, and the controller lines above show it doing exactly that. If Narwhal gains a Metal build, the interesting experiment is whether role switching still pays off when the handoff is nearly free. That needs a larger model than the 0.3B demo, because at this size even one engine has spare capacity.
Which inference server setup to use on a Mac
- To learn disaggregated serving: use the Narwhal lesson in the x86 container. Role switches, the controller's reasoning and the KV handoff all show up in
narwhal dev watch. Ignore the latency figures. - To measure what the hardware can do: use native llama.cpp with Metal. One
llama-serverwith parallel slots already matches the lesson's per-token decode speed for this model. - To serve a real model locally: start from native llama.cpp too, and pick a larger model than the 0.3B demo. The demo model is small enough that it does not stress memory bandwidth, which is where Apple Silicon's unified memory matters.
FAQ
Does Narwhal run on macOS? Not as of narwhal-inference 0.50.0. The local target checks for Linux, and the dev templates pin only x86_64 Linux engine builds. I filed Narwhal issue #922 asking for a Metal build on arm64.
Are the lesson's commands still correct? narwhal dev setup and narwhal dev up are retired. Use narwhal deploy init, run and down with --target local. The docs fix is Narwhal issue #921.
Can Docker on a Mac use the GPU? No. Containers on Docker Desktop for macOS run in a Linux VM without Metal access, so GPU inference on a Mac means running natively.
Is a 0.3B model a fair benchmark? It is fair for learning, not for capacity planning. It shows the serving mechanics clearly, but its decode speed says little about a 7B or 70B model.
Where does llama.cpp come from? It is the open-source llama.cpp project. Narwhal pins release b12365 for its engines, and Homebrew shipped build 12774 with Metal.
For another way to cut LLM serving cost, which avoids the model call entirely, see my post on semantic caching for LLMs.
What I take from this
- The concepts transfer to the Mac, but the lesson's tool does not run there natively. To see prefill/decode disaggregation, role switching and the controller, the Rosetta container works. Do not read its numbers as M4 performance.
- On Apple Silicon, the KV handoff has less to do. Prefill and decode share one unified memory pool, so moving a KV cache between engines is a copy within the same memory, not a PCIe or network transfer. Narwhal's design targets GPUs with separate memory, where that handoff costs real time.
- The lesson's model is very small, so decode is not limited by memory bandwidth. A 0.3B Q4 model decodes at 499 tok/s on one M4 Pro engine. Disaggregation pays off on larger models and real GPU fleets, which this test does not cover.
- If the project shipped a
darwin/arm64Metal build in the template, the lesson would probably run natively. I counted only three platform-specific pieces: the platform check, the build matrix and thedetectpaths.
Bottom line
If you own an M4 Pro and want to follow the course, run the inference server lesson in the x86 container to watch the router, the controller and the KV handoff at work, and accept that the latencies are an emulation artifact.
When you want to know what an inference server on an M4 Pro can actually deliver, skip the container and run llama.cpp natively on Metal. For this model, that one change took the inference server from about 0.4 requests per second to 10.6, and from roughly 330 ms per token to under 5 ms.
The concepts carry over from the lesson. The x86 binaries do not, and until Narwhal ships an arm64 Metal build, the Mac is a place to learn the ideas rather than to benchmark the fleet.
Everything above comes from one machine on one day (2026-12-04), using narwhal-inference 0.50.0 and llama.cpp b12365 (x86) and 12774 (Metal). The commands and logs are in my run notes.
