You ship a coding agent on four H100 GPUs. Ten turns later, your bill is 3× higher than expected, live chat freezes for half a second whenever someone uploads a big file, and your GPUs sit 99.7% idle while streaming words.
Nothing is wrong with your model. You just hit the physics of LLM serving. Every [R] figure below was re-derived in code ([V] vendor-reported, [S] secondary, [I] illustrative late-2026 model). For failure-guard tables and the full glossary, see our LLM inference infrastructure guide.
Why one word is so weird to generate
Think of writing a word like carrying a 140 GB book off the shelf just to type one word. Every decode step moves all 140 GB of a 70B model's weights from GPU memory (HBM) into the math cores—whether it writes one word for one user or one word each for five hundred users.
Hardware has two speed limits: peak math speed (compute) and memory speed (bandwidth). Their ratio is the ridge point:
Think of the GPU as a super-fast calculator that has to haul the 140 GB model off the memory shelf first. Serving 1 user does almost no math per byte moved (AI = 1); serving 256 users at once shares that exact same haul 256 ways.
Figure 1. H100 BF16 roofline: one user decoding uses 0.3% of the math roof, while a 2,048-token prompt runs 7× past the ridge.
- Prefill (reading the prompt): Reads all tokens in one sweep ()—pure compute-bound work.
- Decode (writing one word at a time): One user () hits a 41.8 ms/word floor (~24 tok/s) with 99.7% of the math cores idle
[R]. Sharing that 140 GB read across users scales utilization linearly until ~295 concurrent tokens cross the ridge, which is why providers pack chats into big batches and why streaming slows at peak hours.
1. Shrink the sticky notes (KV cache)
To write word 10,001 without re-reading the entire chat from page 1, the GPU saves sticky notes (keys and values, the KV cache) for every token:
On a classic 64-head 70B model, those sticky notes weigh 2.62 TB at 1M tokens—19× heavier than the model itself [R]. On a 4×H100 node (180 GB spare memory), full attention fits zero 128K-token chats, grouped heads (GQA) fit 4, and compressed latent notes (MLA) fit 20 [R].
Figure 2. KV cache per token across attention designs and total memory at 1M context.
Four model designs shrink those notes, while FP8 quantization (2× smaller), PagedAttention (2–4× throughput [V]), and CPU/NVMe offload stack on top:
- Share note pads (
GQA): 8 shared K/V groups (Llama 3, Mistral, Qwen) cut memory 8× with virtually no quality drop. - Compress each note (
MLA): DeepSeek-V2/V3 packs keys and values into a 512+64 latent vector, cutting KV 93.3% vs. its dense 67B baseline and lifting throughput 5.76×[V]. - Read only top matches (
DSA/CSA+HCA): DeepSeek V4 interleaves stride-4 and stride-128 compressed tiers with an FP4 indexer—reporting 27% of V3.2 FLOPs and 10% of its cache (~7 GB) at 1M tokens[V]. - Stop growing notes in most layers (Hybrids): Qwen3-Next, Kimi Linear, and Falcon-H1 replace ~3 of 4 attention layers with fixed-size state-space layers.
Test long-context retrieval on your own docs before adopting aggressive compression—third-party reviews of V4 flagged needle-in-a-haystack recall risk [S].
2. Separate the reading desk from the writing desk
Reading a 30,000-word PDF (prefill, setting TTFT—wait before the first word) and typing one word at a time (decode, setting ITL—pause between words) collide in a shared queue, freezing live chats whenever a huge document arrives.
Disaggregation (NVIDIA Dynamo, vLLM Production Stack, llm-d, Mooncake, SGLang) gives each phase its own GPU pool. The trade-off is shipping KV notes between pools over ~50 GB/s RDMA [R]:
| Prompt length | MHA (2.6 MB/tok) | GQA (0.33 MB/tok) | MLA (0.07 MB/tok) |
|---|---|---|---|
| 1K tokens | 52 ms | 7 ms | 1.4 ms |
| 10K tokens | 524 ms | 66 ms | 14 ms |
| 100K tokens | 5.2 s | 656 ms | 141 ms |
Split when prompts exceed ~10K tokens, agents re-prefill heavy history, or tail freezes hurt users. Stay monolithic for short (<=2K) well-batched chat.
3. Let a junior assistant draft ahead (speculative decoding)
While low-batch decode leaves 99.7% of math cores idle, a fast junior drafter guesses words in a row and the big model grades all positions in one 140 GB trip—losslessly keeping the matching prefix plus a bonus word:
Even if the assistant guesses badly, the big model still gives you 1 word for free. When the assistant matches 70% of the time across 4 guesses, those lucky streaks add up to 2.77 words per trip instead of 1.
At acceptance and , one trip emits words [R]. Speedup depends on draft cost ratio : at , at , break-even at , and (slower) at . Feature-level drafters (EAGLE-3, 3.0–6.5× [V]), model-native heads (DeepSeek-V3 MTP, 1.8× [V]), and free n-gram lookup beat standalone small models. Gate speculation off above ~256 concurrent users (where idle math disappears) and watch JSON schemas (SGLang #9187 can stall slower than baseline).
4. Pay for scratch paper only when you can grade it
Test-time compute (TTC) trades output tokens for accuracy via voting, critique loops, tree search, or reasoning_effort. It pays where a cheap verifier exists (math, unit tests): Snell et al. beat a ~14× larger model on easy prompts with smart allocation, s1 pushed Qwen2.5-32B from 50% to 57% on AIME24, and o3 scored 87.5% on ARC-AGI using ~57M tokens/question [S]. Yet GSM8K and MATH-500 reach 95% of peak accuracy at just 256 thinking tokens, and overlong chains can hurt accuracy [S].
At $60/M output, 256 tokens cost $0.015 while 57M cost $3,420 [R]. Because Epoch AI tracks cost-per-fixed-score falling ~47% per quarter (~13×/year) [S], route effort by difficulty, cap thinking budgets in code, and re-price quarterly.
5. Bill the whole email thread, not one email
Model APIs are stateless, so every tool call re-mails the entire conversation thread. Over turns with base prompt and new tokens/turn, input volume grows quadratically:
For , , and , input hits tokens [R] (real coding agents reach up to 1,000× single-query volume plus a 1.7–2.0× retry multiplier [S]).
Figure 3. 10-turn session cost: uncached quadratic growth vs. prefix caching.
Prefix caching lets providers keep old KV notes resident at 5–10% of input price, cutting our 10-turn bill from $0.285 to $0.098 warm-prefix ($0.106 cold-start on Turn 1) [R]. Put static instructions and tools first, append dynamic tool outputs last, and cap loop depth in code.
6. Don't buy a car from a brochure without gas mileage
Providers publish context limits and $/Mtok while hiding batch policies, served quantization, cache eviction, and speculation gating—creating 2–10× latency and throughput spreads on identical open weights [S]. At identical $2/M in and $10/M out, a provider with 12-hour automatic caching and KV-aware routing finishes our 10-turn session for $0.098–$0.106, while one with 5-minute opt-in caching and round-robin routing bills ~$0.21 with 3× tail latency spikes [I].
Six rules to take back to your stack
- Size the cache before running evals: compute
KV bytes/tokenat your real context lengths and turn onPagedAttention+FP8KV. - Split prefill and decode only when tail latency hurts: alert if KV transfer exceeds 10% of
TTFTand matchTPlayouts per pool. - Gate speculation by route and load: log weekly and turn it off above ~256 concurrent tokens.
- Cap scratch paper by difficulty: default easy traffic near ~256 thinking tokens; only escalate with a verifier.
- Keep prefixes static-first: alert below 80% cache-hit rate on agent routes and enforce hard loop-depth caps.
- Procure on cost per successful task: replay your own traffic quarterly to measure latency-vs-concurrency and real cache TTLs.
