Inference, Serving & Production·Question 16 of 76Intermediate

Explain arithmetic intensity and the roofline model as applied to LLM inference. Why does batching improve decode throughput so dramatically?

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

Arithmetic intensity = FLOPs performed per byte moved from memory. The roofline model says achievable performance = min(peak_FLOPs, intensity × memory_bandwidth): below a ridge point you're memory-bound (perf grows linearly with intensity), above it compute-bound. The ridge for an H100 at BF16 is roughly ~989 TFLOPs ÷ ~3.35 TB/s ≈ ~300 FLOPs/byte; for an A100 it's ~150.

Full worked answer with diagram

Arithmetic intensity = FLOPs performed per byte moved from memory. The roofline model says achievable performance = min(peak_FLOPs, intensity × memory_bandwidth): below a ridge point you're memory-bound (perf grows linearly with intensity), above it compute-bound. The ridge for an H100 at BF16 is roughly ~989 TFLOPs ÷ ~3.35 TB/s ≈ ~300 FLOPs/byte; for an A100 it's ~150.

Now place the two inference phases on that roofline. Batch-1 decode: for each weight element (2 bytes in FP16) you do one multiply-add (2 FLOPs) - intensity ≈ 1 FLOP/byte. That's two orders of magnitude below the ridge: the GPU streams 140 GB of weights to emit one token while its tensor cores sit ~99% idle. Prefill: a 4K-token prompt reuses each loaded weight 4096 times - intensity in the thousands, firmly compute-bound.

Batching decode raises intensity almost for free: with batch size B, each weight byte loaded performs B multiply-adds - intensity ≈ B FLOPs/byte. Throughput therefore scales ~linearly with B until B approaches the ridge (~a few hundred sequences), where decode finally becomes compute-bound. Since the weight-read cost was being paid anyway, tokens 2..B are nearly free - this is the economic fact of LLM serving, and why every scheduler fights to keep batches full.

Limits on B: KV-cache memory (each sequence's cache must be resident - usually the real cap), per-token latency growth as compute share rises, and the KV-read component of attention, which unlike weights is per-sequence and doesn't amortise - at long contexts, KV reads, not weight reads, dominate the bandwidth bill.

This lens also explains quantization's asymmetry (weight-only quant lifts the memory-bound regime; W8A8/FP8 lifts the compute-bound one) and why speculative decoding works (trades idle compute for fewer sequential memory sweeps).

Worth sketching. Placing the three regimes against the ridge point is what turns "batching helps" into a number you can defend.

flowchart LR
    B1["Batch-1 decode:<br/>~1 FLOP per byte"] --> R["Ridge point:<br/>~300 FLOPs per byte on H100"]
    B2["Batch-B decode:<br/>~B FLOPs per byte"] --> R
    B3["Prefill of a 4K prompt:<br/>thousands of FLOPs per byte"] --> R
    R -->|"below the ridge"| M["Memory-bound: perf = intensity x bandwidth"]
    R -->|"above the ridge"| C["Compute-bound: perf capped by peak FLOPs"]

What a good answer covers

  • Arithmetic intensity = FLOPs performed per byte moved from memory
  • The roofline model says achievable performance = min(peak_FLOPs, intensity × memory_bandwidth)
  • The ridge for an H100 at BF16 is roughly ~989 TFLOPs ÷ ~3.35 TB/s ≈ ~300 FLOPs/byte; for an A100 it's ~150
  • Now place the two inference phases on that roofline
  • Batch-1 decode: for each weight element (2 bytes in FP16) you do one multiply-add (2 FLOPs) - intensity…

Key terms: Arithmetic intensity · roofline model · Batch-1 decode · Prefill

Interviewer follow-ups to expect

  1. Why doesn't the KV cache read amortise across the batch like weights do?

  2. Where does MoE sit on the roofline compared to a dense model at the same active-parameter count?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep