Scaling Book

Conclusions and Further Reading

11. Conclusions

This last section is just thanks and a reading list, so here's a short recap instead. Basically every chapter is the same move: count the FLOPs, count the bytes, divide each by the right hardware number, and take the max.

  • Rooflines: A TPU v5e does 1.97e14 FLOPs/s against 8.2e11 bytes/s of HBM, roughly 240 FLOPs/byte, and a bf16 matmul's intensity is about BB. So we need more than 240 tokens per batch to be compute-bound.
  • The speed hierarchy: VMEM, HBM, ICI, PCIe, DCN, fastest to slowest. The traffic on each link has to scale with its speed, so DCN only gets the infrequent transfers.
  • Sharding: A matmul only needs communication when a contracting dimension is sharded: an AllGather first if one input is, an AllReduce or ReduceScatter after if both are. Throughput-bound, an AllGather takes V/WiciV / W_{\text{ici}} whatever the ring size.
  • Transformer math: About 2 FLOPs per parameter per token for a forward pass, 6 for training, and the MLP holds most of the parameters and FLOPs.
  • Training: Data parallelism and FSDP go comms-bound below about 2,550 tokens per chip on a TPU v5p, tensor parallelism past about F/2550F / 2550 shards, and mixing the two gets us down to roughly 100 tokens.
  • Inference: Prefill looks like training and is compute-bound. Generation needs 240 requests in flight to get there, so at small batch the step time is just bytes over bandwidth, and the KV cache decides how big a batch we can afford.

The full series is at jax-ml.github.io/scaling-book.

Further Reading

The reading list from the end of How to Scale Your Model: