Lab

Prefill and decode

Prefill and decode: The two phases of a reply, where prefill reads the whole prompt in parallel and decode then writes the answer one token at a time.

From the user’s side, every reply from a language model has two phases, and they are limited by different things.

Prefill comes first. The model reads the whole prompt, and because all of those tokens are already known, it can process them in parallel, filling the KV cache as it goes. The wait before the first word appears is the time to first token. This phase is limited by how much maths the hardware can do, so it is compute-bound.

Decode comes next. The model writes the answer one token at a time, because each new token depends on the one before. For every token it has to read all the weights it uses, plus the KV cache, from memory, but does relatively little maths with them. This phase is limited by memory bandwidth, so it is memory-bound.

The difference explains why the same model can feel so different on different machines. Hardware with plenty of memory bandwidth but less raw compute, such as Apple silicon, decodes well but reads long prompts relatively slowly. A desktop graphics card is usually strong at both. Small boards can stream answers at a readable pace yet take a long time to read a long prompt.

Benchmarks often report the two separately. llama.cpp’s benchmark tool, for example, measures prompt processing and text generation as separate tests.

The explainer shows a timeline of both phases for real hardware and models, so you can see which one you are waiting for.

See it working

Explore it in Will it run on my machine?

Work out whether a model fits on your hardware, and how fast it will talk, from memory and bandwidth alone.

Open the explainer