Contents
Chapter 5

Measuring and Scaling

Rooflines, MFU, collectives and the price of a joule

How fast should this be? This chapter gives you the yardsticks: the roofline for kernels, MFU for training runs, the α-β model for collectives and Amdahl for scaling. It ends with the cost that is easiest to ignore, energy, and the simplest lever for it, power capping.

5.1Roofline model

Every kernel has an arithmetic intensity (AI): FLOPs performed per byte moved from memory. The roofline says:

attainable FLOP/s = min( peak FLOP/s ,  AI × memory bandwidth )

Plot it on log-log axes and you get a slanted "memory roof" meeting a flat "compute roof" at the ridge point. For an H100 in BF16 that's ~989 TFLOP/s ÷ 3.35 TB/s ≈ 295 FLOPs/byte.

  • Elementwise ops (add, GELU, layer norm) have AI around 1. They're hopelessly memory-bound, so fuse them.
  • Large matmuls have AI in the thousands. They're compute-bound, and that's where tensor cores shine.
  • Attention without fusion is memory-bound. FlashAttention restructures it to stay on-chip.

The PRACE GPGPU guide uses the same reasoning for HPC kernels: first decide which roof you're under, then optimize for that resource.

LIVE Roofline explorer
0.11101001k0.11101001k10kFLOPs per byteTFLOP/sattainablevector addlayer normsmall GEMM4k×4k GEMMyou
Attainable
105.9 TFLOP/s
% of peak
11%
Ridge point
295 FLOP/B
Regime
memory-bound

Arithmetic intensity = FLOPs ÷ bytes moved from HBM. Kernel positions are illustrative.

Checkpoint+50 XP30 XP if you need a retry
H100 BF16: 989 TFLOP/s peak and 3.35 TB/s HBM. Where's the ridge point, in FLOPs per byte?
FLOP/B
A kernel with arithmetic intensity 10 runs on an H100. It can reach about…

5.2MFU (Model FLOPs Utilization)

For dense transformers, training costs about 6 × parameters × tokens FLOPs (2 forward + 4 backward). MFU compares what you achieved to the theoretical peak:

MFU = (6 · N · tokens_per_second) / (num_GPUs · peak_FLOP/s)

It deliberately ignores recomputation from Activation checkpointing (that's HFU, hardware FLOPs utilization), so it only rewards useful work.

What's good? 35–55% is typical for well-tuned large-model training on H100-class clusters. Above 60% is excellent.

What drags it down: small micro-batches, exposed communication (no overlap), pipeline bubbles, data-loader stalls, Stragglers, throttled clocks and plain FP32. The Feed the Beast mission walks through these in order.

Checkpoint+50 XP30 XP if you need a retry
A 7B model trains at 500k tokens/s on 32 H100s (989 TFLOP/s each). MFU = 6·N·tokens/s ÷ (GPUs × peak). In %?
%
Do recomputed FLOPs from activation checkpointing count toward MFU?

5.3All-reduce (ring & tree)

Ring all-reduce arranges n ranks in a ring and runs two phases (reduce-scatter, then all-gather) of n−1 steps each. Every rank sends and receives ~2(n−1)/n × the buffer size:

T_ring ≈ 2(n−1)/n · S/B  +  2(n−1) · α

where S is bytes, B is per-link bandwidth and α is per-step latency. The bandwidth term barely grows with n. The latency term does, which hurts small messages at large scale.

Tree algorithms (NCCL's double binary tree) cut the latency term to ~log₂(n) steps and win for small messages and very large rank counts.

Bus bandwidth, the number nccl-tests reports, normalizes away the 2(n−1)/n factor, so you can compare it straight to link speed. A healthy NVLink node shows hundreds of GB/s. A node with a degraded link shows PCIe-class numbers.

Use the widget to see how size, rank count and bandwidth trade off.

LIVE All-reduce cost model
ringtree
1 µs100 µs10.0 ms1.0 s1 KB100 KB10 MB1 GBmessage sizetimetreeringyou
Ring
14.0 ms
Tree
13.4 ms
Algorithm bw
23.6 GB/s
Bus bw (ring)
43.7 GB/s

α-β model: ring = 2(n−1)/n·S/B + 2(n−1)·α; tree ≈ 2·S/B + 2·log₂(n)·α. Real NCCL picks per message size and topology.

Checkpoint+50 XP30 XP if you need a retry
Ring all-reduce of 1 GB across 8 GPUs at 100 GB/s per link, ignoring latency: 2(n−1)/n · S/B. Time in ms?
ms
Tree all-reduce algorithms beat rings mainly for…

5.4Scaling efficiency

Amdahl's law: if a fraction s of the work is serial, the speedup on n workers is at most 1 / (s + (1−s)/n). Even 5% serial work caps you at 20× speedup.

Distributed training adds communication that grows with scale: collective latency terms, cross-rack hops, and the growing chance that some GPU is slow (see Stragglers).

Weak vs strong scaling

  • Strong scaling: same problem, more GPUs. Efficiency drops as per-GPU work shrinks.
  • Weak scaling: grow the batch with the GPU count. Much friendlier, which is why large-batch training exists, within the limits of what still converges.

Measuring it: scaling efficiency = (throughput at n) / (n × throughput at 1). Report it alongside MFU. A job can scale perfectly and still be inefficient per GPU.

LIVE Scaling efficiency
idealactual
1×4×16×64×256×1024×1416642561024workersspeedupidealactual15.3×
Speedup
15.3×
Efficiency
24%
Amdahl ceiling
50×

Speedup = 1 / (serial + (1 − serial)/n + comm·log₂ n). A toy model, but it shows why efficiency decays.

Checkpoint+50 XP30 XP if you need a retry
Amdahl's law: 5% of the work is serial. What's the maximum speedup, even with infinite GPUs?
×
1 GPU does 10k tokens/s; 64 GPUs do 512k tokens/s. Scaling efficiency, in %?
%

5.5Input pipeline

Once the model math is fast, the CPU side often becomes the limit: reading shards from storage, decompressing, tokenizing, shuffling and collating batches.

Symptoms: GPU utilization saw-tooths, step time doesn't improve when you optimize the model, and logs show time waiting on the next batch.

Fixes

  • More data-loader workers (processes) per rank, and pinned memory.
  • Prefetching: prepare batch k+1 while batch k trains (see CUDA streams & async execution).
  • Pre-tokenize offline and store packed binary shards. It's the single biggest win for LLM pretraining.
  • Make sure the parallel filesystem or object store can deliver the aggregate bandwidth: GPUs × tokens/s × bytes per token, plus checkpoint traffic.

The Feed the Beast mission shows the bottleneck moving to data loading the moment communication is fixed.

Checkpoint+50 XP30 XP if you need a retry
Your job log says this. What's the best first fix?
[rank0] step 120 | loss 3.112 | 1.02 s/step | 128.4k tok/s | MFU 32.5% | dataloader wait
Each worker tokenizes 8k tokens/s. A rank needs 64k tokens per 1-second step. Minimum number of workers?

5.6Power capping

Near the top of the voltage/frequency curve, power grows much faster than performance: dynamic power ∝ f·V², and voltage must rise with frequency. Capping power therefore costs proportionally less performance than it saves.

In training, only the compute-bound part of each step slows down. Communication, data loading and pipeline bubbles don't care about SM clocks, so the real-world throughput hit is smaller still.

How

sudo nvidia-smi -pl 550            # all GPUs on this node
sudo nvidia-smi -pl 550 -i 3       # just GPU 3

Caps reset on reboot unless managed by your provisioning or by DCGM policies.

Caveats: cap all GPUs in a job. Capping one creates a straggler. And measure tokens per joule, not just tokens per second.

LIVE Power cap trade-off (H100, fully loaded)
throughputenergy / token
40%60%80%100%300 W400 W500 W600 W700 Wpower limit% of uncappedthroughputenergy / token91%
Throughput
91%
Power
79%
Energy per token
86%

Only the compute-bound share of each step slows with clocks; communication and data loading don't.

Checkpoint+50 XP30 XP if you need a retry
Why does a power cap cost less performance than the power it saves?
You cap only 1 of the 16 GPUs in a training job. What happens?

5.7Energy & carbon

A GPU cluster is a power plant's customer. A rough accounting:

facility energy (kWh) = IT energy (GPUs + hosts + network) × PUE
emissions (kg CO₂e)   = facility energy × grid carbon intensity
  • PUE (Power Usage Effectiveness) captures cooling and power-delivery overhead: ~1.1 for the best liquid-cooled sites, 1.3–1.6 for typical ones.
  • Carbon intensity varies by more than 10× between regions and by time of day. Where and when you train can matter as much as how.

Levers you control

  • Efficiency first: higher MFU means fewer GPU-hours for the same model.
  • Power caps trade a little speed for a lot of energy.
  • Right-size: don't leave idle allocations running. Schedulers can reclaim them.
  • Report kWh and CO₂e per run, next to cost and accuracy, so trade-offs are visible.

Every LazyLab run shows its energy, cost and carbon in the header.

Checkpoint+50 XP30 XP if you need a retry
IT load of 100 kW, PUE 1.3, running for 24 hours. Facility energy in MWh?
MWh
3,000 kWh on a grid at 0.4 kg CO₂e per kWh. How many kg of CO₂e?
kg
◆ Boss mission

Watts Up

The facility asks for a 20% power cut. Keep at least 85% of the throughput.

🔒 Master 4 more section(s) in this chapter to unlock.Play anyway