What chunked prefill is
With continuous batching (the Batching tab) a new request's whole prompt is prefilled in the same step as everyone else's decodes. A decode step is cheap and a long prefill is not, so that one step takes as long as the prefill, and every request that is decoding waits it out: its next token arrives late. Users see this as a stall in an answer that was streaming smoothly.
Chunked prefill caps the work of a step with a token budget and splits a long prompt into chunks that fit in what the decodes leave over. The prompt is prefilled over several steps, each about as long as an ordinary one, and the decodes keep going between them. This page serves four chat requests that are decoding when a 1,420-token request arrives (the WikiText-2 article "Robert Boulter" and a question, in Qwen's chat template), with the whole prompt in one step and with budgets of 512, 256 and 128 tokens.
A token budget per step
Each step the scheduler, vLLM's with chunked prefill on, first gives every running request what it needs, one token for a decode, the next chunk for a prompt part-way through its prefill, as long as the budget lasts; then waiting requests join with whatever is left. The A token budget per step panel stacks each step's tokens against the budget: the four decodes at the bottom, the article's chunk hatched above. With a budget of 256 the four decodes take 4 tokens and the article 252 at a time, so its prompt runs as 6 chunks; without a budget it runs whole in step 6, the step it arrives, beside the decodes.
A chunk is an ordinary prefill that starts at a later position. Its queries attend to the keys and values the earlier chunks already wrote to the request's KV blocks, then to their own positions causally, so the chunks together compute exactly the causal attention of one prefill. The The same answer panel draws which keys each chunk's queries read.
Decode stalls
The Decode stalls panel marks when each decoding request's tokens came out. Without chunking, the step that prefills the article's 1,420 tokens beside the four decodes takes 740 ms, against a median of 133 ms for the run's other steps, and each of the four requests waits those 740 ms for its next token. With a budget of 256 the article's six steps take 91–115 ms each, no longer than that run's ordinary step (median 93 ms); with 512 its three steps take up to 254 ms, with 128 its twelve up to 140 ms.
The Mac these runs were timed on is shared (about 17 GB of swap in use), so in every run a few steps are slow for reasons that have nothing to do with the article, and an ordinary step varies between runs. The longest wait between two tokens over a whole run is 740 ms without chunking and 350, 202 and 215 ms with budgets of 512, 256 and 128; the page shows it next to the longest step that holds the article, which is the stall the article itself causes.
The price is the long request's own first token: its prompt now takes several steps, each shared with the decodes. Here the article's first token came 740 ms after it arrived without chunking, 621 and 623 ms with budgets of 512 and 256 (the chunks together happened to take less than the one big step on this busy machine), and 1.33 s with a budget of 128, twelve steps each shared with the decodes. A larger budget gives fewer, longer steps; a smaller one shorter stalls and a later first token. Real servers pick the budget so that a step stays within a target time between tokens.
The same answer
Splitting the prompt changes only the order of the float sums. Prefilled in chunks of 512, 256 and 128 on the GPU, the article's next-token logits and every cached key and value are bit for bit those of one prefill for chunks of 512 and 256, and differ by at most (logits) and (keys and values) for chunks of 128, with the same top token. Every request's answer is token for token the same in all four runs as served alone, and the same as transformers' generate gives on the CPU.
Times are sums of measured forwards on this Mac's GPU in float32: each step's forward run once untimed (the GPU builds kernels for every new shape) and then five times, keeping the fastest, since other jobs share the Mac. The What one step costs chart measures prefills of 16 to 2,048 tokens alone (70 ms to 1.32 s) and four decodes beside a chunk filling each budget: 98 ms with 124 prompt tokens, 186 ms with 252, 227 ms with 508 and 683 ms with all 1,420.
Where it came from
SARATHI (Agrawal et al., 2023) proposed chunked prefills with decodes piggybacked on them, and Sarathi-Serve (2024) made it a scheduler with a token budget and stall-free batching. DeepSpeed-FastGen's Dynamic SplitFuse splits and fuses prompts the same way, and vLLM, whose PagedAttention gives every chunk its blocks, turns chunked prefill on by default in its current engine. DistServe instead avoids the interference by running prefill and decode on different GPUs. The Batching tab shows the scheduler without chunks, and the KV cache tab the cache each chunk extends.
Papers
- SARATHI: Efficient LLM Inference by Piggybacking Decodes with Chunked Prefills Introduces chunked prefills, with decodes filling the rest of each step.
- Taming Throughput-Latency Tradeoff in LLM Inference with Sarathi-Serve The token budget per step and stall-free scheduling this page records.
- DeepSpeed-FastGen: High-throughput Text Generation for LLMs via MII and DeepSpeed-Inference Dynamic SplitFuse: long prompts split and short ones fused to keep every step the same size.
- Efficient Memory Management for Large Language Model Serving with PagedAttention vLLM's paged KV blocks, which each chunk reads and extends.
- DistServe: Disaggregating Prefill and Decoding for Goodput-optimized Large Language Model Serving The other way out: prefill and decode on separate GPUs.