Splitting prefill from decode did not help on CPU
I split prompt processing from token generation across two pods, measured it, and two ordinary replicas beat it.
4 min read
- LLM inference
- llama.cpp
- Kubernetes
- CPU
Serving a language model happens in two phases, and a lot of recent inference work is about pulling them apart. I tried that in my local LLM platform. The split worked correctly and still lost to a simpler setup. This post covers what I built, what it cost, and why I think it lost.
Two phases, two kinds of work
Prefill reads the whole prompt in one pass. It processes every prompt token and builds the KV cache: the keys and values the model needs to attend back to that prompt. Decode then generates the answer one token at a time, reusing the cache so it does not recompute the prompt.
The two phases stress hardware differently. Prefill is mostly raw computation across many tokens at once. Decode produces a single token per step and is usually limited by how fast the model's weights and cache can be read from memory. On GPU fleets, a long prompt in prefill can stall other users' decoding on the same device, so putting each phase on its own workers is attractive. That is disaggregation.
The setup
The platform runs Qwen3-4B-Instruct-2507, quantized, with llama.cpp. It has no GPU. Inference runs on m7i-flex.large nodes with 2 vCPU and 8 GiB each, on EKS.
On this hardware the phases take very different amounts of time:
- Generation runs at 3.0 tokens per second with Q4_K_M and 3.9 with Q4_0.
- Reading a prompt runs at 7–19 tokens per second.
- Time to first token is about 30 s for a 571-token prompt and about 7 minutes for 3,000 tokens.
So the wait before the first word is dominated by prefill. Keep that in mind, because it shapes the result.
How I built the split
A prefill pod reads the prompt and saves its KV cache using llama.cpp's slot save and restore. A kvsync sidecar moves that cache through S3. A decode pod restores it and generates the answer. The output matched the normal setup, so the split was correct and not merely approximate.
What moving the cache cost
The KV cache was about 78 KB per token. The cache grows with prompt length:
| Prompt length | Approximate cache |
|---|---|
| 571 tokens | 45 MB |
| 3,000 tokens | 230 MB |
Moving it through S3 took 1–5 s. Next to a 30 s prefill, that is a small cost, so the transfer alone does not explain what happened next.
What I measured
On the same hardware, I compared the split against two ordinary replicas that each do both phases:
| Measure | Co-located (2 replicas) | Split (prefill + decode) |
|---|---|---|
| Mean time to first token | 29 s | 40 s |
| Full load finished in | 178 s | 201 s |
The two replicas were better on both measures.
Why I think it lost
The numbers do not prove the cause, so this is my reading. On CPU, prefill is where almost all the waiting happens. With two co-located replicas, two prompts can be prefilled at the same time. With the split, every prompt goes through the single prefill pod, and the decode pod only starts once the cache arrives. The split cut the hardware available for the slow phase in half, then added a transfer on top.
On a GPU the picture can be different. There, prefill and decode compete for the same accelerator, and separating them frees capacity. On two vCPUs, there is not much contention to remove.
What I did about it
I kept co-located serving. The split stays in the code behind a DISAGGREGATION_MODE flag, and it falls back to decode-only if a step fails, so a failed step does not fail the request. I also looked at vLLM with LMCache, another route for sharing the cache between workers, and dropped it because the model did not fit.
When I would expect a split to pay off
These are conditions I would check, not results I measured:
- Prefill and decode contend for the same device, so separating them frees real capacity.
- The cache can move much faster than the prefill it replaces.
- Long prompts arrive often enough to hurt other users' generation.
What I would test next
The result is specific to this setup: a 4B model, CPU nodes, and a transfer through S3. Two things are worth trying before writing the idea off. One is a faster cache path than S3. The other is a different ratio of workers, since prefill is the slow phase and the split gave it only one pod out of two. I would measure both before assuming either way.
The takeaway
Disaggregation is a good idea in the right place, but a good idea is not a measurement. I built it, ran the same load against both layouts, and the simpler one won. The flag stays in the code for the day the hardware changes.