GPU memory math

In one sentence

Weights take parameters × bytes (70B in FP16 ≈ 140 GB), the KV cache gets what's left and that leftover sets concurrency; batch-1 decode speed is capped at memory bandwidth ÷ weight bytes.

Analogy: A moving truck: the furniture (weights) takes fixed space, the boxes (KV cache) fill whatever is left, and how fast you unload depends on the width of the door, not on how strong the movers are.

Weights are a fixed cost; the memory left becomes KV cache and sets concurrency, while bandwidth caps how fast each step runs.

How it works

  • Bytes per parameter set weight size: FP16 = 2, FP8/INT8 = 1, INT4 = 0.5 (plus scales).
  • KV per token = 2 × layers × kv_heads × head_dim × bytes: 320 KiB on Llama-3-70B FP16.
  • Max concurrent sequences ≈ (usable memory − weights) ÷ (KV per token × context).
  • A 7B FP16 model (14 GB) on an A100 (~2 TB/s) caps near ~140 tokens/s; real engines reach less.
  • Batching shares each weight read across sequences, so aggregate throughput grows with concurrency.

Check yourself

Answer to mark it learned; your answers aren't scored.

You must serve Llama-3-70B at 8k context to ~40 concurrent users. INT4 on one H100 fits but holds only ~12 sequences. Assume ~68 GB usable per H100 and ~2.7 GB of FP16 KV per 8k sequence. Which option meets the target with the fewest GPUs?

Go deeper

GPU memory: weights + KV cache Interactive lab
Full explanation

Three numbers decide whether a model fits, how many users it serves at once, and how fast it can talk.

  1. Weights = parameters × bytes per parameter. FP16/BF16 = 2 bytes, FP8/INT8 = 1, INT4 = 0.5. A 70B model is ~140 GB in FP16, ~70 GB in FP8, ~35 GB in INT4 (plus scales).
  2. KV cache per token = 2 × layers × kv_heads × head_dim × bytes. Llama-3-70B in FP16: 2×80×8×128×2 = 320 KiB, so one 8k-token sequence holds ~2.7 GB (KV cache).
  3. Overhead: CUDA context, CUDA graphs and activation buffers, a few GB per GPU. vLLM claims 90% of GPU memory by default (gpu_memory_utilization=0.9), loads the weights, profiles activations and turns the rest into KV blocks.

Then max concurrent sequences ≈ (usable memory − weights) ÷ (KV per token × context). Weights are a fixed cost; the KV pool is what you sell.

Bandwidth sets the speed limit. At batch 1, each decode step reads every weight once, so tokens/s ≤ HBM bandwidth ÷ weight bytes: a 7B FP16 model (14 GB) on an A100 (~2 TB/s) tops out near ~140 tokens/s, and real engines reach only part of that. Batching shares each read across sequences, so aggregate throughput grows with concurrency, which is why the KV pool matters (Prefill vs decode).

Code Size a 70B deployment: fit, concurrency, speed
pythonSize a 70B deployment: fit, concurrency, speed
GB = 1e9

def kv_bytes_per_token(layers, kv_heads, head_dim, kv_bytes=2):
    return 2 * layers * kv_heads * head_dim * kv_bytes  # one K and one V per layer

def plan(n_gpus, params_b, w_bytes, layers, kv_heads, head_dim, ctx, kv_bytes=2,
         gpu_gb=80, util=0.90, overhead_gb=4):  # overhead: assumed, measure yours
    usable = n_gpus * (gpu_gb * util - overhead_gb)  # minus activations, CUDA graphs
    weights = params_b * w_bytes                     # 1B params x 1 byte = 1 GB
    kv_pool = usable - weights
    if kv_pool <= 0:
        return f"{n_gpus} GPU: weights {weights:.0f} GB > usable {usable:.0f} GB"
    per_seq = kv_bytes_per_token(layers, kv_heads, head_dim, kv_bytes) * ctx / GB
    return f"{n_gpus} GPU: KV pool {kv_pool:.0f} GB, ~{kv_pool // per_seq:.0f} seqs"

# Llama-3-70B (config.json: 80 layers, 8 KV heads, head_dim 128), 8k context
L70 = dict(params_b=70, layers=80, kv_heads=8, head_dim=128, ctx=8192)
print(plan(1, w_bytes=2, **L70))              # FP16: 140 GB > usable 68 GB
print(plan(4, w_bytes=2, **L70))              # FP16, 4xH100: KV 132 GB, ~49 seqs
print(plan(2, w_bytes=1, kv_bytes=1, **L70))  # FP8 + FP8 KV, 2xH100: ~49 seqs
print(plan(1, w_bytes=0.5, **L70))            # INT4, 1xH100: KV 33 GB, ~12 seqs

# Batch-1 decode ceiling: each token streams all weights from HBM once
def max_tokens_per_s(weight_gb, bandwidth_tb_s):
    return bandwidth_tb_s * 1000 / weight_gb

print(max_tokens_per_s(14, 2.0))       # 7B FP16 on A100: ~143 tok/s
print(max_tokens_per_s(70, 2 * 3.35))  # 70B FP8 on 2xH100 (TP=2): ~96 tok/s
Real example

A team wants Llama-3-70B for an internal assistant, 8k contexts, ~40 concurrent users, and asks for "one H100". The math: FP16 weights (140 GB) don't fit. INT4 (~35–40 GB) fits but leaves room for only ~10–12 sequences at 8k, and may cost quality. FP16 on 4×H100 holds ~49 sequences; FP8 weights plus FP8 KV on 2×H100 hold the same ~49 on half the GPUs. You propose 2×H100 in FP8 once an eval confirms quality, with a per-user ceiling of ~96 tokens/s (6.7 TB/s ÷ 70 GB), well above reading speed.

Trade-offs +3 · −3

+ You gain

  • Answers "does it fit, how many GPUs, how many users" in minutes, before any benchmark.
  • Exposes the real levers: quantization, GQA models, FP8 KV, context caps and tensor-parallel degree.
  • Gives a hard ceiling to sanity-check vendor claims and your own benchmark results.

− You pay

  • Ignores engine details: fragmentation, CUDA graphs and activation peaks vary, so keep ~10–20% slack (rule of thumb).
  • Gives ceilings, not predictions: real kernels reach only part of peak bandwidth and FLOPs.
  • Average context hides tails: a few max-length sequences can exhaust the KV pool and force preemption.

Use it when

Before every model, GPU or context-length decision: capacity planning, self-host vs API cost, choosing a quantization level, and setting max context per tier.

Avoid it when

It doesn't replace a load test before committing spend. And with a hosted API the provider owns the GPUs: reason in tokens, prices and rate limits instead.

Numbers to know 5
  • Weights: 70B ≈ 140 GB in FP16, ~70 GB in FP8, ~35 GB in INT4 (+ scales).
  • KV per token in FP16: Llama-3-8B 128 KiB, Llama-3-70B 320 KiB.
  • H100 SXM: 80 GB HBM3 at ~3.35 TB/s; H200: 141 GB at ~4.8 TB/s; A100 80 GB: ~2 TB/s.
  • Batch-1 decode ceiling = bandwidth ÷ weight bytes: 7B FP16 on A100 ≈ 140 tokens/s.
  • vLLM default gpu_memory_utilization = 0.9: 90% of each GPU for weights, activations and KV.
Common pitfalls 4
  • Sizing by weights alone: "70B in INT4 fits in 40 GB" leaves room for only a handful of long sequences.
  • Using num_attention_heads instead of num_key_value_heads, overestimating KV 4–8× for GQA models.
  • Expecting INT4 to speed up everything: weight-only quantization helps bandwidth-bound decode, not compute-bound prefill.
  • Splitting a model across GPUs without NVLink: tensor parallelism over PCIe can be slower than fewer, bigger GPUs.
Interview questions 2

Answer out loud first, then reveal.

Can we serve Llama-3-70B on a single H100?Show answer

In FP16, no: 140 GB of weights against 80 GB. In FP8, 70 GB of weights leaves essentially no room for activations and KV cache. INT4 at ~35–40 GB fits with ~30 GB for KV, about 10–12 sequences at 8k context, and I'd need an eval to accept the quality loss. For real traffic I'd rather run FP8 on 2×H100 with tensor parallelism: the same ~49 concurrent 8k sequences as FP16 on four GPUs, at half the hardware.

Why does an H200 serve the same model faster than an H100 with the same compute?Show answer

Because decode is bandwidth-bound, not compute-bound. The H200 has the same Hopper compute but ~4.8 instead of ~3.35 TB/s of HBM bandwidth, so each decode step, which streams all weights and KV, can be up to ~1.4× faster. It also has 141 GB instead of 80, so after the weights there's far more KV cache, which means bigger batches and more throughput per GPU. Prefill is compute-bound and barely changes, so I'd expect the gain in TPOT and concurrency, not TTFT.