Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Module 4.2 — Training at Scale

Mode: hybrid Gate: concept check Est. effort: 8–12 focused hours

You have trained models on a single GPU. Frontier models train on thousands of GPUs for weeks, and even routine industry training spans several. This module is about what changes when one GPU is not enough: how training is spread across hardware, the tricks that make it fit and run fast, and the economics that decide what is worth doing. You will practice the single-GPU techniques directly and understand the multi-GPU ones clearly.

Why this matters

Scale is a defining feature of modern ML, and the techniques that make large training possible are now standard knowledge even for engineers who rarely touch a cluster. Understanding them tells you why training runs cost what they cost, why some models are feasible and others are not, and how to make your own training faster and cheaper. Two engineers can run the same job and one finishes in a third of the time and memory because they used mixed precision, gradient accumulation, and the right parallelism.

This is a concept-check module with hands-on parts you can actually run. The single-GPU efficiency techniques (mixed precision, gradient accumulation, gradient checkpointing) you will practice; the multi-GPU parallelism strategies you will understand conceptually and, if you have access to more than one GPU, try. The judgment is what transfers.

What you will be able to do

By the end of this module you will be able to:

Prerequisites

Curated path

  1. The single-GPU efficiency techniques: Hugging Face’s “Methods and tools for efficient training on a single GPU.” Mixed precision, gradient accumulation, gradient checkpointing, and optimizer choices, all of which you can run yourself. https://huggingface.co/docs/transformers/perf_train_gpu_one

  2. Distributed training, conceptually: the Hugging Face Ultra-Scale Playbook. The current, authoritative explanation of how LLMs are trained across GPU clusters, built from thousands of real experiments. Read it for the concepts (the parallelism strategies and memory tricks), not to reproduce it. https://huggingface.co/spaces/nanotron/ultrascale-playbook

  3. Hugging Face accelerate. The practical tool that takes a normal PyTorch training loop and makes it run on one GPU, many GPUs, or multiple machines with minimal changes. Read the quickstart and adapt one of your earlier training loops. https://huggingface.co/docs/accelerate

  4. Chip Huyen, Designing Machine Learning Systems, the model-development and training sections, for the systems and cost framing of training at scale. https://github.com/chiphuyen/dmls-book

Deliberately skip for now: writing custom CUDA kernels and the deepest internals of specific parallelism libraries (Megatron, DeepSpeed) unless you specialize. Understand the strategies and practice the single-GPU efficiency tools.

Background: the ideas in words

Why scale is hard. A model and its training state (the weights, their gradients, and the optimizer’s per-parameter state) must fit in GPU memory, and the computation must finish in reasonable time. Large models break both limits, so you reduce memory per GPU and spread work across GPUs.

Single-GPU efficiency. Mixed precision stores and computes in 16-bit where safe, roughly halving memory and speeding up math, while keeping a 32-bit master copy for stability. Gradient accumulation simulates a large batch by summing gradients over several small batches before updating, so you get large-batch behavior without large-batch memory. Gradient checkpointing trades compute for memory by not storing all intermediate activations, recomputing them during the backward pass instead. These three let you train substantially larger models on the same hardware.

Parallelism across GPUs. Data parallelism puts a full copy of the model on each GPU, feeds each a different slice of the batch, and averages the gradients; it is the most common and scales throughput. When the model itself is too big for one GPU, tensor parallelism splits individual layers (their weight matrices) across GPUs, and pipeline parallelism puts different layers on different GPUs and streams data through like an assembly line. Real large-scale training combines all three.

The economics. Training cost is roughly GPUs times time times price, and the scaling laws from Module 3.1 let you forecast the benefit. This is why efficiency matters so much: a technique that cuts memory by 40% can be the difference between a run that fits on affordable hardware and one that does not, and a speedup is a direct cost saving on a run that may cost real money.

Knowledge check

  1. What three things must fit in GPU memory during training, and which often dominates?

  2. Explain mixed precision and why it both saves memory and speeds up training.

  3. What does gradient accumulation simulate, and why is it useful on a small GPU?

  4. Contrast data, tensor, and pipeline parallelism, and say when each is needed.

  5. What does gradient checkpointing trade for what?

  6. Why does a 40% memory reduction matter beyond convenience?

Project

A hands-on efficiency study plus a written scaling analysis:

Definition of done: the before-and-after efficiency measurements, an accelerate-ready training loop, and the written scaling analysis.

The workshop: ship it

Build this in its own repository, modelwright-scaling-study, using the project habits from Module 0.2.

  1. Set up the project:

mkdir modelwright-scaling-study && cd modelwright-scaling-study
uv init && uv add torch torchvision accelerate matplotlib && mkdir src
  1. Write a configurable training script in src/ where each efficiency technique is a flag, so the comparison is clean. Run it on a free GPU notebook with the code committed here.

  2. Commit at checkpoints: “Baseline measurements”, then “Efficiency techniques compared”, then “accelerate-ready loop”.

  3. Add a README with your memory/speed table and the scaling analysis.

  4. Ship it:

gh repo create modelwright-scaling-study --public --source=. --push

(No gh? Create an empty public repo, then git remote add origin <url> and git push -u origin main.)

Done when: modelwright-scaling-study is on GitHub with measured efficiency gains and a clear written analysis of how the job would scale across GPUs.

Going deeper (optional)

Canonical references