What sets the cost of a generated token? For autoregressive language models the answer is usually bytes moved, not arithmetic performed. This lesson builds the roofline model that explains why, works through the numbers for a 70B model, and shows how batching, paged caches, speculative decoding and disaggregation follow from it. It also covers why reasoning models made these questions matter more in 2025–2026.
Two phases with opposite bottlenecks
Serving a request has two phases.
- Prefill processes the whole prompt in one parallel pass and writes its keys and values to the KV cache. Each weight loaded from memory is used against thousands of tokens, so prefill is compute-bound.
- Decode generates one token per step for each sequence. Every step must read every weight (and the sequence's whole KV cache) to do a small amount of arithmetic. Decode is memory-bandwidth-bound.
Shazeer flagged the decode problem in 2019: incremental decoding is slow because of the memory bandwidth spent repeatedly loading keys and values.[1] Pope et al. at Google formalized the trade-offs for serving 500B-parameter models. They showed how latency, batch size and chip partitioning interact, reporting 29 ms per token at small batch and 76% FLOP utilization for large-batch prompt processing on PaLM 540B.[2]
The roofline in one ratio
A chip has peak compute (FLOP/s) and memory bandwidth (bytes/s). A kernel performing FLOPs on bytes has arithmetic intensity . It is memory-bound whenever , the chip's ridge point. An NVIDIA H100 SXM offers about 989 TFLOP/s of dense BF16 compute and 3.35 TB/s of HBM3 bandwidth,[3] so
A decode step at batch size 1 does about 2 FLOPs per weight (see the transformer block) and reads each 2-byte BF16 weight once, so . That is about 300× below the ridge. With a batch of sequences, each weight read serves tokens, so for the weight traffic. Batching is how decode climbs toward the ridge.
The gap is widening. Gholami et al. estimate that peak server FLOP/s grew about 3.0× every two years over the last two decades, against about 1.6× for DRAM bandwidth.[4] NVIDIA's Rubin GPU, announced for 2026, pairs 50 PFLOP/s of NVFP4 inference compute with 22 TB/s of HBM4.[5] That is roughly 2,300 low-precision FLOPs per byte.
Worked example: Llama 3 70B on eight H100s
Take a 70B model in BF16, so 140 GB of weights, sharded across 8 GPUs with an aggregate bandwidth of TB/s. Its KV cache costs about 0.33 MB per token (computed in the attention lesson). Ignoring compute, which stays far below the ridge throughout, the time for one decode step is roughly
where is weight bytes, batch size, context length and KV bytes per token.
Batch 1. ms, so at most about 190 tokens/s. The GPUs are using about TFLOP/s of their roughly 7,900 TFLOP/s, about 0.3%.
Batch 64, 8k context each. Each sequence's cache is GB, so KV reads add GB per step. Then ms, and throughput is tokens/s, about 29× the batch-1 figure on the same hardware.
Two lessons follow. First, batching amortizes the weights but not the KV cache: each sequence reads its own. At long contexts, KV traffic overtakes weight traffic (172 GB against 140 GB here) and the benefit of batching flattens. Second, HBM capacity caps the batch. The cache must fit next to the weights.
Same setup, but every sequence has 32k tokens of context. With 640 GB of total HBM and 140 GB of weights, what is the largest batch whose KV cache fits (ignore activations and fragmentation)?
Show answer +Hide answer −
Each sequence needs GB. The free memory is GB, so sequences. Quadrupling context cut the feasible batch by more than 4× relative to what the weights alone would allow, which is why KV-cache size directly sets serving cost.
Serving systems built on this arithmetic
Continuous batching. Requests finish at different times. The Orca system schedules at the granularity of a single model iteration, so new requests join the running batch as soon as any slot frees up. It reported up to 36.9× higher throughput than FasterTransformer on GPT-3 175B at equal latency.[6]
Paged KV caches. Reserving a contiguous cache for each request's maximum length wastes memory and therefore batch size. vLLM's PagedAttention stores the cache in fixed-size blocks, like operating-system virtual memory, and reported 2–4× throughput gains over prior systems.[7]
Prefill/decode disaggregation. Because the two phases bottleneck on different resources, DistServe runs them on separate GPUs and ships the KV cache between them. It reported up to 7.4× more requests served within latency targets.[8] NVIDIA's Dynamo framework, released in 2025, implements the pattern. Its documentation notes that an aggregated deployment can still win at low concurrency, where the transfer overhead is not repaid.[9] NeuroGenesys's review of interconnect measurements found that communication is a modest share of prefill time (measured at 9–23%) but becomes the binding constraint in multi-node decode. That is where faster interconnect, optical or otherwise, has its strongest case.[10]
Speculative decoding: trading idle FLOPs for bytes
At batch 1 the GPU is about 99% idle on arithmetic, so extra computation is nearly free if it does not add memory traffic. Speculative decoding exploits this. A small draft model proposes tokens, and the large model scores all of them in one forward pass, which reads the weights once. A modified rejection-sampling rule accepts a prefix of the draft so that the output distribution is exactly the large model's.[11][12] If each draft token is accepted with probability , the expected number of tokens per large-model pass is
which for , is about 3.4. Leviathan et al. reported 2–3× speedups on T5-XXL with identical outputs.[11] EAGLE-3, which drafts from the target model's own hidden features, reported speedups of up to 6.5×.[13] Multi-token prediction heads trained with the model (see next-token prediction) can serve as built-in drafters. The gain shrinks at large batch, where the FLOPs are no longer idle.
Why inference-time scaling raised the stakes
Reasoning models spend compute by generating long chains of tokens, and those are decode tokens: the expensive, bandwidth-bound kind. Usage data show the shift. In OpenRouter's study of more than 100 trillion tokens, models optimized for reasoning went from a negligible share of traffic in early 2025 to more than half of all tokens by late 2025. Average prompts grew about fourfold, to over 6,000 tokens, and completions nearly tripled.[14] Prices at fixed capability have fallen fast. Epoch AI measured declines of 9× to 900× per year depending on the benchmark and threshold.[15] But tokens consumed per task rose at the same time, so total serving demand still grew.
Model designers responded by attacking the KV cache and the attention FLOPs directly. DeepSeek-V4-Pro's model card reports that at a one-million-token context it needs 27% of the per-token FLOPs and 10% of the KV cache of its predecessor. It stores its expert weights in FP4.[16] Sparsity and compression covers the weight side of the same bill.
Why does speculative decoding help much more at batch size 1 than at batch size 256?
Show answer +Hide answer −
At batch 1, decode is deeply memory-bound and most compute is idle, so scoring draft tokens in one pass costs almost no extra time: the weights are read once either way. At batch 256 the step is already near the ridge point. Verifying extra draft tokens then adds real compute, and the latency gain shrinks or disappears.
Key takeaways
- Prefill is compute-bound. Decode is memory-bandwidth-bound, with arithmetic intensity of about 1 FLOP/byte at batch 1 against a ridge of about 300 on an H100.
- Batching amortizes weight reads, but each sequence's KV cache is read separately, so long contexts erode the benefit and HBM capacity caps the batch.
- Continuous batching, paged KV caches and disaggregation are systems responses to this arithmetic. Speculative decoding turns idle FLOPs into fewer weight reads.
- Reasoning models shifted traffic toward long, decode-heavy generations. As of November 2026, KV-cache and attention-FLOP reduction are first-class architectural goals.
Sources
-
N. Shazeer (2019). "Fast Transformer Decoding: One Write-Head is All You Need." arXiv:1911.02150. https://arxiv.org/abs/1911.02150 ↩
-
R. Pope, S. Douglas, A. Chowdhery et al. (2022). "Efficiently Scaling Transformer Inference." arXiv:2211.05102. https://arxiv.org/abs/2211.05102 ↩
-
NVIDIA. "NVIDIA H100 Tensor Core GPU" (product page and datasheet; SXM: 80 GB HBM3, 3.35 TB/s; BF16 dense ≈ 989 TFLOP/s, half the listed sparse figure). https://www.nvidia.com/en-us/data-center/h100/ ↩
-
A. Gholami, Z. Yao, S. Kim, C. Hooper, M. W. Mahoney and K. Keutzer (2024). "AI and Memory Wall." arXiv:2403.14123. https://arxiv.org/abs/2403.14123 ↩
-
The Register (5 January 2026). "Every conference is an AI conference as Nvidia unpacks its Vera Rubin CPUs and GPUs at CES." https://www.theregister.com/2026/01/05/ces_rubin_nvidia/ ↩
-
G.-I. Yu et al. (2022). "Orca: A Distributed Serving System for Transformer-Based Generative Models." OSDI 2022. https://www.usenix.org/conference/osdi22/presentation/yu ↩
-
W. Kwon et al. (2023). "Efficient Memory Management for Large Language Model Serving with PagedAttention." arXiv:2309.06180. https://arxiv.org/abs/2309.06180 ↩
-
Y. Zhong, S. Liu, J. Chen et al. (2024). "DistServe: Disaggregating Prefill and Decoding for Goodput-optimized Large Language Model Serving." OSDI 2024. arXiv:2401.09670. https://arxiv.org/abs/2401.09670 ↩
-
NVIDIA. "Disaggregated Serving." NVIDIA Dynamo documentation. https://docs.nvidia.com/dynamo/dev/knowledge-base/concepts/system-architecture/disaggregated-serving ↩
-
NeuroGenesys (2026). "The wrong phase: optical interconnect's case is in decode, not prefill." /research/optical-interconnect-decode ↩
-
Y. Leviathan, M. Kalman and Y. Matias (2023). "Fast Inference from Transformers via Speculative Decoding." ICML 2023. arXiv:2211.17192. https://arxiv.org/abs/2211.17192 ↩ ↩2
-
C. Chen, S. Borgeaud, G. Irving, J.-B. Lespiau, L. Sifre and J. Jumper (2023). "Accelerating Large Language Model Decoding with Speculative Sampling." arXiv:2302.01318. https://arxiv.org/abs/2302.01318 ↩
-
Y. Li, F. Wei, C. Zhang and H. Zhang (2025). "EAGLE-3: Scaling up Inference Acceleration of Large Language Models via Training-Time Test." arXiv:2503.01840. https://arxiv.org/abs/2503.01840 ↩
-
M. Aubakirova, A. Atallah, C. Clark, J. Summerville and A. Midha (2026). "State of AI: An Empirical 100 Trillion Token Study with OpenRouter." arXiv:2601.10088. https://arxiv.org/abs/2601.10088 ↩
-
Epoch AI (2025). "LLM inference prices have fallen rapidly but unequally across tasks." https://epoch.ai/data-insights/llm-inference-price-trends ↩
-
DeepSeek-AI (2026). "DeepSeek-V4-Pro" model card. Hugging Face. https://huggingface.co/deepseek-ai/DeepSeek-V4-Pro ↩
