The idea to keep with you
When H100s OOM at batch=20, enable per-group INT4 KV quantization and fused SRAM dequantization.
TL;DR30-second simplified summary▾
Raises max batch from 20 to 80+ and boosts decode throughput 3.2x.
Before you begin · Building blocksAlready know these? Jump to Stage 01 ↓
KV Cache Byte Sizing
2 * layers * kv_heads * head_dim * bytes_per_elem.
PagedAttention
Manages KV cache in fixed-size virtual blocks.
Full walkthrough · 2 stages
01
STAGE 01intermediate
Diagnosing the 2.56 GB/Request HBM Bottleneck.
Why this matters: Calculate exact KV footprint and identify HBM bandwidth saturation.
20 concurrent 8k requests * 2.56 GB = 51.2 GB KV + 35 GB TP-sharded weights > 80 GB H100 capacity.
Before · FP16 Batch=20 OOM
After · INT4 Batch=80+ Healthy
| Choice | What it buys | What it costs |
|---|---|---|
| FP16 (16-bit) | Native precision | 2.56 GB / 8k req; OOM at batch=20 |
| Per-Group INT4 (4-bit) | 0.64 GB / 8k req; batch=80+ | Requires fused SRAM dequant kernel |
def kv_bytes_per_token(layers: int, kv_heads: int, head_dim: int, bits: int) -> int:
return (2 * layers * kv_heads * head_dim * bits) // 8
02
STAGE 02advanced
Group-Wise Quantization & Fused Attention.
Why this matters: Implement outlier-safe group quantization and verify perplexity bounds.
Quantize 64-element groups with asymmetric min/max scale and zero-point; dequantize on-the-fly in SRAM.
Engineering Decision Framework
- Problem
- Resolve 80 GB H100 OOMs at batch=20 on 70B 8k-context serving without buying 4x more GPUs.
- Naive Solution
- Evict/recompute KV caches on preemption or use global per-tensor INT4 quantization.
- Why It Fails
- Recomputation kills TTFT and wastes FLOPs; global per-tensor INT4 destroys accuracy on Key outlier channels.
- Alternatives
- 4x GPU horizontal scaling, KV preemption/recompute, or per-group (64) asymmetric INT4/FP8 KV quantization.
- Engineering Decision
- Enable per-group asymmetric INT4 KV quantization in PagedAttention blocks with fused SRAM dequantization.
- Trade-Offs
- Adds minor SRAM dequant ALU instructions, but cuts HBM footprint 4x and boosts decode throughput 3.2x.
Decision Exercise · Make the Call
Your 70B serving cluster is HBM-bound at batch=20. Which change 4x's batch concurrency without hurting TTFT or perplexity?
public static int kvBytesPerToken(int layers, int kvHeads, int headDim, int bits) {
return (2 * layers * kvHeads * headDim * bits) / 8;
}
Practice · Explain the consequences
Practice: Make the trade-off yourself.
Question 1 of 3
Score: 0/3At 80 KB/token, how much KV memory does an 8k-token request consume?
Recommended Learning Flow