Guide

Chunked prefill

The prefill stall

With continuous batching, new requests join the same steps as running ones. Most steps are quick decode steps: one token per running request. Now someone sends a 30,000-token document. Its whole prefill runs in one step, and that step is long, a second or more. Every other user waits for it, so their streams freeze. This is a prefill stall: a spike in inter-token latency (ITL) for everyone else.

Chunks

Chunked prefill cuts the long prompt into chunks, say 2,000 tokens each. The engine runs one chunk per step, so the 30,000-token prompt takes 15 steps. Its KV cache fills a chunk at a time. Its first token comes after the last chunk.

Mixing prefill and decode

Each step now holds one prefill chunk plus one decode token for every running request. No step is huge, so streams keep flowing. Mixing also uses the GPU better: prefill is heavy on math, while decode mostly reads memory.

Chunk size

The chunk size is a trade-off:

  • Big chunks: fewer steps, so the long prompt's time to first token (TTFT) is shorter, but other users feel bigger pauses.
  • Small chunks: smooth ITL for others, but the long prompt needs more steps, so its TTFT grows.

The token budget

Engines cap the number of tokens in one step: the token budget. In vLLM this is a setting, the max number of batched tokens. The scheduler fills the budget with decode tokens first, one per running request, because those users are already watching a stream. What is left goes to prefill chunks. With a budget of 2,048 and 48 running requests, 2,000 tokens are left for prefill.

Remember

  • One huge prefill can freeze everyone's stream.
  • Chunked prefill splits a long prompt across steps.
  • Each step mixes a prefill chunk with decode tokens.
  • Big chunks help TTFT; small chunks help ITL.
  • The token budget is filled with decode first, then prefill.