AI engineering glossary · Transformers LLM architecture

What is prefill and decode?

Prefill and decode (also called Prompt processing): The two phases of LLM inference. In prefill, the model processes the entire prompt in parallel and fills the KV cache; in decode, it generates output tokens one at a time. Prefill is compute-heavy, while decode is limited mostly by memory bandwidth.

Level: intermediateTopic: Transformers LLM architecture

Prefill and decode: an example

A 2,000-token prompt is handled in one prefill pass, followed by 300 decode steps to write a 300-token answer.

Related terms

More Transformers LLM architecture terms

Where you learn it

Prefill and decode is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.