The Inference Cost Rosetta Stone: Why Your GPU Runs at 1% and What to Do About It
The Physics You Can't Optimize Away
A first-principles breakdown of transformer inference economics reveals the complete FLOP cost formula: 24nd² + 4n²d per layer. The quadratic attention term (4n²d) crosses the linear projection term at n=2d — for d=2048, that's exactly 4,096 tokens, explaining why 4K was the standard context length for years. Beyond this crossover, costs explode: at 32K context, the quadratic term accounts for 73% of total compute. At 128K, it's 92%.
But the deeper problem is the prefill/decode regime split. Prefill (processing your prompt) runs compute-bound at ~4,096 FLOPs/byte. Decode (generating each token) runs at just 1 FLOP/byte at FP16 — catastrophically memory-bound. The H100's compute-to-bandwidth threshold is 295 FLOPs/byte, meaning your GPU sits at ~0.34% utilization during token generation. You're paying for 989 TFLOPS and using 3.4.
Compute power compounds at 3x every two years while memory bandwidth grows at roughly half that rate. The decode bottleneck gets structurally worse with each hardware generation.
KV Cache: The Concurrency Killer
KV cache is the binding constraint on GPU concurrency, and the numbers are stark. A 7B INT4 model on an H100 (80GB HBM) serves 278 concurrent users at 4K context but only 8 at 128K — a 35x cost increase per user from $0.009/hr to $0.31/hr. Double the context, halve the concurrent users — it's a direct linear relationship.
| Context Length | KV Cache/Session | Concurrent Users/GPU | Per-User Cost/hr |
|---|---|---|---|
| 4K | 268 MB | 278 | $0.009 |
| 32K | 2.1 GB | 34 | $0.074 |
| 128K | ~9.3 GB | ~8 | $0.31 |
This table should be on every ML team's wall. Your 128K context feature isn't just expensive in FLOPs — each long-context session evicts other users from the GPU.
The Architecture Evaluation Litmus Test
Every serious architectural innovation of the last two years attacks exactly two numbers: bytes of KV cache per token, and bytes of weights loaded per decode step. Apply this filter ruthlessly:
- GQA (Llama 3.2): 4x KV cache reduction. ✅ Moves number 1.
- MoE (Mixtral 8x7B): 47B total params but ~13B active. ✅ Moves number 2.
- Hybrid attention/SSM: 6 attention layers instead of 16 = 192 MB vs 512 MB at 32K. ✅ Moves number 1.
- FlashAttention: Optimizes memory access, does NOT reduce FLOPs. ❌ Moves neither number.
- INT4 quantization: Quadruples arithmetic intensity from 1 to 4 FLOPs/byte — the single largest software-side decode improvement.
If a new architecture paper doesn't clearly move one of these two numbers, it doesn't change your inference economics regardless of benchmark scores.
Cross-Source Tension: Long Context vs. RAG
Here's where today's intelligence gets interesting. Claude Sonnet 4.6 ships with a 1M-token context window (beta), which theoretically lets you skip RAG entirely for documents under ~750K tokens. But the inference economics above show why this is expensive: at 128K context you're already at 92% quadratic compute share and 8 concurrent users per GPU. Scaling to 1M context would be economically devastating at self-hosted scale. The implication: long-context models make sense through API providers who absorb the utilization problem, while self-hosted deployments should invest in RAG with simple chunking (see next deep dive) and aggressive context management.
The raw compute floor for a well-optimized 14B deployment is ~$0.004/M tokens at full utilization. API pricing runs $0.10-$1.25/M tokens — an 8-40x markup that covers redundancy, SLAs, and the engineering team you don't hire. But hidden self-hosting costs range from $125K-$190K/year (minimal) to $6M-$12M+ (enterprise-scale).
What to do
Profile your production context length distribution and compute the quadratic cost share this week — if median context exceeds 4K-8K, prioritize GQA or hybrid attention/SSM architectures for your next model selection
Benchmark actual GPU utilization during decode and compute utilization-adjusted cost per million tokens — compare against API pricing to validate your self-hosting decision by end of sprint
Implement KV cache budgeting as a first-class resource in your serving infrastructure, with per-request context limits based on GPU memory headroom and target concurrency
Evaluate INT4 quantization for decode-heavy workloads this quarter — it quadruples arithmetic intensity from 1 to 4 FLOPs/byte