Open Agent School · Public worked example

Prefill & Decode: meaning and example

Welcome! Take one idea with you today.

Prefill processes the supplied context and builds attention state. Decode then advances the output token by token using that state. Queueing happens before service begins and is a separate source of delay. Time to first token (TTFT) measures when the response starts; completion latency measures when it finishes.

Picture it: A synthetic announcement assistant waits two seconds, processes 1,000 input tokens at 1,000 tokens per second, then produces 101 output tokens. In this simplified timing convention, its first token arrives at the end of prefill; the remaining 100 arrive at fifty tokens per second.

What is easy to mix up?

Streaming can reveal output earlier and allow cancellation, but the same number of tokens may take the same total computation. Diagnose queue, prefill, decode and transport separately before choosing a remedy.

Teaching example by Open Agent School. Source: Hugging Face - Streaming and perceived versus completion latency.