Scaling Book

How to Think About GPUs

12. Thinking About GPUs

Chapters 2, 3 and 5 again, but for NVIDIA GPUs (mostly the H100 and B200).

What Is a GPU?

A GPU looks a lot like a TPU, but instead of 1 or 2 big TensorCores it has over a hundred small, mostly independent Streaming Multiprocessors (SMs): 132 on an H100, 148 on a B200. Each SM has 4 subpartitions, each with:

  • Tensor Core: The matmul unit, so the GPU's MXU (confusingly, not a TPU TensorCore). Almost all the FLOPs/s live here, 990 TFLOPs/s in bf16 on an H100.

  • CUDA Cores: 32 fp32 ALUs for vector math, like the lanes of the TPU's VPU.

  • Register file: 16,384 32-bit registers.

An SM also switches between up to 64 warps (groups of 32 threads) to hide memory waits, where a TPU is basically single-threaded.

Memory

  • SMEM: 256kB of L1 cache per SM, the GPU's VMEM. The B200 adds 256kB of TMEM per SM.

  • L2 cache: About 50MB on an H100, shared and not under our control.

  • HBM: 80GB at 3.35 TB/s on an H100, 192GB at 8 TB/s on a B200.

Summary of GPU specs

The full table is under Reference Numbers. The bf16 critical intensity is around 295 FLOPs/byte on an H100 and 281 on a B200 (240 on a TPU v5e), so matmuls still need a few hundred tokens of batch to be compute-bound.

GPUs vs. TPUs at the chip level

An H100 has 132×4=528132 \times 4 = 528 independent vector units of 32 lanes, against 8 units of 1,024 on a TPU v5p, so it's more flexible but less predictable. TPUs make up for smaller chips with more of them, a stronger network, and far more fast cache (128MB of VMEM on a v5p against 33MB of SMEM on an H100).

Networking

GPUs sit at the bottom of a tree of switches: any GPU can reach any other, but the bandwidth depends on how far up the tree a message climbs. Links are quoted in bits (400 Gbps is 50 GB/s) and per direction.

At the node level

A node is 8 GPUs wired all-to-all through NVSwitches, the telephone switchboard from Chapter 2. On an H100 each GPU has 18 NVLink links at 25 GB/s each way, so 18×25=450 GB/s18 \times 25 = 450\text{ GB/s} in and out of every GPU. The B200 doubles that to 900 GB/s.

Beyond the node level

Past the node, every GPU has its own 400 Gbps InfiniBand NIC, so a node has 8×50=400 GB/s8 \times 50 = 400\text{ GB/s} of egress. NVIDIA's reference H100 SuperPod puts 32 nodes under 8 leaf switches (a Scalable Unit, or SU) and 4 SUs under 16 spine switches. It's a fat tree: the cabling thickens towards the top, so any node can send its full 400 GB/s to any other node. The diagrams on jax-ml.github.io/scaling-book/gpus/ help a lot here.

So two numbers to remember: 450 GB/s per GPU inside a node, 400 GB/s per node outside it. That second one is only 50 GB/s per GPU, a 9×9\times drop. The GB200 NVL72 eases this with 72 GPUs per NVLink domain and 3.6 TB/s of node egress.

How Do Collectives Work on GPUs?

Intra-node collectives

AllGather and ReduceScatter run around a ring like on a TPU, at full GPU egress:

TAG or RS=bytes⋅(N−1)N⋅WGPU≈bytesWGPUT_{\text{AG or RS}} = \frac{\text{bytes} \cdot (N - 1)}{N \cdot W_{\text{GPU}}} \approx \frac{\text{bytes}}{W_{\text{GPU}}}

An AllReduce is still twice that. AllToAll is where the switch pays off: every GPU sends each chunk straight to its destination for about bytes/(N⋅WGPU)\text{bytes} / (N \cdot W_{\text{GPU}}), half the torus cost at N=8N = 8.

With SHARP (in-network reductions) the switch does the summing, so an AllReduce costs bytes/WGPU\text{bytes} / W_{\text{GPU}} instead of twice that. In practice it's more like a 30% gain, and NVLink AllReduce tops out near 370 GB/s.

Cross-node collectives

Above the node, an AllGather or ReduceScatter is one big ring through the nodes at about bytes/400e9\text{bytes} / 400\text{e}9. AllToAll does NOT survive the trip: all 8 GPUs of a node squeeze through the same 400 GB/s, so two nodes are already 4.5×4.5\times slower than one.

On a TPU, sharding the array over a second axis YY makes the collective YY times cheaper. On GPUs that's only half true. With YY as the inner axis:

Tnode=bytesWGPU⋅min⁡(Y,8)Tscale-out=bytesWnode⋅8max⁡(Y,8)T_{\text{node}} = \frac{\text{bytes}}{W_{\text{GPU}} \cdot \min(Y, 8)} \qquad T_{\text{scale-out}} = \frac{\text{bytes}}{W_{\text{node}}} \cdot \frac{8}{\max(Y, 8)}

If Y≤8Y \le 8, the node still pushes the whole array through its one uplink, so the total doesn't move. Only when YY spans several nodes does the cross-node cost drop. I think this is the one fact worth memorizing here.

Rooflines for LLM Scaling on GPUs

Same setup as Chapter 5: one MLP block (Win[D,F]W_{\text{in}}[D, F], Wout[F,D]W_{\text{out}}[F, D]), batch BB in tokens, CC FLOPs/s per GPU. WW is 450e9 inside a node and 400e9 outside, so for an H100 C/WC/W is 2,200 or 2,475.

Data Parallelism

Pure DP and FSDP (ZeRO) both do a weight-sized AllReduce (or ReduceScatter plus AllGather) in the backward pass. With XX replicas:

Tmath=8BDFX⋅CTcomms=8DFW  ⟹  BX>CWT_{\text{math}} = \frac{8BDF}{X \cdot C} \qquad T_{\text{comms}} = \frac{8DF}{W} \implies \frac{B}{X} > \frac{C}{W}

So we need around 2,500 tokens per GPU (2,475 across nodes), against 850 on a TPU v5p. Three adjustments:

  • MoE: multiply by E/kE/k (EE experts, kk active). For E=128E = 128 and k=4k = 4 that's 79,200 tokens per GPU.

  • Only 2-way DP: the ring factor (X−1)/X(X - 1)/X halves the threshold to about 1,238.

  • Model parallelism across nodes: a replica spanning 8 nodes cuts the threshold by 8, since each node only moves its own slice of the weights.

Tensor Parallelism

TP moves activations instead of weights, which works out to Y<F⋅W/CY < F \cdot W / C: F/2200F/2200 inside a node and F/2475F/2475 beyond it. For F=28,672F = 28{,}672 that's 13 and 11.6, so TP fits comfortably in one 8-GPU node.

Expert Parallelism

For MoEs we shard the experts and AllToAll each token to wherever its experts live. Over a node or two that's easy; wider than that we need F>8⋅C/WF > 8 \cdot C/W, about 19,800 on H100s.

Pipeline Parallelism

Splitting the layers across nodes only sends small microbatches of activations between stages, so the comms are basically free. The price is awkward code, pipeline bubbles, and using ZeRO-1 instead of ZeRO-3, which would AllGather the weights every microbatch.

TLDR of LLM scaling on GPUs

Inside a node GPUs are great; leaving it costs 9×9\times per GPU. Spreading a replica over several nodes makes the DP reduction cheaper, so the usual recipe is TP or EP inside a node or two, pipelining across nodes, and DP or ZeRO-1 outside that. Faster chips on the same network make this harder, since C/WC/W goes up.

Worked Problems

Quiz 1: GPU hardware

Question 1 [CUDA cores]: How many fp32 CUDA cores (ALUs) does an H100 have? A B200? How does that compare with the number of independent ALUs in a TPU v5p?

  • SMs, times 4 subpartitions, times 32 fp32 cores:

    H100: 132×4×32=16,896 CUDA coresB200: 148×4×32=18,944 CUDA cores\text{H100: } 132 \times 4 \times 32 = \mathbf{16{,}896 \text{ CUDA cores}} \qquad \text{B200: } 148 \times 4 \times 32 = \mathbf{18{,}944 \text{ CUDA cores}}
  • A TPU v5p has 2 TensorCores, each with a VPU of 4 independent units of 8×1288 \times 128 lanes:

    2×4×8×128=8,192 ALUs2 \times 4 \times 8 \times 128 = \mathbf{8{,}192 \text{ ALUs}}
  • So an H100 has about twice the vector lanes, but in 528 small units instead of 8 big ones.

Question 2 [vector FLOPs calculation]: An H100 has 132 SMs and a 1.59GHz clock (1.98GHz with boost). If every ALU does one vector op per cycle, how many vector fp32 FLOPs/s does the chip get, with and without boost? How does that compare with its matmul FLOPs/s?

  • The cores from Question 1 times the clock:

    16,896×1.59×109=26.9 TFLOPs/s16,896×1.98×109=33.5 TFLOPs/s (boost)16{,}896 \times 1.59 \times 10^9 = \mathbf{26.9 \text{ TFLOPs/s}} \qquad 16{,}896 \times 1.98 \times 10^9 = \mathbf{33.5 \text{ TFLOPs/s (boost)}}
  • The spec sheet's 67 TFLOPs/s counts a fused multiply-add as 2 FLOPs. The Tensor Cores' 990 TFLOPs/s is around 30×30\times the boosted number, so anything that isn't a matmul runs on a much slower machine.

Question 3 [GPU matmul intensity]: What is the peak fp16 matmul intensity on an H100? On a B200? What about fp8? Intensity here means the ratio of matmul FLOPs/s to memory bandwidth.

  • FLOPs/s over bytes/s, like Chapter 1:

    H100: 990×1012 FLOPs/s3.35×1012 bytes/s=295 FLOPs/byteB200: 2250×10128×1012=281 FLOPs/byte\text{H100: } \frac{990 \times 10^{12} \text{ FLOPs/s}}{3.35 \times 10^{12} \text{ bytes/s}} = \mathbf{295 \text{ FLOPs/byte}} \qquad \text{B200: } \frac{2250 \times 10^{12}}{8 \times 10^{12}} = \mathbf{281 \text{ FLOPs/byte}}
  • Both chips do exactly 2×2\times the FLOPs/s in fp8, so the fp8 intensities are 591 and 562.

  • So a bf16 matmul needs a batch of around 280 to 300 tokens, close to the TPU v5e's 240. fp8 also halves the weight bytes, so that batch stays about the same.

Question 4 [matmul runtime]: Using the answer to Question 3, how long should an fp16[64, 4096] * fp16[4096, 8192] matmul take on a single B200? How about fp16[512, 4096] * fp16[4096, 8192]?

  • We read xx and WW and write the output at 2 bytes per element, with 8e12 bytes/s and the table's 2.3e15 FLOPs/s.

  • B=64B = 64:

    2BD+2DF+2BF=524,288+67,108,864+1,048,576=68,681,728 bytes2BD + 2DF + 2BF = 524{,}288 + 67{,}108{,}864 + 1{,}048{,}576 = 68{,}681{,}728 \text{ bytes} Tcomms=68,681,728 bytes8×1012 bytes/s=8.6 μsTmath=4,294,967,296 FLOPs2.3×1015 FLOPs/s=1.9 μsT_{\text{comms}} = \frac{68{,}681{,}728 \text{ bytes}}{8 \times 10^{12} \text{ bytes/s}} = \mathbf{8.6 \ \mu\text{s}} \qquad T_{\text{math}} = \frac{4{,}294{,}967{,}296 \text{ FLOPs}}{2.3 \times 10^{15} \text{ FLOPs/s}} = 1.9 \ \mu\text{s}

    Memory wins, so about 8.6 μs.

  • B=512B = 512:

    Tcomms=79,691,776 bytes8×1012 bytes/s=10.0 μsTmath=34,359,738,368 FLOPs2.3×1015 FLOPs/s=14.9 μsT_{\text{comms}} = \frac{79{,}691{,}776 \text{ bytes}}{8 \times 10^{12} \text{ bytes/s}} = 10.0 \ \mu\text{s} \qquad T_{\text{math}} = \frac{34{,}359{,}738{,}368 \text{ FLOPs}}{2.3 \times 10^{15} \text{ FLOPs/s}} = \mathbf{14.9 \ \mu\text{s}}

    Now the math is the slow part, so about 15 μs.

Question 5 [L1 cache capacity]: What is the total L1/SMEM capacity of an H100? What about register memory? How does this compare with TPU VMEM capacity?

  • SMEM is 256kB per SM, times 132 SMs:

    132×256 kB=33,792 kB=33 MB132 \times 256 \text{ kB} = 33{,}792 \text{ kB} = \mathbf{33 \text{ MB}}
  • Registers are 4×16,384×4=262,1444 \times 16{,}384 \times 4 = 262{,}144 bytes, also 256kB per SM, so another 33 MB.

  • Together that's about 66 MB, roughly half of a TPU v5p's 128MB of VMEM, but split very differently: a TPU has only 256kB of registers, since spilling into its low-latency VMEM is cheap.

Question 6 [calculating B200 clock frequency]: NVIDIA reports that a B200 can do 80 TFLOPs/s of vector fp32 compute. Given that each CUDA core can do 2 FLOPs per cycle with an FMA (fused multiply-add), estimate the peak clock frequency.

  • Question 2 run backwards, with 18,944×2=37,88818{,}944 \times 2 = 37{,}888 FLOPs per cycle:

    80×1012 FLOPs/s37,888 FLOPs/cycle=2.11 GHz\frac{80 \times 10^{12} \text{ FLOPs/s}}{37{,}888 \text{ FLOPs/cycle}} = \mathbf{2.11 \text{ GHz}}
  • A bit above the H100's 1.98GHz boost, high but reasonable since B200s are generally liquid cooled.

Question 7 [estimating H100 add runtime]: Using the figures above, how long should it take to add two fp32[N] vectors on a single H100? Work out both TmathT_{\text{math}} and TcommsT_{\text{comms}}. What is the arithmetic intensity of the operation? If you can get access, run it in PyTorch or JAX for N=1024N = 1024 and N=1024×1024×1024N = 1024 \times 1024 \times 1024 and compare.

  • An add runs on the CUDA cores. It does NN FLOPs and moves 12N12N bytes (two loads and one store at 4 bytes each):

    Intensity=N FLOPs12N bytes=112 FLOPs/byte\text{Intensity} = \frac{N \text{ FLOPs}}{12N \text{ bytes}} = \mathbf{\frac{1}{12} \text{ FLOPs/byte}}
  • The hardware gives about 10 FLOPs/byte (33.5 TFLOPs/s over 3.35e12 bytes/s), so we're memory-bound whatever NN is:

    T=max⁡(N3.35×1013,12N3.35×1012)=N2.79×1011 sT = \max\left(\frac{N}{3.35 \times 10^{13}}, \frac{12N}{3.35 \times 10^{12}}\right) = \mathbf{\frac{N}{2.79 \times 10^{11}} \text{ s}}
  • N=1024N = 1024: TcommsT_{\text{comms}} is 3.7 nanoseconds, far less than a kernel launch, so this one is latency-bound.

  • N=10243N = 1024^3: we move 12×230=12,884,901,88812 \times 2^{30} = 12{,}884{,}901{,}888 bytes:

    T=12,884,901,888 bytes3.35×1012 bytes/s=3.85 msT = \frac{12{,}884{,}901{,}888 \text{ bytes}}{3.35 \times 10^{12} \text{ bytes/s}} = \mathbf{3.85 \text{ ms}}
  • To check it ourselves:

    import time
    import jax
    import jax.numpy as jnp
    
    add = jax.jit(lambda a, b: a + b)
    
    for n in (1024, 1024**3):
        a = jnp.ones((n,), dtype=jnp.float32)
        b = jnp.ones((n,), dtype=jnp.float32)
        add(a, b).block_until_ready()  # compile once before timing
        t0 = time.perf_counter()
        for _ in range(100):
            add(a, b).block_until_ready()
        print(n, (time.perf_counter() - t0) / 100, "seconds per add")
    
  • We'd expect microseconds of pure overhead for N=1024N = 1024 and roughly 4 ms for N=10243N = 1024^3. This question needs an H100, so I'll come back to it.

Quiz 2: GPU nodes

Question 1 [total bandwidth for H100 node]: An 8xH100 node has 4 NVSwitches. What is the total bandwidth of the node? Hint: check the NVLink links and the NVSwitch ports separately.

  • Bandwidth can run out at the GPU links or the switch ports, so we take the smaller. The switches have 4×64 ports×25 GB/s=6.4 TB/s4 \times 64 \text{ ports} \times 25 \text{ GB/s} = 6.4 \text{ TB/s}, and the links:

    8 GPUs×18 links×25 GB/s=3.6 TB/s8 \text{ GPUs} \times 18 \text{ links} \times 25 \text{ GB/s} = \mathbf{3.6 \text{ TB/s}}
  • The links are the limit, so the node has 3.6 TB/s in total.

Question 2 [bisection bandwidth]: Cut a network into two equal halves and add up the bandwidth that crosses the cut. The bisection bandwidth is the smallest value we can get over every way of making that cut. What is it for an 8xH100 node? Hint: the figure usually counts flow in both directions.

  • Through the switches every even split looks the same: 4 GPUs on each side, each pushing 450 GB/s across. Counting both directions:

    2×4×450 GB/s=3.6 TB/s2 \times 4 \times 450 \text{ GB/s} = \mathbf{3.6 \text{ TB/s}}

Question 3 [AllGather cost]: How long does an AllGather of an array of BB bytes take on an 8xH100 node, assuming it's throughput-bound? Then put numbers in for bf16[DX,F]\text{bf16}[D_X, F] with D=4096D = 4096 and F=65,536F = 65{,}536.

  • The ring AllGather from Chapter 3 with NVLink in place of ICI: each of the N=8N = 8 GPUs passes a BN\frac{B}{N} shard per turn for N−1N - 1 turns.

    Tcomms=(N−1)⋅BN⋅WGPU=7B8×450×109≈B450×109T_{\text{comms}} = (N - 1) \cdot \frac{B}{N \cdot W_{\text{GPU}}} = \frac{7B}{8 \times 450 \times 10^9} \approx \frac{B}{450 \times 10^9}
  • For our array, B=4096×65,536×2=536,870,912B = 4096 \times 65{,}536 \times 2 = 536{,}870{,}912 bytes:

    Tcomms=536,870,912×78×450×109=1.04 msT_{\text{comms}} = \frac{536{,}870{,}912 \times 7}{8 \times 450 \times 10^9} = \mathbf{1.04 \text{ ms}}

Quiz 3: Beyond the node level

Question 1 [fat tree topology]: Take the reference SuperPod: 1,024 H100s in 128 nodes of 8, one 400 Gbps NIC per GPU, 4 SUs of 32 nodes with 8 leaf switches each, 16 spine switches, 64-port switches everywhere, and 2 links from every leaf to every spine. What's the pod's node-level bisection bandwidth, and is every link sized for full bisection bandwidth? Hint: check the link and switch bandwidth at each level.

  • 400 Gbps is 50 GB/s per cable, and full bisection bandwidth means every level carries 400 GB/s per node.

  • Node to leaf: one cable from each node to each of the SU's 8 leaves is 400 GB/s per node, 12.8 TB/s per SU, using 32 of each leaf's 64 ports.

  • Leaf to spine: the other 32 go up, 2 cables to each of 16 spines: 8×16×2×50 GB/s=12.8 TB/s8 \times 16 \times 2 \times 50 \text{ GB/s} = 12.8 \text{ TB/s} per SU.

  • Spine: 32 leaves times 2 cables fills all 64 ports, so 3.2 TB/s per spine, and 16×3.2=51.216 \times 3.2 = 51.2 TB/s is exactly 128×400128 \times 400 GB/s. Every level matches.

  • For the bisection, two halves of 64 nodes each send 400 GB/s across:

    64×400 GB/s=25.6 TB/s one way  ⟹  51.2 TB/s counting both directions64 \times 400 \text{ GB/s} = 25.6 \text{ TB/s one way} \implies \mathbf{51.2 \text{ TB/s}} \text{ counting both directions}

Question 2 [scaling to a larger DGX pod]: Say we want to train on 2,048 GPUs instead of 1,024. What's the simplest way to modify the DGX topology above? What about 4,096? Hint: there's no single right answer, but try to keep costs down, and keep link capacity in mind.

  • The constraint is ports: a leaf has 32 facing down and 32 up, and a spine has all 64 facing down.
  • 2,048 GPUs: double everything above the SU. 8 SUs is 64 leaves with 64×32=2,04864 \times 32 = 2{,}048 uplinks, so 32 spines with 1 cable from each leaf. Still a full fat tree at 32×3.2=102.4 TB/s32 \times 3.2 = 102.4 \text{ TB/s}, with 96 switches instead of 48.
  • 4,096 GPUs: 16 SUs is 128 leaves, but a spine reaches at most 64 leaves and a leaf 32 spines, so two levels top out at 2,048 GPUs. Per the solution, we add a core level: 128 spine and 64 core switches, with 64×64=4,09664 \times 64 = 4{,}096 core ports to match the 4,096 leaf uplinks.
  • That's 320 switches plus an extra hop, so the cheaper option is to oversubscribe the top level and give up full bisection bandwidth.

Quiz 4: Collectives

Pop Quiz 1 [AllGather time]: On an 8xH100 node, with 450 GB/s of full-duplex bandwidth, how long does AllGather(bf16[BX,F])\text{AllGather}(\text{bf16}[B_X, F]) take for B=1024B = 1024 and F=16,384F = 16{,}384?

  • Same ring as Quiz 2 Question 3 with a smaller array, 2×1024×16,384=33,554,4322 \times 1024 \times 16{,}384 = 33{,}554{,}432 bytes:

    Tcomms=33,554,432×78×450×109=65 μsT_{\text{comms}} = \frac{33{,}554{,}432 \times 7}{8 \times 450 \times 10^9} = \mathbf{65 \ \mu\text{s}}

Pop Quiz 2 [AllToAll time]: Same 8xH100 node, 450 GB/s of unidirectional bandwidth. How long does AllToAllX→N(bf16[BX,N])\text{AllToAll}_{X \to N}(\text{bf16}[B_X, N]) take? And if only 4 of the 8 entries are known to be non-zero?

  • Careful with the letters: BB is the batch here, and N=8N = 8 is both the second dimension and the GPU count, so the array is V=2BN=16BV = 2BN = 16B bytes.

  • Each GPU keeps 1N\frac{1}{N} of its VN\frac{V}{N} bytes and sends VN2\frac{V}{N^2} straight to each of the other N−1N - 1:

    Tcomms=V⋅(N−1)N2⋅WGPU=7V64×450×109≈V8×450×109=V3.6×1012 sT_{\text{comms}} = \frac{V \cdot (N - 1)}{N^2 \cdot W_{\text{GPU}}} = \frac{7V}{64 \times 450 \times 10^9} \approx \frac{V}{8 \times 450 \times 10^9} = \mathbf{\frac{V}{3.6 \times 10^{12}} \text{ s}}
  • If only 4 of the 8 entries are non-zero: each GPU only ships half of every chunk:

    Tcomms≈V2⋅N⋅WGPU=V7.2×1012 sT_{\text{comms}} \approx \frac{V}{2 \cdot N \cdot W_{\text{GPU}}} = \mathbf{\frac{V}{7.2 \times 10^{12}} \text{ s}}
  • Meaning, an AllToAll inside a node acts like it has 3.6 TB/s, 8×8\times the AllGather bandwidth, which is why MoE routing is cheap as long as it stays in one node.

Pop Quiz 3 [sharding along 2 axes]: Say we want to do AllGatherX(bf16[DX,FY])\text{AllGather}_X(\text{bf16}[D_X, F_Y]) over a single SU (256 chips), where YY is the inner axis. How long will this take as a function of DD, FF and YY?

  • The array is 2DF2DF bytes, and there are X=256/YX = 256/Y groups of YY GPUs, each group filling a node first.

  • Case 1, Y≤8Y \le 8: every node holds all YY slices of FF, so it needs 3132\frac{31}{32} of the array through one 400 GB/s uplink:

    Tcomms=2DF⋅3132×400×109≈2DF400×109 sT_{\text{comms}} = \frac{2DF \cdot 31}{32 \times 400 \times 10^9} \approx \mathbf{\frac{2DF}{400 \times 10^9} \text{ s}}
  • Case 2, Y>8Y > 8: a group spans Y/8Y/8 nodes, and each GPU pulls its own slice of FF through its 50 GB/s share of the uplink:

    Tcomms=2DFY×50×109⋅X−1X≈2DFY×50×109 sT_{\text{comms}} = \frac{2DF}{Y \times 50 \times 10^9} \cdot \frac{X - 1}{X} \approx \mathbf{\frac{2DF}{Y \times 50 \times 10^9} \text{ s}}
  • For D=8192D = 8192 and F=32,768F = 32{,}768 (2DF=536,870,9122DF = 536{,}870{,}912 bytes), that's about 1.34 ms for any Y≤8Y \le 8, then 0.67, 0.34, 0.17 and 0.08 ms as YY doubles from 16 to 128. Meaning, model parallelism inside a node does nothing for the outer AllGather, and past that every doubling of YY halves the cost.

Question 1 [SU AllGather]: Take one SU with MM nodes of NN GPUs each and run an AllGather across all of it. Exactly how many bytes go into and out of a node-level switch? And the top-level switch?

  • For a BB-byte array, each of the MNMN GPUs starts with BMN\frac{B}{MN}. A node's switch takes in BM\frac{B}{M} from its GPUs and the missing B(M−1)M\frac{B(M - 1)}{M} from the top, sends BM\frac{B}{M} up, and sends each GPU all but its own shard, N⋅(B−BMN)=NB−BMN \cdot \left(B - \frac{B}{MN}\right) = NB - \frac{B}{M}:

    Ingress=BM+B(M−1)M=BEgress=BM+NB−BM=NB\text{Ingress} = \frac{B}{M} + \frac{B(M - 1)}{M} = \mathbf{B} \qquad \text{Egress} = \frac{B}{M} + NB - \frac{B}{M} = \mathbf{NB}
  • Top-level switch: BM\frac{B}{M} from each of the MM nodes is B\mathbf{B} in, and each node gets back its missing share, so B(M−1)\mathbf{B(M - 1)} out.

  • Egress sets the time, at 450 GB/s per GPU and 400 GB/s per node:

    Tnode≈B450×109Ttop=B⋅(M−1)M×400×109=B413×109 for M=32T_{\text{node}} \approx \frac{B}{450 \times 10^9} \qquad T_{\text{top}} = \frac{B \cdot (M - 1)}{M \times 400 \times 10^9} = \frac{B}{413 \times 10^9} \text{ for } M = 32
  • So an AllGather over a whole SU runs at about 413 GB/s, not far off a single node.

Question 2 [single-node SHARP AR]: Now a single node of NN GPUs doing an AllReduce with SHARP (in-network reductions). Exactly how many bytes does the switch take in and send out?

  • Each GPU starts with its own unreduced BB-byte copy, split into NN chunks, and GPU jj finishes chunk jj.

  • Step 1: each GPU sends the switch every chunk but its own. Ingress B(N−1)B(N - 1).

  • Step 2: the switch sums each chunk and sends chunk jj's partial sum to GPU jj. Egress BB.

  • Step 3: GPU jj adds its own copy and sends the finished chunk back. Ingress BB.

  • Step 4: the switch multicasts each finished chunk to the other N−1N - 1 GPUs. Egress B(N−1)B(N - 1).

    Ingress=B(N−1)+B=NBEgress=B+B(N−1)=NB\text{Ingress} = B(N - 1) + B = \mathbf{NB} \qquad \text{Egress} = B + B(N - 1) = \mathbf{NB}
  • Per GPU that's BB each way, so B/WGPUB / W_{\text{GPU}}. Without SHARP each GPU egresses 2B(N−1)N\frac{2B(N - 1)}{N}, or 1.75B1.75B for N=8N = 8, so SHARP is 1.75×1.75\times faster in theory.

Question 3 [cross-node SHARP AR]: An array bf16[DX,FY]\text{bf16}[D_X, F_Y] is sharded over the NN GPUs of one node. With in-network reductions, how long does AllReduce(bf16[D,FY]{UX})\text{AllReduce}(\text{bf16}[D, F_Y] \{U_X\}) take? What changes once there's more than one node?

  • Each of the node's N=XYN = XY GPUs holds an unreduced 2DFY\frac{2DF}{Y} bytes, and the XX GPUs sharing a slice of FF sum theirs. That's Question 2 running YY times side by side:

    Tcomms=2DFY⋅WGPU=2DFY×450×109 sT_{\text{comms}} = \mathbf{\frac{2DF}{Y \cdot W_{\text{GPU}}}} = \frac{2DF}{Y \times 450 \times 10^9} \text{ s}
  • More than one node: the reduction over XX now crosses nodes. A node's YY slices of FF can't be summed with each other, so all 2DF2DF bytes go through its 400 GB/s uplink:

    Tcomms=2DFWnode=2DF400×109 sT_{\text{comms}} = \frac{2DF}{W_{\text{node}}} = \frac{2DF}{400 \times 10^9} \text{ s}
  • The YY is gone, same lesson as Pop Quiz 3.

Question 4 [spine level AR cost]: Same setup as Question 3, except Y=256Y = 256, which pushes the AllReduce up to the spine level. How long does it take, again with in-network reductions?

  • With Y=256Y = 256 each slice of FF lives on one GPU per SU, and we reduce over the X=4X = 4 SUs. Each GPU sends and receives its 2DF256\frac{2DF}{256} bytes through its own 50 GB/s NIC, all 256 at once, since the fat tree gives each SU 12.8 TB/s to the spine:

    Tcomms=2DF256×50×109=2DF12.8×1012 sT_{\text{comms}} = \frac{2DF}{256 \times 50 \times 10^9} = \mathbf{\frac{2DF}{12.8 \times 10^{12}} \text{ s}}
  • That's 32×32\times the bandwidth of the Y≤8Y \le 8 case. Without SHARP it would take 2⋅X−1X=1.5×2 \cdot \frac{X - 1}{X} = 1.5\times longer.

Question 5 [2-way AllGather cost]: What does an AllGather of BB bytes cost over exactly 2 nodes? Keep the exact ring factors instead of the usual approximation, and work out the intra-node cost as well as the cross-node one.

  • 2 nodes is 16 GPUs with B16\frac{B}{16} each.

  • Cross-node: each node pulls in the other half at 400 GB/s:

    Tcross=B⋅(M−1)M⋅Wnode=B2×400×109=B800×109T_{\text{cross}} = \frac{B \cdot (M - 1)}{M \cdot W_{\text{node}}} = \frac{B}{2 \times 400 \times 10^9} = \frac{B}{800 \times 10^9}
  • Intra-node: each GPU's NIC brings in 18\frac{1}{8} of the remote half, so every GPU owns B8\frac{B}{8}, and the other 7B8\frac{7B}{8} comes over NVLink:

    Tnode=B⋅(N−1)N⋅WGPU=7B8×450×109=B514×109 sT_{\text{node}} = \frac{B \cdot (N - 1)}{N \cdot W_{\text{GPU}}} = \frac{7B}{8 \times 450 \times 10^9} = \mathbf{\frac{B}{514 \times 10^9} \text{ s}}
  • The node level is slower, so a 2-node AllGather is NVLink-bound at 514 GB/s. The M−1M\frac{M - 1}{M} factor doubles the cross-node bandwidth here, which is where the 2-way DP discount in the notes comes from.

Quiz 5: LLM rooflines

Question 1 [B200 rooflines]: A B200 DGX SuperPod (NOT the GB200 NVL72) has 2×2\times the bandwidth within a node (900 GB/s of GPU egress) but the same bandwidth in the scale-out network (400 GB/s per node). The FLOPs/s are in the reference table. How does this change the model-parallel and data-parallel rooflines?

  • Every roofline sees the hardware through C/WC/W, so we recompute it with C=2250e12C = 2250\text{e}12:

    In a node: 2250×1012900×109=2,500Across nodes: 2250×1012400×109=5,625\text{In a node: } \frac{2250 \times 10^{12}}{900 \times 10^9} = \mathbf{2{,}500} \qquad \text{Across nodes: } \frac{2250 \times 10^{12}}{400 \times 10^9} = \mathbf{5{,}625}
  • Model parallelism (TP): inside a node the limit goes from F/2200F/2200 to F/2500F/2500, 13.0 down to 11.5 for F=28,672F = 28{,}672, still above 8. Across nodes it drops from F/2475F/2475 to F/5625F/5625, only about 5.

  • Data parallelism: the per-GPU batch we need jumps from 2,475 to 5,625 tokens.

  • So a faster chip on the same network is harder to keep busy. The GB200 NVL72's 3.6 TB/s of node egress brings the cross-node ratio down to 625.

Question 2 [how to shard LLaMA-3 70B]: We're training LLaMA-3 70B with bfloat16 weights and Adam, with the optimizer state kept in fp32.

1. What's the smallest number of H100s that can hold the weights and the optimizer state?

  • 2 bytes per parameter for the bf16 weight, plus Adam's two moments at 4 bytes each:

    70×109×(2+8) bytes=700 GB700 GB80 GB per H100=8.75  ⟹  9 GPUs70 \times 10^9 \times (2 + 8) \text{ bytes} = 700 \text{ GB} \qquad \frac{700 \text{ GB}}{80 \text{ GB per H100}} = 8.75 \implies \mathbf{9 \text{ GPUs}}
  • GPUs come in nodes of 8, so in practice 2 nodes, before gradients or activations.

2. How long does training take on 4,096 H100s for 15T tokens at 45% MFU (Model FLOPs Utilization)?

  • The 6×parameters×tokens6 \times \text{parameters} \times \text{tokens} rule from Chapter 4, at 45% of peak:

    6×70×109×15×1012=6.3×1024 FLOPs4,096×990×1012×0.45=1.82×1018 FLOPs/s6 \times 70 \times 10^9 \times 15 \times 10^{12} = 6.3 \times 10^{24} \text{ FLOPs} \qquad 4{,}096 \times 990 \times 10^{12} \times 0.45 = 1.82 \times 10^{18} \text{ FLOPs/s} 6.3×10241.82×1018=3.45×106 s≈40 days\frac{6.3 \times 10^{24}}{1.82 \times 10^{18}} = 3.45 \times 10^6 \text{ s} \approx \mathbf{40 \text{ days}}

3. The model has F=28,672F = 28{,}672 and a batch of about 4M tokens. How much model parallelism can we use before it's comms-bound? On 4k chips, does that plus pure DP stay compute-bound? With ZeRO-3 instead? With 8-way pipelining added? Check GPU memory as well as communication.

  • Model parallelism: F/2200≈13F / 2200 \approx 13, more than a node's 8 GPUs, so we stop at 8-way TP.

  • 8-way TP plus pure DP: each replica holds 700 GB on 8 GPUs, 87.5 GB per GPU against the H100's 80, so no. The comms fail too: 4×106/4,096≈9774 \times 10^6 / 4{,}096 \approx 977 tokens per GPU against the 2,475 we need.

  • ZeRO-3: sharding everything over 4,096 GPUs fixes the memory (around 0.17 GB each) but not the comms. On top of the backward-pass reduction, ZeRO-3 also gathers the weights for the forward pass, so the solution doubles DP's bound to about 4,950 tokens per GPU. We have 977, so no.

  • 8-way pipelining: a replica is now 8-way TP times 8 stages, 64 GPUs over 8 nodes, with 64-way DP on top. Each node only moves 18\frac{1}{8} of the weights, so the effective bandwidth is 8×400=3,200 GB/s8 \times 400 = 3{,}200 \text{ GB/s}:

    CW=990×10123,200×109≈309 tokens per GPU\frac{C}{W} = \frac{990 \times 10^{12}}{3{,}200 \times 10^9} \approx \mathbf{309 \text{ tokens per GPU}}
  • We have 977, about 3.2×3.2\times more, and memory is fine at 700/64≈10.9 GB700 / 64 \approx 10.9 \text{ GB} per GPU. So yes: 8-way TP, 8-way PP and 64-way DP works on paper, with ZeRO-1.

Question 3 [Megatron-LM hyperparams]: A figure in the Megatron-LM repository lists the hyperparameters behind their high MFU numbers, all at a sequence length of 4096. What per-GPU batch size, in tokens, do the 16B, 70B and 314B models use? With data parallelism outermost and bfloat16 reductions, is each config compute-bound or communication-bound on paper, and could any be configured better?

  • The configs, as the solution reads them off the figure: 16B has 192 sequences on 192 GPUs, 70B has 384 on 768 GPUs with 16-way model parallelism (TP times PP), and 314B has 1,536 on 3,072 GPUs with 64-way.

  • Per-GPU batch: sequences times 4096 tokens, over GPUs:

    16B: 192×4096192=4,09670B: 384×4096768=2,048314B: 1,536×40963,072=2,048\text{16B: } \frac{192 \times 4096}{192} = \mathbf{4{,}096} \qquad \text{70B: } \frac{384 \times 4096}{768} = \mathbf{2{,}048} \qquad \text{314B: } \frac{1{,}536 \times 4096}{3{,}072} = \mathbf{2{,}048}
  • With DP outermost we need 2,475 tokens per GPU, divided by the nodes a replica spans:

    • 16B: 4,096 against 2,475, about 1.65×1.65\times to spare.
    • 70B: 16-way is 2 nodes, so 1,238 against 2,048, about 1.65×1.65\times again.
    • 314B: 64-way is 8 nodes, so 309 against 2,048, about 6.6 times over.
  • All three are compute-bound on paper, but 1.65×1.65\times isn't much headroom when real collectives fall short of spec. The 314B could spread the same batch over roughly 6.6×6.6\times more GPUs.

Reference Numbers

The V100 has no bf16 Tensor Core figure.

ModelSMs/chipSMEM/SML2/chipHBM capacity/chipHBM BW/chip (bytes/s)FLOPs/s (bf16/fp16)FLOPs/s (fp8/int8)FLOPs/s (fp4)
V1008096kB6MB32GB9.0e11n/an/an/a
A100108192kB40MB80GB2.0e123.1e146.2e14n/a
H100132256kB50MB80GB3.4e129.9e142.0e15n/a
H200132256kB50MB141GB4.8e129.9e142.0e15n/a
B200148256kB126MB192GB8.0e122.3e154.5e159.0e15

Every generation has 256kB of register memory per SM, and the B200 adds 256kB of TMEM per SM. Clocks are 1.59GHz (1.98GHz boost) for the H100 and H200; the B200's isn't published.

Interconnect Figures

NVLink inside a node, by generation:

NVLinkGPU generationBW/link (GB/s, each way)Links/GPUGPU egress (GB/s)Node sizeNVSwitches/node
3.0Ampere (A100)251230086
4.0Hopper (H100, H200)251845084
5.0Blackwell (B200)50189008 or 722 or 18

The reference 1,024-GPU H100 SuperPod, level by level:

LevelGPUsChildrenSwitches per unitSwitch BW (TB/s)Cable BW (TB/s)Collective BW (GB/s)
Node88 GPUs4 NVSwitch6.43.6450 per GPU
Leaf (SU)25632 nodes8 InfiniBand25.612.8400 per node
Spine1,0244 SUs16 InfiniBand51.251.2400 per node

Egress by node type, which is what the rooflines use:

Node typeGPUs/nodeGPU egress (bytes/s)Node egress (bytes/s)
H1008450e9400e9
B2008900e9400e9
GB200 NVL7272900e93600e9

All of these are full-duplex, with one 400 Gbps (50 GB/s) InfiniBand NIC per GPU.