Running Models YourselfLesson 13 of 82

Module 2 · The memory arithmetic

Prefill and decode are two different machines

In this lesson

  • 9 min read
  • 7 reading sections
  • Knowledge check
  • Lesson 4 of 9 in this chapter

This chapter’s goalCompute, for any model and any context length, whether it fits on a stated machine and roughly how fast it will run: naming which of weights, KV cache, bandwidth or interconnect is the binding constraint, and choosing the remedy that costs the least quality when it does not fit.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 8Free · no account needed
Lesson steps

One request, two workloads

Every generation is two phases with opposite characteristics, and almost every confusing performance result comes from measuring one and reasoning about the other.

Prefill processes the prompt. All the input tokens go through the model at once, as a matrix multiply against a matrix rather than a vector. There is a great deal of arithmetic per byte of weights read. It is compute-bound.

Decode produces output, one token at a time. Each token reads every weight in the model to produce a single vector. There is very little arithmetic per byte read. It is memory-bandwidth-bound.

These two facts explain most of what follows.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the Open Model Ecosystem exam.

Stuck on something?Ask Tri, your AI tutor

How to cite: Addaly (2026) ‘Prefill and decode are two different machines’, in Running Models Yourself. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/running-models-yourself/prefill-and-decode (Accessed: 29 November 2026).