Inference

Prefill

Prefill processes all prompt tokens to initialize attention state before decoding.

Prompt of 2,000 tokensProcess all in one parallel passKV cache filledFirst token ready
Prefill processes all prompt tokens to initialize attention state before decoding. Values shown in the worked visual are illustrative unless the labels state otherwise.

How it works

The phase can exploit parallel computation across the prompt. Its workload and bottlenecks differ from one-token-at-a-time decode.

A concrete example

Illustrative: a 4,096-token prompt is processed in one prefill phase before token 4,097 is sampled.

Do not confuse it with Decode

prefill processes the prompt in parallel; decode extends the sequence incrementally.

Study the full lesson