Skip to content

Chapter 17: Training at Scale

A model and a correct training loop still need a memory, compute, and recovery plan. The foundations loop uses float32 and retains intermediate activations; a larger batch, longer context, or larger model can make that state dominate memory. This chapter develops the precision, accumulation, recomputation, communication, and checkpoint mechanisms needed to move the capstone from a local experiment to a larger training system.

Concepts from other sections (15)

This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.

The first section supplies the capstone’s precision, accumulation, and recomputation techniques. The next two build process collectives, data parallelism, and ZeRO from small implementations. The final parts connect those mechanisms to tensor, pipeline, context, and expert layouts, then to profiling, numerical failures, checkpointing, and recovery. Implementation checks and production measurements have different scopes: use the small checks to understand the algorithm, then validate memory, quality, and throughput on the actual training stack.

Three ideas run through the whole chapter. Mixed precision keeps a float32 master copy of the weights and computes in bf16; fp16 needs a loss scale so that small gradients do not underflow. Accumulation sums gradients over micro-batches so that a large effective batch fits in memory, with each micro-batch’s loss weighted by its share of the objective’s units, such as valid target tokens; data parallelism is the same idea spread over processes. Checkpointing stores activations at segment boundaries and recomputes the rest during backward, trading compute for memory.

Learning objectives

You should be comfortable with the Tensor and training loop of the Foundations chapter. From Mathematics, the chapter leans on the bf16 and fp16 emulation in Numerical Methods and Floating Point, the optimizers and gradient clipping in Optimization, and the checkpoint schedule in Hessian-vector products and the recompute-versus-memory schedule.

  1. Mixed precision, loss scaling, gradient accumulation, and activation checkpointing: the four tools every large training run uses, built from first principles and checked against float32, as used by the capstone’s --bf16 --accum --checkpoint-activations flags.
  2. Collectives over processes: ring all-reduce (optional): point-to-point messages between processes, the ring reduce-scatter and all-gather, why the ring’s traffic per link does not grow with the number of ranks, and how to avoid deadlock.
  3. Data parallelism and ZeRO stages 1 to 3 (optional): data parallelism as accumulation across processes, and sharding the optimizer state, gradients, and parameters so that per-rank memory falls toward 1/p1/p.
  4. Parallelism, topology, and the global batch: choose the dimension to split, count independent replicas, and validate distributed equivalence.
  5. Training failures, profiling, and recovery: diagnose data/numerical/optimization failures, save complete state, and test interrupted-run continuation.