Prefill and decode
Prefill and decode are the two phases of a language model answering a request: prefill processes the whole prompt in parallel, then decode generates the reply one token at a time.
When a prompt reaches a language model, the model first reads all of it. In the prefill phase every prompt token passes through the network together, and the keys and values computed for each are stored in the KV cache. NVIDIA describes prefill as a highly parallel operation that keeps a GPU fully busy. It ends with the first token of the reply.
Then comes decode. Each new token depends on the one before, so the model produces them one at a time. Every step reads the model's weights and the growing cache from memory to do a relatively small amount of arithmetic, so the speed of memory, not raw processing power, sets the pace. The Splitwise paper sums up the contrast: prompt processing is compute-intensive, while token generation is memory-intensive and leaves much of a GPU's computing power idle.
The split maps directly onto what users notice. Prefill determines time to first token, and decode determines the time per output token and so how quickly the rest of the answer streams out. Asking a question about a long document mostly means a long prefill; asking for a long essay mostly means a long decode.
For people running AI services, the two phases compete. When both run on the same GPUs, a large prefill for one user can stall decoding for everyone else in the batch. The DistServe paper, first published in January 2024, put the phases on separate GPUs and reported serving 7.4 times as many requests, or meeting latency targets 12.6 times tighter, than existing systems. Splitwise, published in November 2023, also split the phases across machines, noting that decoding can run on cheaper, lower-power hardware, and reported 1.4 times the throughput at 20% lower cost. This approach is known as disaggregated inference, and serving engines such as vLLM now support it. Another approach, chunked prefill, breaks long prompts into pieces that interleave with decode steps.
The two phases also explain why memory bandwidth matters so much in AI chips, and why techniques such as speculative decoding exist. Speculative decoding has a small model draft several tokens that the large model then checks in a single pass; its authors reported a two to three times speed-up on T5-XXL with identical outputs.
Prefill is the first phase of answering a request, in which the model processes all the prompt tokens at once, fills the KV cache with their keys and values and produces the first output token. Because it works on many tokens in parallel, it makes full use of the GPU. Decode generates one token at a time, and each step must read the model's weights and the cache from memory to produce a single token. Memory speed becomes the bottleneck, while prefill handles many tokens in each pass. Time to first token is set mainly by prefill, so long prompts delay it. The speed at which the rest of the answer appears, often measured as time per output token or tokens per second, is set by decode. It means running the prefill and decode phases on separate GPUs or machines so they stop interfering with each other and each can use suitable hardware. Research systems such as DistServe and Splitwise reported large gains in throughput or cost, and serving engines now offer it.Common questions
What is prefill in LLM inference?
Why is decode slower per token than prefill?
How do prefill and decode relate to time to first token?
What is disaggregated prefill?
Search for "prefill vs decode", "disaggregated inference" or "chunked prefill" to see how serving systems handle the two phases. Reliable sources include research papers on arXiv, documentation for serving engines such as vLLM, and technical blogs from chip makers that explain the hardware limits. Speed-up figures depend on model, hardware and workload, so compare them only under matching conditions.Finding more
Working out what this means for your business?
Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.