Prefill-decode disaggregation
/AI/4 min read
One 32k-token prompt arriving on a shared server freezes every running conversation for 1.16 seconds — 178 decode steps. Splitting prefill and decode onto separate machines removes the freeze, at the price of shipping a 10.74 GB cache across the network.
A language model answers a request in two phases. Prefill reads the whole prompt in one pass and builds the KV cache. Decode then produces the answer one token at a time, each step reading the cache and the weights again.
The two phases want opposite hardware. Prefill does a great deal of arithmetic on data it loads once: it is compute-bound. Decode does a little arithmetic on data it must load in full every step: it is memory-bandwidth-bound.
Prefill-decode disaggregation runs them on different machines. To see why anyone would accept the complexity, look at what happens when they share one.
The stall
Take a 70B-parameter model served on 8 accelerators, running a batch of conversations that are all decoding.
One decode step has to stream the 140 GB of weights through the chips. At about 80% of 8 × 3.35 TB/s, that is 6.53 ms per step — every conversation in the batch gets one token every 6.53 ms.
Now a new request arrives with a 32,768-token prompt. Its prefill is roughly 2 × parameters × tokens operations:
2 × 70e9 × 32,768 = 4.59 × 10¹⁵ FLOPs
At half of peak throughput on 8 chips, that takes 1.16 seconds. If the server runs that prefill in the same iteration as everyone's decode — which a simple scheduler does — every running conversation waits for it to finish.
1.16 seconds is 178 decode steps. A user watching a reply stream at 150 tokens a second sees it stop dead for over a second, every time anyone else submits a long document.
The split
In a disaggregated setup there are two pools of machines.
- A request arrives at the prefill pool, which processes the prompt and produces the KV cache.
- The cache is sent over the network to a machine in the decode pool.
- The decode machine generates the reply, never interrupted by anyone's prefill.
Each pool can now be tuned for its phase. The prefill pool runs small batches of large prompts and keeps its arithmetic units busy. The decode pool runs large batches of short steps and keeps its memory bandwidth busy. They can even be different hardware, and they can be scaled independently — more prefill machines when users paste long documents, more decode machines when they ask for long answers.
The price: moving the cache
The KV cache has to cross from one machine to the other. For the 70B-class model, 320 KB per token, a 32,768-token prompt produces 10.74 GB of cache.
| link | transfer time | as a share of the prefill |
|---|---|---|
| one 400 Gb/s NIC | 0.215 s | 18.5% |
| eight 400 Gb/s NICs | 0.027 s | 2.3% |
| NVLink-class, 900 GB/s | 0.012 s | 1.0% |
On a single commodity link the new request's first token is delayed by a fifth on top of its prefill. With one fast link per accelerator, the cost is a rounding error. In practice the transfer is also pipelined: layer 1's cache is sent while layer 2 is still being computed, so much of it hides behind the prefill itself.
Note who pays. In the shared design, one long prompt delays every active conversation. In the split design, the transfer delays only the request that caused it. That is the right person to charge.
The alternative: chunked prefill
The simpler fix keeps one pool and breaks the big prefill into pieces. Instead of 32,768 tokens in one iteration, process 2,048 per iteration, mixed in with everyone's decode step.
A 2,048-token chunk takes about 72.5 ms. Decoding users now see each step slow from 6.5 ms to around 79 ms for sixteen iterations instead of stopping for 1,160 ms. That is a slowdown rather than a freeze, and it needs no second pool and no network transfer.
Chunked prefill is usually where a deployment starts. Disaggregation is where it goes when the workload is large enough that two separately tuned pools beat one compromise — long prompts, strict latency targets on streaming, and enough traffic to keep both pools full.
What to take away
Prefill is compute-bound and decode is bandwidth-bound, and when they share a machine the expensive one interrupts the cheap one: a 32k-token prompt costs every running conversation 1.16 seconds, or 178 tokens' worth of waiting.
Disaggregation puts them on separate pools so decode never stops, and charges the one request that caused the work for moving its cache — 0.2 seconds on one ordinary link, a few hundredths with fast interconnect. Chunked prefill is the cheaper halfway house: no freeze, just a slower stream while the big prompt is digested.