Why is autoregressive LLM decoding at batch size memory-bandwidth bound? For a -billion-parameter fp16 model () on a GPU with memory bandwidth and of fp16 compute, what is the upper bound on tokens/s at batch size , what is the arithmetic intensity, and near what batch size does decoding reach the compute ridge point?
Sequence models and transformers, Inference
Level L3 Intermediate. Length Medium. Nature Mat Mathematical.
What's being asked
Whether you can quantify the compute-versus-memory bottleneck in autoregressive decoding using roofline analysis (read time, compute time, arithmetic intensity and ridge point), and explain how batching changes it.
Key idea
Generating one token at batch size multiplies a vector by every weight matrix, so the GPU (graphics processing unit) must read all of weights from memory to do only FLOPs (floating-point operations) — an arithmetic intensity of . Because is below the hardware ridge point, the compute cores sit idle waiting on memory bandwidth.
Steps
- Compute the weight-read time at batch size : the model has parameters in fp16 (16-bit floating point, bytes each), so weights total (). Streaming them once from HBM (high-bandwidth memory) at takes
- Compute the arithmetic time at batch size : each weight takes part in one multiply and one add ( FLOPs) per token, giving roughly (billion FLOPs, ignoring smaller attention-dot-product terms at short contexts). At (trillion FLOPs per second), compute takes over faster than reading the weights.
- Find the batch-1 throughput upper bound: limited by weight loading alone (before counting KV, key–value, cache reads), the GPU can produce at most
- Define arithmetic intensity and the ridge point: arithmetic intensity is FLOPs divided by bytes transferred from HBM. Ignoring KV cache reads, batch size has intensity The hardware ridge point (where memory time equals compute time) is
- Show how batching sequences shifts the regime: reading the weights stays per step while weight FLOPs grow -fold to , so arithmetic intensity rises roughly -fold (). Total tokens/s therefore scales almost linearly with until approaches the ridge point (), where decoding turns compute-bound.
- Add the KV cache caveat: at every decoding step, the GPU must also read each sequence's cached keys and values (covered in detail in KV-cache questions). Because KV cache reads grow linearly with and context length, they lower effective arithmetic intensity and cap batch size in VRAM (video memory) before on long contexts.
Common mistakes
- Using instead of FLOPs per token, forgetting that one multiply-accumulate counts as floating-point operations.
- Assuming prefill (processing a long prompt) is also memory-bandwidth bound; prefill processes many prompt tokens in parallel, giving high arithmetic intensity similar to large-batch decoding.
- Ignoring the KV cache at long contexts or large batches, where reading cached keys and values can rival or exceed reading the model weights.
How long your answer should be
3–4 minutes; compare 7 ms vs 0.047 ms, derive ~143 tokens/s, intensity 1 FLOP/B, ridge point 150, and note the KV cache.
Read this
Previous in Sequence models and transformers: How much GPU memory do model states take when fine-tuning a -billion-parameter model with mixed-precision Adam under (a) full fine-tuning, (b) LoRA with million trainable adapter parameters on an fp16 base, and (c) QLoRA with a -bit NormalFloat base? How do NF4, double quantisation and paged optimisers work, and what is the trade-off?
Next in Sequence models and transformers: In speculative decoding, a draft model proposes tokens and each is accepted independently with probability . How do you derive the expected number of tokens produced per target-model forward pass, what is its value for and , and what is the expected speedup if one draft forward pass costs of a target forward pass?