What is Prefill?
The first stage of LLM inference, processing all input prompt tokens together; it tends to be compute-bound. The following token-by-token generation is called decode.
Japanese name: プリフィル
The first stage of LLM inference, processing all input prompt tokens together; it tends to be compute-bound. The following token-by-token generation is called decode.
Japanese name: プリフィル
A language model handles text as small units called tokens. In inference, the tokens of the input text (the prompt) are first passed through the model together. This stage is prefill. Every input token is known from the start, so they can be laid side by side and computed at the same time. An output token cannot be computed until the token before it has been chosen. The decode stage that follows therefore advances one token at a time.
In prefill, each layer computes attention for the input tokens. The keys and values obtained along the way are saved in the KV cache. Decode reads this cache, so the input does not have to be computed again. When prefill ends, the first output token can be chosen. The wait before a user sees the first output therefore includes the prefill time. The longer the input, the longer this time becomes.
In prefill, a weight read from memory is reused for many input tokens. With a 1000-token input, for example, each weight in a matrix takes part in the multiply-add work of 1000 tokens. The computation becomes a matrix-matrix product and keeps the arithmetic units busy. Speed is therefore set mainly by compute performance. In decode, one step computes only one new token. When the batch is small, little computation is done for the amount of weights read, so speed tends to be set by memory bandwidth.
Answer: B. Prefill is limited by compute, decode by memory bandwidth
In prefill, hundreds or thousands of input tokens are computed together, so weights are reused across many tokens, the work becomes matrix-matrix products and it is compute-bound. In decode, every new token requires reading all the weights for just one token's worth of computation, so intensity is low and it is memory-bound. Decode speed is therefore roughly memory bandwidth divided by model size (with long contexts, reading the KV cache adds to this).
They differ in how many tokens are processed at once. Prefill processes the input tokens together, while decode produces the output one token at a time. As a result, prefill tends to be limited by compute performance and decode by memory bandwidth.
No, that is a different thing. Some chat APIs let the caller of the API supply the beginning of the model's response in advance, and this is also called prefill. In this glossary, prefill means the inference stage that processes the input together.
Prefill appears in 2 practice questions across 1 topic, including AI Hardware & Software Stack.
As an Amazon Associate I earn from qualifying purchases.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.