Mental model
LLM capacity planning cannot rely on classic stateless web RPS math because generative inference latency and memory cost depend violently on token-length distributions, not flat request counts. Because every concurrent request locks multi-megabyte KV-cache HBM blocks linearly across its full input + output token sequence while compute latency splits between heavy parallel prefill (TTFT) and memory-bandwidth-bound sequential decode (TPOT), reliable sizing starts from P50/P95/P99 prompt & generation token distributions, prefix-cache reuse ratios, quantization precisions, cold-start model weight loading lag, and strict VRAM headroom (25%–30%) + N + 1 failover redundancy—verified empirically cleanly via production trace replay rather than synthetic uniform prompts!
Learning outcomes
- Compute explicit HBM VRAM budgets partitioning static model weights (
FP16/FP8/AWQ), CUDA activation workspaces, and dynamic PagedAttention KV-cache capacity (free KV blocks). - Explain why token-length tails (
P95long-context documents) and output-to-input ratios distort naïve requests-per-second averages dramatically. - Factor container image pulls and multi-gigabyte weight deserialization cold-starts (
30–240 s) cleanly into warm baseline replica floors and HPA buffers. - Size
N + 1redundancy and isolated prefill/decode pools so node preemption or AZ failure never triggers cluster-wide queue collapse.
Theory
Suppose a 70B dense parameter model (GQA 8 KV heads, FP8 weights ~70 GB) deploys across 2x H100 80 GB (160 GB total HBM): after ~140 GB is occupied immediately by model weights (70 GB/GPU? Wait: 70 GB total split across 2 GPUs = 35 GB/GPU -> leaving 45 GB/GPU / 90 GB aggregate for activations, CUDA graphs, and KV blocks! Checking exact arithmetic keeps numbers cleanly grounded!). Using KV bytes/token = 2 * layers * kv_heads * head_dim * bytes_per_val: at 80 layers, 8 KV heads, 128 head_dim, FP8 (1 byte) or BF16 (2 bytes), one 32K-token context locks 2 * 80 * 8 * 128 * 2 = 327,680 bytes/token * 32,768 = ~10.7 GB of HBM strictly for ONE user's KV cache! A handful of unexpected 64K inputs therefore exhausts KV pools abruptly if provisioned only around "mean 1,200-token" averages!
| Capacity Input Variable | Physical GPU Bottleneck Driven | Production Sizing & Safety Rule |
|---|---|---|
Static Weights + CUDA Graphs (W) | Baseline HBM committed before request 1 | Always measure real vLLM engine startup memory (gpu_memory_utilization=0.90), leaving OS/NCCL room |
| P95 Sequence Length Peak Active Concurrency | Dynamic KV-Cache block pool exhaustion (num_preemptions) | Keep 25%–30% free KV-block margin at predicted daytime peak so long answers never evict live neighbors! |
| Input Prefill vs. Output Decode Ratio | Prefill saturates Tensor Cores (TTFT); Decode saturates HBM bandwidth (TPOT) | Large RAG (8K in / 150 out) behaves compute-bound, requiring prefill-decode disaggregation or chunked prefill cleanly earlier than chat (300 in / 800 out)! |
Weight Load & Pod Warmup Time (T_boot) | Horizontal autoscaler reaction lag (45–180 s) | Hold warm baseline replicas sized to absorb T_boot burst derivative cleanly without waiting for cold nodes |
Trace Replay Under N + 1 Failure and Queue-Collapse Cliffs
Always validate candidate fleet sizes on trace replay (real production timestamped prompt/output histograms) under missing-node failure (N healthy replicas -> simulate losing 1 replica cleanly during peak burst!). At 95% utilization, losing 1 of 10 pods spikes the remaining 9 past 105% demand—turning graceful 20 ms queues immediately into catastrophic 30-second timeout cascades where waiting queues pile up and every retried client compounds load 3x (Metastable Queue Collapse)! Keeping steady-state utilization cleanly under 65%–70% alongside upstream admission shedding (HTTP 429/503) guarantees remaining healthy GPUs drain cleanly through failovers.
pythonfrom dataclasses import dataclass@dataclass(frozen=True)class FleetSizingInput:peak_tokens_per_sec_decode: floatsingle_replica_goodput_tps: floatsingle_replica_kv_gb: floatkv_gb_per_p95_req: floatp95_concurrent_reqs: inttarget_utilization: float = 0.70def compute_n_plus_1_replicas(cfg: FleetSizingInput) -> dict[str, int]:"""Size GPU replica fleet covering compute goodput, KV block capacity, and 1 failed worker."""compute_replicas = max(1, int(-(-(cfg.peak_tokens_per_sec_decode / (cfg.single_replica_goodput_tps * cfg.target_utilization)) // 1)))total_kv_needed_gb = cfg.p95_concurrent_reqs * cfg.kv_gb_per_p95_requsable_kv_per_replica = cfg.single_replica_kv_gb * 0.75 # Preserve 25% KV headroom against preemptionskv_replicas = max(1, int(-(-(total_kv_needed_gb / usable_kv_per_replica) // 1)))active_floor = max(compute_replicas, kv_replicas)return {"active_replicas": active_floor,"recommended_with_n_plus_1": active_floor + 1,}
Alternatives and trade-offs
- Warm-Baseline + Trace-Verified
N + 1Dedicated GPU Fleet + Spillover Burst API: Guarantees deterministicTTFT/TPOTSLAs, protects private KV caches cleanly, and prevents cold-boot drops during sudden traffic ramps via instant overflow onto serverless pay-per-token APIs during extreme3xlaunches—balancing fixed reserved GPU costs cleanly against un-provisioned launch surges! - Pure Aggressive Scale-to-Zero GPU Autoscaling: Minimizes overnight idle cloud spend on low-volume internal batch jobs, while imposing severe
1–4 minutecold-start SLA breaks whenever daytime interactive users hit zero warm pods. - Disaggregated Prefill / Decode Fleets: Splits heavy long-context prefill workers cleanly onto high-FLOP compute pods while keeping decode replicas focused on smooth
TPOTstreams—unmatched at massive cluster scale, yet premature overhead below tens of GPUs.
Failure modes and misconceptions
- Sizing Capacity From Mean RPS Ignoring Token-Length Tails: Provisioning for
50 req/saveraging500tokens crashes instantaneously the afternoon enterprise RAG users paste24,000-token PDFs cleanly driving30xKV consumption and15xprefill FLOPs per request! - Ignoring Container Weight Download & Engine Warmup Lag (
30–240 s): Configuring tight Kubernetes HPA scale-ups at85%load guarantees4-minute outage waves while giant70 GBSafetensors checkpoints stream down over container registries and compile CUDA graphs! Keep cached NVMe weights (hostPath/DaemonSetpre-warmed images) and conservative scale-up triggers (55%–65%). - Provisioning
100%VRAM Without KV Eviction Headroom (gpu_memory_utilization): Packing active queues right to99%of KV blocks sets off constant recomputation/swap preemption storms under minor output-length variance. - Zero
N + 1Redundancy Margin During Peak (Metastable Collapse): Running3replicas at92%capacity triggers total SLA collapse the instant 1 spot node or GPU driver resets (Xidfault), pushing load to138%across survivors cleanly.
Decision scenario
Your SaaS copilot handles steady daytime enterprise coding and RAG summarization (P50 = 1,500 input / 300 output tokens, P95 = 18,000 input / 1,100 output tokens) alongside sharp Monday morning launch spikes, running on multi-GPU Kubernetes nodes taking 90 s to warm new serving pods. Measure real trace replay goodput under exact FP8 weights + GQA KV footprints, allocate 30% free KV margin, maintain warm baseline capacity holding <= 65% target daytime utilization plus N + 1 failover redundancy cleanly verified against simulated replica kills, pre-cache weights locally on node NVMe volumes to trim autoscaling lag, and wire upstream admission queues to shed overload or route brief extreme spikes cleanly to an overflow endpoint.
Trade-offs
Token-distribution-driven N + 1 capacity planning prevents catastrophic preemption thrashing, cold-start blackouts, and metastable failover collapses across production GPU inference fleets, while requiring intentional investment in warm baseline reserve nodes rather than squeezing 95%+ naive hardware utilization.