Skip to content
ML to LLMs
Learning path

Module 27

Training at scale

Train models too big or too slow for one GPU: mixed precision and clipping, gradient checkpointing, collective communication, data/tensor/pipeline parallelism, and ZeRO/FSDP sharding.

  1. 1. Gradient clipping and mixed precisionClip gradients by their global norm, train in bf16 or fp16 with loss scaling, and diagnose NaNs, skipped steps, and loss spikes.40 min
  2. 2. Gradient checkpointingTrade compute for memory by storing only some activations and recomputing the rest during backward; size activation memory and pick a checkpointing policy.35 min
  3. 3. Collective operations from scratchBuild ring reduce-scatter, all-gather, and all-reduce, prove the 2(N-1)/N bandwidth cost, and pick ring or tree with a latency-bandwidth model.40 min
  4. 4. Scaling and distributed trainingSize training memory per GPU, and choose between data, tensor, pipeline, and sharded data parallelism (and their 3D combination) for a model and cluster.45 min
  5. 5. ZeRO and FSDPShard optimizer state, gradients, and weights across data-parallel GPUs; compute per-GPU memory and communication for DDP and ZeRO stages 1 to 3, and pick a stage.40 min

A training run is limited by memory, then by communication. This module builds each technique that pushes those limits from scratch, and keeps one set of numbers throughout: a synthetic 7B-style model needs 16 bytes per parameter with mixed-precision AdamW, 108.63 GB in total, and every lesson shows a different way to make that fit.

LeverWhat it savesWhat it costs
Mixed precision (bf16 / fp16)half the weight and activation bytes, faster matmulsrange or precision limits; fp16 needs loss scaling
Gradient clippingruns that would diverge on one bad batchnothing, unless it clips every step
Gradient checkpointingmost activation memoryabout 33% more compute per step
Data parallelismwall-clock timeone gradient all-reduce per step; no memory saving
Tensor / pipeline parallelismweight memory per GPUper-layer communication / pipeline bubble
ZeRO / FSDPduplicate optimizer state, gradients, weightsup to 1.5 times DDP's communication (stage 3)
#LessonYou will be able to
1Gradient clipping and mixed precisionclip by global norm, choose bf16 or fp16, and run and debug a loss scaler
2Gradient checkpointingsize activation memory and trade it for recompute
3Collective operations from scratchbuild ring all-reduce and cost any collective
4Scaling and distributed trainingsize training memory and combine data, tensor, and pipeline parallelism
5ZeRO and FSDPcompute per-GPU memory and communication for DDP and ZeRO stages 1 to 3

Interactive lab: Data parallelism and ZeRO memory

Next moduleModule 28: Prompting and context engineering