Unit 4 of 10 · about 5 hours · derive, measure
Arithmetic intensity, a first roofline and the prefill and decode regimes
The roofline turns counts and bytes into a prediction: which side of the ridge each phase sits on, and how much batch it takes to cross. Without it, prefill and decode tuning is guessing.
You'll be able to
- Derive arithmetic intensity for a matmul and a decode step, and the batch where each turns compute-bound.
- Place prefill and decode of one model on the same roofline and name the bound on each side.
- Measure a batch crossover on your own GPU with synchronized event timing and reconcile the knee with your measured peak and bandwidth.
Covers
Read
In this order, only the parts listed
0 of 3 done
- Roofline, arithmetic intensity and the critical batchHow to Scale Your Model - Inference
Where Does the Time Go?: Visualizing rooflines and Matrix multiplication; A Few Problems to Work, Questions 1 and 2 (int8 and mixed-precision answers)
- Linear and attention bottlenecks: the critical batch and attention intensityHow to Scale Your Model - Inference
Linear operations: what bottlenecks us? (the derivation) and What about attention? (the derivation)
- The 208 ratio and per-stage flop-per-byte limitsTransformer Inference Arithmetic
kv cache: Flops vs Memory Boundedness; batch sizes: the qkv/o/w1/w2 table
The article writes the crossover as ; the ratio it computes is peak operations per second over bytes per second, FLOP/byte. Its remark that comms latency was still 11% for a 52B model at batch 512 points at an example the article never works; its worked 260B example at batch 512 gives 3 ms of latency against 53 ms, about 6%. Recompute instead of quoting.
Focus on
- Intensity is operations over bytes moved (); the ridge is peak operations per second over bytes per second, and the bound is the minimum of the two ceilings.
- A bf16 matmul with batch far below width has intensity near the batch size; the chapter's 240 on TPU v5e and 295 on H100 are the same ratio on different hardware.
- Decode attention sits near FLOP/byte at one query token, so batch cannot move it; prefill attention sits near .
- Report the lower (max) and upper (sum) bounds; the gap is the overlap assumption, and profiles decide it.
Common mistakes · 3
- Quoting a ridge without naming the precision. int8 weights with bf16 compute halve the critical batch (120 versus 240 on v5e); int8 compute restores it.
- Reading achieved peaks as vendor peaks. Dense H100 bf16 without sparsity is half the headline (9.89e14, not 1.979e15); measure your own plateau.
- Expecting step time to fall with smaller batch below the knee. One full weight pass already costs about 0.22 ms on the RTX 3050 example above (recompute the floor from your own copy bandwidth); batching toward the knee buys throughput, not latency.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.At what batch does a bf16 matmul turn compute-bound on H100, and why half the headline?Answer
About 295 (9.89e14/3.35e12). The headline 1.979e15 needs structured sparsity, so dense math uses half.
2.What is decode attention intensity at one query token against a long cache, and what follows?Answer
About 1 FLOP/byte from ; it stays memory-bound at any batch, since each request adds its own cache bytes.
3.On TPU v5e, past what prompt length is prefill attention compute-bound?Answer
Past about 480 tokens: intensity must clear the 240 ridge.
4.State the lower and upper runtime bounds for the roofline int8 matmul question.Answer
Lower , upper their sum, with and comms bytes over 8.2e11 per second.
Practice
- Roofline Questions 1, 2 and 5: int8, mixed-precision and H100 critical batch
A Few Problems to Work, Questions 1, 2 and 5 (reproduce 240, 120 and 295 before opening the answers)
- How to Scale Your Model inference Question 3: parameter-load lower bound
Worked Problems, Question 3 (reproduce the 1.4 ms bound for 18.4e9 int8 parameters on 16 chips)
You're done when
Your sweep shows the knee near your measured peak-over-bandwidth ratio, roofline Questions 1, 2 and 5 reproduce their answers, and you state both bounds for one decode step.
Only when you can do this without notes.
Leads to
Notes
Resources · 2 for this unit, 7 more in the section
- How to Scale Your Model - InferenceJAX Scaling Book · primary
Work through the single-request, batching, key-value memory and parallelism arithmetic. Recompute every quantity for the small model and workload used by the track project, keeping symbols, units and assumptions visible.
- Transformer Inference ArithmeticKipply · required
Reproduce the FLOP, parameter-byte, key-value-byte and communication estimates for dense transformer inference. Compare the formulas with an instrumented framework trace and explain model residuals instead of fitting constants after measurement.
Also in this section
- AI Performance Engineering - Start HereWafer · reference
A curated, dated index. Its Start Here list names the readings this section already assigns; use the later sections only to find a primary source for a later section, never as the reading itself.
- Efficiently Scaling Transformer InferenceMLSys · required
Study the latency, memory and parallelism model. Use the paper to derive a batch and parallelism crossover for your workload, while reserving distributed execution for GPU-9.
- EtalonEtalon Authors · support
Read the latency metric definitions, their pitfalls and fluidity-index. Add TTFT and TPOT SLOs to a small load generator, and show why peak token throughput can rank two systems differently from an SLO-qualified rate.
- GPU Microbenchmark and Kernel SuiteRoadmap-Final · support
Adopt the project harness schema, architecture constraints and hardware tiers now. Implement only the environment manifest, independent references, raw-trial storage and the initial operation and byte models in this stage.
- How to Scale Your Model - TrainingJAX Scaling Book · required
Work Some Problems to Work Questions 1 to 3 for training-step parameters, Adam and activation bytes and step time; read Data Parallelism and Fully-Sharded Data Parallelism for the comms-bound batch rule.
- Amdahl's lawWikipedia · reference
Read Definition and Derivation for the overall-speedup formula with the worked share examples; apply it to kernel time shares at fixed workload.
- DistServe: Disaggregating Prefill and Decoding for Goodput-optimized LLM ServingZhong et al. (OSDI 2024) · support
Read Section 1 with Figure 1 for per-GPU goodput: the highest request rate served while a target share of requests meets the TTFT and TPOT SLOs.