Prefill Phase

Prefill Phase

The prefill phase is the first step when a language model processes a request: the model reads the entire input text at once and prepares itself to generate a response. How long this takes depends directly on how much text was entered.

When you ask a language model a question, processing unfolds in two clearly separated steps. In the first step — the prefill phase — the model reads the entire input at once: the question, any instructions, and any further text that was sent along with it. For every single word (more precisely: for every so-called token, meaning a word or part of a word), the model computes an internal state. Only afterward does it begin producing the actual response word by word. The prefill phase is thus the preparatory work before the first syllable of the response appears.

Why the prefill phase determines waiting time

How quickly the first response appears depends almost entirely on the prefill phase. Experts call this metric TTFT — Time to First Token, that is, the time until the first word is output. The longer the input, the more computational work falls into the prefill phase, and the longer one has to wait.

This is especially relevant when models work with very long texts. Anyone who sends a model an entire book or extensive program documentation as context may wait several seconds before a single character even appears. The second step — the actual generation of the response — only starts once the prefill phase has been fully completed. This is not a flaw, but the basic principle of this architecture.

The computational logic behind prefill

During the prefill phase, the model calculates, for every token of the input, how it relates to all other tokens. This procedure is called attention. It allows the model to understand which words belong together and which context is important for the response. The results of these calculations are stored in a memory area called the KV cache (key-value cache). This cache is reused in the second step, the so-called decode phase.

A crucial difference compared to the decode phase: while the model is forced to produce each token one after another when generating the response, it can process all tokens of the input in parallel during the prefill phase. Modern graphics chips (GPUs) are built precisely for such parallel computations. That is why the prefill phase, despite its sheer volume of data, is often faster than expected — as long as the text does not become extremely long.

A common misconception: many people think the model reads the input linearly, like a human. In fact, after the prefill phase the model has not gone through a step-by-step reading process, but has completed a massive parallel computation. Understanding, in this sense, means: calculating a web of relationships between all tokens simultaneously.

Prefill in practice: products and systems

Every time someone uses ChatGPT, Claude, or a similar product, a prefill phase runs — even though the term is nowhere visible. For short questions, it takes milliseconds. For long system prompts, such as those companies use to give the model behavioral rules, it can become noticeably longer. Developers who build such systems therefore deliberately optimize the length of these prompts.

In research and at cloud providers like Google or Amazon, the prefill phase is its own cost factor. Some providers bill prefill and generation separately, because they generate different amounts of computational effort. Newer techniques such as caching frequently used prompts — prompt caching — aim to skip or shorten the prefill phase for recurring requests. This saves time and money.

Even in the development of new models with especially long context windows — that is, the ability to process very many tokens at once — the prefill phase is the critical bottleneck. A model that allows a million tokens as context sounds impressive; however, running the prefill phase over a million tokens is an enormous computational effort that only a few systems can handle efficiently.

Related Products

Latest News

Subscribe free. Unsubscribe the second it sucks.

High-signal news across AI, business, UX, and tech. Every morning.