Module 7 · Lesson 2 of 4

Two stages: prefill and decode

How long is the prompt?

18 prompt tokens: prefill takes 72 units. The first token arrives after 97 units, and each later token after 25 more.

Application, sends the prompt, NOWApplicationsends the promptprompt: 18 tokensNOWLanguage model, on a GPULanguage modelon a GPU
  • Application — sends the prompt — healthy — NOW — prompt: 18 tokens
  • Language model — on a GPU — healthy
  • The prompt
  • One answer token
Step 1 of 9

Step 1 of 9 · Application

Done: The application has the prompt ready

What happens
The prompt is 18 tokens long. A token is a word or a piece of a word.
Why
The model has not seen the prompt yet, so it has written nothing.
What changes
Nothing is saved, and no time has been used.
Next
Prefill: the model reads the whole prompt

Event log

8 more to go. Press a line to go back to that step.

Prompt tokens read
0
of 18
Answer tokens written
0
of 7
KV cache rows
0
one for each token so far
Time used
0units
made-up units, not milliseconds

Prompt:

Answer so far:

Time so far, in illustrative time units (not real milliseconds):

Time so far: prefill 4 units for each of 18 prompt tokens, then 25 units per answer token. 0 of 247 units used so far.

KV cache rows: 0

Step 1 of 9: Application. The application has the prompt ready. The prompt is 18 tokens long. A token is a word or a piece of a word.

What this simplifies. Real models do this for thousands of tokens, with huge sums run on a GPU. The rows here stand for much larger blocks of numbers, and the time units are made up. Here every decode step takes the same time; in a real model it grows a little as the KV cache grows.

The full prompt for this example: You are a support agent. Answer from the policy. Where is my parcel?

Writing an answer has two stages. The first is : the model reads the whole , all its side by side, and saves its work for the next steps.

The second stage is : the model writes one new token per step, using the work it saved. Prefill handles many tokens together; decode handles one token per request, per step.

This split matters for speed. A longer prompt still makes prefill take longer, since there is more to read, but it does not add one step per prompt token. Decode adds one step per answer token, run one after another.

Example. A 1,000-token prompt is read in one prefill stage, its tokens handled side by side. Writing a 100-token answer still takes 100 separate decode steps, one new token at a time.

In system design: Long prompts slow prefill; long answers add decode steps. A design that only shortens prompts misses half the cost, since decode time grows with answer length too.

Check yourself

A prompt doubles in length, and the answer stays at 100 tokens. What grows?