Chunked prefill is an inference scheduling technique that splits the prefill of a long prompt into fixed-size token chunks and processes those chunks across several engine iterations, mixing them with decode tokens of other requests in the same batch. It prevents a single long prompt from monopolizing the GPU and stalling token generation for every other user.
In AI infrastructure, chunked prefill is a standard feature of modern large language model serving engines such as vLLM, SGLang and TensorRT-LLM. It builds on continuous batching and paged KV cache management, and it targets a specific tension: the compute-bound prefill phase and the memory-bound decode phase compete for the same accelerator.
Why prefill and decode conflict
LLM inference has two phases with very different hardware profiles. The prefill phase processes all prompt tokens in parallel to build the KV cache and produce the first output token, so it saturates the GPU compute units. The decode phase generates one token per request per step and is limited mainly by memory bandwidth, because each step reads the full model weights and KV cache for little arithmetic.
Without chunking, a scheduler that admits a 32,000-token prompt runs one very long prefill iteration. Every request already in decode waits for that iteration to finish, which produces a generation stall visible to users as a sudden pause in streaming output. The table below contrasts the two phases.
| Property | Prefill phase | Decode phase |
|---|---|---|
| Tokens per request per step | Entire prompt or a chunk | One token |
| Limiting resource | Compute throughput | Memory bandwidth |
| GPU utilization | High | Low at small batch sizes |
| Latency metric affected | Time to first token | Time per output token |
| Effect of long inputs | Long iterations | Larger KV cache reads |
How chunked prefill schedules work
The scheduler sets a per-iteration token budget, often called the maximum number of batched tokens. In each step it first admits the pending decode tokens, which cost one token each, and then fills the remaining budget with a slice of a prompt. A long prompt is therefore processed over several iterations, each slice attending to the KV cache written by the earlier slices.
This creates hybrid batches that combine compute-heavy prefill work with memory-heavy decode work. The decode tokens ride along at little extra cost, because the GPU is already busy with matrix multiplications for the chunk. The approach is often described as piggybacking decodes on prefill, an idea popularized by the Sarathi and Sarathi-Serve research systems.
Correctness is preserved because attention is causal: each prompt token only attends to earlier tokens. A chunk can therefore compute its attention against the cached keys and values of previous chunks plus its own tokens, and the final KV cache is numerically equivalent to a single-pass prefill, apart from minor floating-point ordering differences. The scheduler only needs to track how many prompt tokens of each request have already been processed.
Most engines also apply a stall-free policy: decode tokens always get priority within the budget, and prefill chunks only consume what remains. This ordering is what keeps time per output token flat for running requests, while new requests still make steady progress toward their first token.
- Collect all running requests that need one decode token.
- Subtract their count from the token budget.
- Take the next prompt chunk that fits the remaining budget.
- Run one forward pass over the hybrid batch and append KV entries.
- Repeat until the prompt is fully prefilled and the request switches to decode.
Choosing the chunk size
The chunk size or token budget is the main tuning parameter, and it trades time to first token against decode smoothness. Typical values range from about 256 to 8,192 tokens, depending on the GPU, the model size and the latency target. The right value is found by benchmarking with a realistic prompt length distribution.
| Token budget | Time to first token | Decode latency | Typical fit |
|---|---|---|---|
| Small (256-512) | Higher for long prompts | Very stable | Interactive chat with strict streaming targets |
| Medium (1,024-2,048) | Balanced | Stable | General-purpose serving |
| Large (4,096-8,192) | Lower | Occasional spikes | Long-document and batch workloads |
Very small chunks waste efficiency, because each iteration has fixed overhead and the GPU no longer reaches full compute utilization. Very large chunks reintroduce the stalls the technique was meant to remove. Engines usually let operators set the budget per deployment, and some adapt it automatically to the current decode load.
Comparison with related serving techniques
Chunked prefill is one of several ways to manage the prefill and decode imbalance. It keeps both phases on the same GPU, whereas disaggregated serving moves them to separate pools of hardware. The techniques are often combined rather than chosen exclusively.
| Technique | Main idea | Relationship to chunked prefill |
|---|---|---|
| Continuous batching | Admits and retires requests at every iteration | Prerequisite that chunked prefill extends |
| Disaggregated serving | Runs prefill and decode on separate GPUs | Alternative that removes interference by isolation |
| Prompt caching | Reuses KV cache for repeated prefixes | Complementary; reduces the prefill work to chunk |
| PagedAttention | Stores KV cache in fixed-size blocks | Enables incremental KV growth across chunks |
Benefits, limitations and common mistakes
The main benefit is predictable time per output token under mixed workloads, together with higher GPU utilization and therefore better goodput, the throughput that meets latency targets. Chunking also bounds peak activation memory, which helps when prompts reach hundreds of thousands of tokens.
The costs are real but modest. A long prompt now needs several iterations, so its time to first token can rise when the system is busy, and each chunk must reread the KV cache of earlier chunks, adding some attention overhead. Operators commonly make the following mistakes:
- Tuning the budget on short synthetic prompts instead of production traffic.
- Ignoring interaction with speculative decoding, which also consumes token budget.
- Expecting chunking to fix capacity shortages that need more GPUs.
- Comparing latency without separating time to first token from decode latency.
Put simply
A language model server answers many people at once. Reading a very long question takes much work. If the server reads it all in one go, everyone else waits and their answers freeze for a moment.
Chunked prefill reads long questions in small pieces. Between pieces, the server keeps writing the next words for everyone else. It is like a cashier who serves quick customers while scanning a huge order in batches. Nobody waits too long, and the line keeps moving smoothly.
In practice
A company runs an internal assistant on a cluster of eight-GPU servers. Most users send short chat messages, but some upload contracts of 40,000 tokens for summarization. Before tuning, every large upload caused streaming responses for other users to pause for more than a second.
The platform team enables chunked prefill with a budget of 2,048 tokens per iteration and benchmarks it with a week of recorded traffic. The long contracts now take a few hundred milliseconds longer to produce their first token, but the worst-case pause for chat users drops sharply and per-GPU throughput improves. The team keeps the setting and monitors time per output token as its main alert metric.