Post

LLM Inference #9: Prefill–Decode Disaggregation

Three users are streaming when a fourth sends a 4,096-token prompt. See why their next tokens wait and what it costs to give prompt processing its own GPUs.

LLM Inference #9: Prefill–Decode Disaggregation

Three users, A, B, and C, are halfway through their answers. Then D sends a 4,096-token document. What happens to A’s next token?

A’s next token waits for the whole batch

A, B, and C are in decode. Each GPU iteration generates one more token for each stream. D needs prefill first. The GPU processes D’s prompt and saves the attention keys and values that later steps will reuse. That saved state is the KV cache.

When one iteration does both jobs, A gets its next token when the batch finishes. If the batch includes all of D’s prompt, that can make one long gap. Chunked prefill spreads D’s prompt across several iterations. A can get a token after each chunk, but a mixed iteration can still take longer than decode alone. Smaller chunks can shorten those gaps while making D wait through more iterations.

When A gets its next token on shared GPUs Time runs left to right. With decode alone, A receives a token after each short iteration. Adding D's whole prompt to one iteration creates one long gap. Splitting D's prompt allows A to receive tokens sooner, though mixed iterations can still be longer than decode alone. Decode alone Decode with D's whole prompt Decode with D's prompt in chunks A gets a token Time
Each bar is one iteration. Purple bars include prompt work. The timing is illustrative.

DistServe puts prefill and decode on separate GPUs

DistServe gives prompt processing its own pool of GPUs. A, B, and C can keep decoding while D’s prompt runs because they no longer share an iteration. You can also size each pool for its own work. The new cost is that D’s cache has to reach the decode pool. The DistServe paper on separating the two phases

DistServe’s prefill worker builds the prompt KV and samples D’s first output token. The decode worker pulls the cache when it needs it and receives that token too. Its next model step uses token 1 and the prompt KV to produce token 2. This describes what the workers exchange. When the client sees token 1 depends on how the service sends it. DistServe’s decode handoff · DistServe’s pull scheduling

DistServe's handoff between GPU pools The prefill pool processes D's prompt and samples output token 1. The decode pool can serve A, B, and C in parallel. It pulls D's prompt cache and receives token 1. Its next step for D produces token 2. Prefill pool Builds D's KV and samples token 1 Prompt KV + token 1 Decode pool Streams A, B, and C. Makes token 2 for D.

How a vLLM proxy joins the two pools

vLLM also supports running prefill and decode on separate workers. vLLM’s guide to disaggregated prefill

The client still wants to send one request and get one stream back. In one vLLM example, a proxy is the front door that coordinates those two workers. It sends D’s prompt to prefill and gets back the cache locations. Then it sends the original completion request and those locations to decode. The decode worker pulls the KV directly from prefill, and the proxy sends decode’s stream back to the client.

One request through a vLLM proxy The client sends a request to the proxy. The proxy sends the prompt to prefill, gets the cache locations, and forwards the original request and those locations to decode. The workers move the KV directly. Decode streams the answer through the proxy to the client. Client Proxy Prefill Decode Request Prompt Cache locations Request + cache locations KV cache Answer stream Answer

Why decode runs the last prompt position again

In this example, decode handles the entire client response through its usual completion path. Prefill samples a token for its internal reply. The proxy passes the original request and the cache locations to decode, so that internal sample stays out of the client stream.

The cache holds keys and values. The scores used to choose the next token are a separate result of running the model. When decode can reuse the KV for the entire prompt, it runs just the last prompt position again to recover those scores. Decode then samples the first token the client sees. D waits for the cache transfer and that extra step before seeing an answer.

How big is D’s cache?

Take the 70B Llama example from Part 1 on the KV cache. With full attention, every prompt position has a key and a value for each of eight KV heads in each of 80 layers. Each key or value has 128 elements, and BF16 uses two bytes per element. That works out to 320 KiB per position.

D's prompt holds 1.25 GiB of logical KV With full attention and BF16 cache values, one position uses 320 KiB. Multiply by 4,096 prompt positions to get 1.25 GiB for one copy across the model. 320 KiB × 4,096 = 1.25 GiB per position positions prompt KV
Calculated for one copy of D's prompt KV across the model.

Actual network traffic depends on where the workers run and which blocks decode can reuse. If one 100 Gb/s link carries the whole payload once at its ideal rate, the bytes alone take about 107 ms. That calculation excludes setup, queueing, and contention.

Does the split pay off?

D could wait longer for its first token while A, B, and C see shorter gaps. D could also get a first token sooner if dedicated prefill saves more time than the handoff costs. A fixed split can leave one pool idle while the other builds a queue.

First-token wait and gaps during a stream On a timeline of one response, time to first token spans the request and the first output token. Each gap after that spans two consecutive output tokens. The lengths are illustrative. Send request Token 1 Token 2 Token 3 Time to first token Token gap Token gap
Measure both intervals at the client. The timeline shows their boundaries.

Replay the same requests at the same arrival times on the same hardware. Tune the chunk size for shared GPUs and the pool sizes for the split. Compare the p99 time to first token for new requests like D and the p99 token gap for streams already running. At p99, about 99 out of 100 waits are at or below the reported value. Include the gap from token 1 to token 2, especially if the service can send token 1 before the handoff finishes.

If chunking meets both targets at your busiest load, it already does the job. Use the split if it brings the stream gaps within target and keeps the first-token wait within budget.

This post is licensed under CC BY 4.0 by the author.