LLM Inference Explained

LLM Inference Explained

How a model actually generates text, one token at a time.

An interactive guide to how real systems serve language models, from the KV cache to disaggregated serving.

New to transformers? First, how one forward pass works

Animated · driven by the model

The same requests, colocated or split

Llama-3-70B on eight H100s, the first 8 of 200 requests, simulated by Disaggregated_Inference_Sim (commit ac1846a).

Colocated: 2 × (4 H100s), each doing bothreq 1req 2req 3req 4req 5req 6req 7req 8Disaggregated: 4 H100s prefill, 4 decodereq 1req 2req 3req 4req 5req 6req 7req 8t = 0.00 s · hatched red: a decode stall (a gap over 3× the request’s median)

t = 0.00 s. Colocated: 0 of 8 done, 0 decode stalls so far. Disaggregated: 0 of 8 done, 0 stalls.

ITL p99, colocated
252 ms
ITL p99, split
14.5 ms
TTFT p99, colocated
756 ms
TTFT p99, split
1033 ms

When this is on screen, your browser re-runs all 200 requests with the same engine.

Split, the decode GPUs never wait behind a prompt: on these 200 requests the slowest 1% of gaps between tokens (ITL p99) falls from 252 ms to 14.5 ms, while the first token comes later (TTFT p99 0.76 s against 1.03 s). The colocated side here has no chunked prefill, the usual first fix (chapter 4); with every lever open to both, the Trade-offs site finds the split no longer wins on any workload's goodput. Run the simulator yourself

How this is checkedThe serving simulator in chapters 11–14 is Disaggregated_Inference_Sim's own engine, copied byte for byte from a pinned commit, and CI requires every request's timestamps to match its Python original; the tiny model's cached logits are bit-identical to full recomputation. How it is tested →

What you'll learn

A forward pass makes one prediction. Serving a model means running that pass thousands of times a second for many users at once. These chapters cover what real inference systems do about it: the KV cache, the roofline, batching, paged memory, FlashAttention, speculative decoding, quantisation, parallelism, the metrics that judge them, and disaggregated prefill and decode, with a live simulator. Every interactive runs tested code in your browser.

New to the Inference track? Start here: the four sites in reading order, what you need first, and a glossary of the terms they define.

The companion sites: the Transformer Decoder Explainer walks through the forward pass itself, LLM Architectures Explained shows how real models’ designs differ, GPU Kernels Explained shows how a GPU executes the maths, Numerics Explained shows the number formats and quantisation behind it, Systolic Arrays Explained shows the matrix hardware of TPUs, and Inference Trade-offs Explained measures which serving lever helps which metric. The source of this one is on GitHub.