Roofline model interview questions for LLM inference
Roofline model interview questions for LLM inference: arithmetic intensity, ridge points, memory-bound vs compute-bound, estimating tokens per second and the batch size where decode becomes compute-bound.
Back-of-envelope performance estimates are the clearest signal that a candidate understands inference rather than having memorised tool names. Expect to do these on a whiteboard with an H100 or similar spec sheet: about 989 TFLOPS dense BF16 and 3.35 TB/s of HBM bandwidth.
Question 1
Explain the roofline model.
Model answer
The roofline model bounds the throughput of a kernel by two limits: how fast the chip can do maths and how fast it can feed data from memory. If a kernel does FLOPs per byte it moves (its arithmetic intensity), the best achievable performance is
where is peak FLOP/s and is memory bandwidth in bytes per second. Plotted on log axes, the part is a sloped line and is a flat roof.
The ridge point is the intensity where the two meet. For an H100 SXM it is about FLOP per byte. Below the ridge the kernel is memory-bound (faster memory or fewer bytes helps); above it the kernel is compute-bound (more FLOP/s or fewer FLOPs helps).
It is a bound, not a prediction: real kernels sit below the roof because of launch overhead, imperfect overlap, cache misses and occupancy limits.
Likely follow-up questions
- What is the arithmetic intensity of a matrix-vector product versus a large matrix-matrix product?
- Why do newer GPUs tend to have higher ridge points, and what does that mean for decode?
- How would you measure where a real kernel sits on the roofline?
Question 2
Estimate the decode speed of a 70B model in FP8 on 4 H100s with tensor parallelism.
Model answer
Weights: 70B parameters at 1 byte each is about 70 GB, split over 4 GPUs, so each GPU reads about 17.5 GB per decode step.
Bandwidth per GPU is 3.35 TB/s, so the memory-bound time per step is
That is an upper bound of about 190 tokens per second for one stream. Then adjust for reality:
- Achieved bandwidth is typically 70 to 85 percent of peak.
- Tensor parallelism adds two all-reduces per layer; over NVLink at batch size 1 these are small but add latency on each of 80 layers.
- The KV cache read adds bytes per step and grows with context length.
A reasonable answer is "roughly 100 to 150 tokens per second for a single stream at modest context", with the reasoning shown. The interviewer cares about the method more than the exact figure.
Likely follow-up questions
- How does the estimate change at a batch of 64 sequences each holding 4,000 tokens of context?
- Why does going from 4 to 8 GPUs not halve the step time?
- What would you expect on a single GPU with 141 GB of memory and 4.8 TB/s?
Question 3
At what batch size does decode become compute-bound?
Model answer
Batching sequences reuses each weight for tokens, so intensity for the weight matmuls rises to roughly
Setting this equal to the ridge point gives the crossover. For BF16 weights (2 bytes) on an H100: , so . For FP8 weights it is about 150, because each byte loaded now carries twice as many parameters.
Two caveats matter in an interview:
- Attention over the KV cache does not get this reuse. Each sequence reads its own cache, so attention stays memory-bound at any batch size, and at long context it can dominate the step.
- Before you reach the crossover you usually run out of KV cache memory. So in practice the batch limit is memory capacity, and decode stays memory-bound.
This is why techniques that shrink KV cache size (GQA, MLA, FP8 KV) raise throughput: they let you batch further along the sloped part of the roofline.
Likely follow-up questions
- How does mixture-of-experts change this calculation?
- Why do throughput gains from batching flatten before the computed crossover?
- How would you pick the maximum batch size in vLLM for a latency target?
Question 4
Prefill is compute-bound. So why does FlashAttention help it?
Model answer
The weight matmuls in prefill are compute-bound, but naive attention is not. Standard attention writes the full score matrix to HBM, reads it back for the softmax, writes the probabilities and reads them again to multiply by the values. For long prompts that traffic is large and the softmax and masking steps have very low arithmetic intensity.
FlashAttention tiles the computation so that blocks of queries, keys and values stay in on-chip SRAM, computes the softmax online with a running maximum and sum, and never writes the full score matrix to HBM. That turns a memory-bound sequence of operations into one fused, compute-heavy kernel. The FLOPs are the same (it is exact attention); the bytes moved drop sharply.
So the roofline lens is per operation, not per phase: a phase can be mostly compute-bound while some of its operations are memory-bound and worth fusing.
Likely follow-up questions
- What is the memory complexity of FlashAttention compared with standard attention?
- Why is a separate decode attention kernel (like FlashDecoding) useful?
- Which other memory-bound operations in a transformer layer are usually fused?
Question 5
How does memory bandwidth explain why a Mac or a gaming GPU runs local models at the speed it does?
Model answer
Single-user local inference is batch size 1 decode, so it is almost purely memory-bound. Tokens per second is close to
A 4-bit 8B model is about 4.5 to 5 GB. An RTX 4090 at about 1 TB/s gives a ceiling near 200 tokens per second; an M-series Max chip at 400 to 550 GB/s gives roughly 80 to 110; a dual-channel DDR5 desktop CPU at about 80 GB/s gives under 20. Measured numbers land at 60 to 80 percent of these.
The same formula explains why a larger, lower-bit model can be as fast as a smaller, higher-bit one, and why mixture-of-experts models run well locally: only the active experts' weights are read per token.
Likely follow-up questions
- Why does prompt processing on a Mac lag a discrete GPU much more than generation does?
- How does offloading some layers to CPU RAM change the formula?
- What would you measure to check the effective bandwidth of a machine?
The lesson behind these answers · 18 min · free
Prefill, decode and the roofline: predicting inference speed
Worked numbers, step-through diagrams and a quiz, so you can derive the answer in the interview instead of reciting it.
Read the lesson →- Units and vocabulary: FLOPs, bytes, bandwidth and the balance point · Start Here: The Plan20 min
- Memory bandwidth: the speed limit of decoding · Hardware & Sizing11 min
- GPU architecture for inference: memory hierarchy, tensor cores and generations · Bottlenecks and Hardware15 min · Pro
- Prerequisite check, and how to measure from day one · Start Here: The Plan15 min
Articles on this topic
- AMD MI300X vs NVIDIA H100 for LLM inference: specs, software and when AMD wins (6 min read)
- How to become an inference engineer in 2026: a skills roadmap (9 min read)
- Prefill vs decode: why the first token is slow and the rest are fast (8 min read)
- Why memory bandwidth, not compute, decides how fast an LLM runs (6 min read)
Related interview questions
- Prefill vs decode interview questions (5 questions)
- Batching and continuous batching interview questions (5 questions)
- LLM quantization interview questions (5 questions)