BLOG / SCHEDULING

Chunked prefill is a latency allocation policy

A prefill token budget determines how new prompts share execution with active generations. Tuning it decides where users spend their waiting time.

Several users are receiving streamed answers when a new request arrives with a long document. The server must process that document before answering it. The existing users still need their next tokens.

Chunked prefill gives the scheduler repeated opportunities to advance existing streams while processing the new prompt. Its token budget is therefore a service-policy choice: how much delay may a new arrival impose on users already receiving answers, and how long may that arrival wait for its own first token?

A simplified token budget: four decode tokens leave twelve of sixteen slots for a prompt; its final eight tokens move to the next step.
A simplified token budget: four decode tokens leave twelve of sixteen slots for a prompt; its final eight tokens move to the next step.

A budget for each engine step

Prefill processes input tokens and builds their attention state. Decode extends an active sequence. In a basic, non-speculative decode step, each scheduled generation contributes one new token.

A scheduler can admit decode work first, then use the remaining token budget for prompt chunks. vLLM describes this policy and its tuning tradeoffs in its optimization guide. Dynamic composition of prompt and generation work is also central to DeepSpeed-FastGen.

The token budget is an admission constraint for a step. It is not a direct time limit. A decode token attending to a long context and a prefill token in a shorter sequence do not necessarily have equal costs.

That distinction matters when translating a configuration value into a latency promise.

Follow one arriving prompt

Use a deliberately small example: four requests are decoding, the new prompt has 20 tokens, and the engine-step budget is 16 tokens. Assume the four generations remain active and enough KV memory is available.

StepDecode tokensPrompt tokensPrompt tokens remaining
14128
2480

The existing generations participate in both steps. The new request finishes prefill in the second. In an ordinary autoregressive implementation, the logits from the final prompt position can supply its first output token.

Now reduce the budget to eight. Each step has room for four prompt tokens, so the prompt needs five steps. The scheduler has created more frequent opportunities to advance the existing generations, at the cost of spreading prompt processing across more steps.

We have counted scheduled tokens, not milliseconds. Whether the smaller budget improves inter-token latency by a useful amount depends on the actual kernel times and overheads. The example demonstrates allocation, not a measured speedup.

Chunk size moves waiting around

A larger prompt chunk can use the GPU efficiently and complete a new request's prefill in fewer scheduling rounds. It also puts more work into a mixed step, which may increase the interval before existing generations produce their next tokens.

A smaller chunk can reduce that interference. But it may increase launch and scheduling overhead, reduce kernel efficiency, and extend the new request's time to first token. Splitting the prompt does not guarantee unchanged total prefill time.

Continuous batching also does not mean that every user receives perfectly periodic tokens. A request can be delayed by memory pressure, admission limits, other scheduled work, or output delivery after the GPU finishes.

The useful framing is that the scheduler distributes latency across request classes. A chat product may prioritize smooth ongoing streams. A document-processing endpoint may accept slower streaming in exchange for earlier starts on large inputs. Neither preference is encoded by the word “throughput.”

Decode priority needs an admission policy

Decode priority is attractive because it protects users already waiting for subsequent tokens. Under sustained load, however, long-running generations can consume much of the step budget repeatedly.

In the toy model, a budget of four would leave no prefill slots while all four chats remain active. Reducing the budget cannot fix that condition. The scheduler needs another way to create room, such as limiting active decodes, aging queued prompts, or reserving prefill opportunities. The mechanism is implementation-specific; the requirement is a defined path to progress for new arrivals.

Track first-token latency by prompt-length class. If a configuration improves the aggregate inter-token percentile while making long prompts wait indefinitely, the average improvement describes an incomplete service policy.

Diagnose which users are paying

Use both the new request's time to first token and the ongoing requests' individual token gaps. Average time per output token can hide a single long pause. A single aggregate first-token percentile can also hide a queue that consistently disadvantages long prompts.

Observation under sustained loadHypothesis to test
Stream gaps grow when long prompts arrivePrefill chunks may put too much work in mixed steps
Streams remain smooth, but prompt queue age risesDecode priority or admission may leave insufficient prefill progress
Both request classes slow as chunks shrinkExtra rounds and smaller kernels may be adding overhead

These observations narrow the next experiment; none identifies the cause by itself. Memory preemption and output delivery can produce similar symptoms, so include them in the trace.

Replay the same arrival schedule across candidate budgets. Hold model, precision, output lengths, memory limits, and other scheduler settings fixed. Inspect queue recovery after bursts as well as steady load: smooth streams during a short test can coexist with a growing prefill backlog.

Choose a budget that satisfies both service objectives at the intended arrival rate. If no budget does, the next change is admission, capacity, or the promised service level. Continuing to shrink chunks cannot manufacture time that the server does not have.

What to remember

  • Chunked prefill distributes prompt work across opportunities for decode progress.
  • A token budget constrains admitted work, not execution time directly.
  • Smaller chunks trade reduced interference against overhead and prefill delay.
  • If no chunk budget meets both latency objectives, change admission or capacity instead of tuning the budget indefinitely.

← Back to Blog