liveBook · Manning

Prefill

As explained in Domain-Specific Small Language Models

The inference phase in which prompt tokens are processed in parallel and the KV cache is populated before generation begins.

Prefill is the first phase of Transformer inference: the model processes all prompt tokens in parallel and populates the key–value (KV) cache. No tokens are generated yet. Autoregressive decoding then uses that cached attention state to produce tokens without recomputing attention over the entire prompt at each step. section 4.3.1

The KV cache consumes memory, but reduces repeated computation during decoding. Prefill also contributes to end-to-end latency: a practical estimate adds prefill time to the time spent generating tokens. section 4.3.1 section 4.3.3

Figure 4.1 The (Q × KT) × V computation process with caching

The attention-computation diagram illustrates where caching fits into the process. section 4.3.1

Estimating prompt-processing time

For GPT-Neo on a T4 GPU, a 300-token prompt has an estimated prefill time of about 50 ms. Add this to the estimated per-token decoding time to approximate total generation time. section 4.3.3

How Domain-Specific Small Language Models covers it

How deep it goes
Defines parallel prompt processing, explains KV-cache use, and estimates prefill time without modeling additional inference overhead in detail.
Examples
Uses a 300-token GPT-Neo prompt on a T4 GPU to estimate prefill time at about 50 ms.
What you can do after
Evaluate inference latency by adding estimated prefill time to estimated token-generation time.
How it connects
Connects prefill to KV caching, attention, autoregressive decoding, and dynamic batching.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Domain-Specific Small Language Models. The section links point to the parts of the book it draws on.