Seyed Masoud Hosseini · Overview · Study log · Weekly summaries · Ideas · Search · Transcript · RSS feed
Deep Learning Systems · Lecture 16 of 25 · 46:37
Lecture 15: Training Large Models
Study guide
What this lecture covers
This lecture addresses two linked scaling problems for training deep networks: fitting a model's memory footprint onto a single GPU, and spreading training across multiple devices. It sits after the course's GPU programming material and treats GPU memory hierarchy as background already covered.
After watching, you should be able to explain why training costs more memory than inference, describe activation checkpointing and why it gives sublinear memory cost, and distinguish model-parallel from data-parallel training, including the allreduce and parameter-server abstractions used to implement data parallelism.
Key ideas
- GPU memory hierarchy: consumer GPUs commonly offer 8-10 GB of global memory while server cards like the A100 offer 40-80 GB, and model size is frequently bottlenecked by this global memory.
- Sources of memory consumption: weights, optimizer state (e.g. momentum), intermediate activation values, and input data all consume GPU memory during training.
- Inference memory reuse: for inference-only feed-forward networks, activations can be cycled through two ping-pong buffers, so memory cost stays constant regardless of network depth.
- Why training costs more: backward-pass gradients depend on forward-pass activations, so those activations can't be freed early, giving naive training an
O(n)memory cost in the number of layers. - Activation checkpointing: store only a subset of activations ("checkpoints") during the forward pass, discard the rest, and recompute short segments on demand during the backward pass; checkpointing every
sqrt(n)layers yieldsO(sqrt(n))memory at roughly 25% extra compute. - Model parallelism: partition the computational graph itself across workers, inserting send/receive pairs at the boundaries; pipeline parallelism with micro-batches keeps workers busy concurrently.
- Data parallelism: replicate the full model on every worker, split a mini-batch across workers, compute gradients independently, then combine them.
- Allreduce and parameter server: allreduce sums a value across all workers and returns the sum to everyone; a parameter server instead collects gradients centrally, applies updates, and can tolerate slow or dead workers by proceeding with whichever gradients have arrived.
Walkthrough
GPU memory hierarchy and sources of memory consumption (1:49)
The lecture recaps GPU memory hierarchy, noting the gap between consumer cards (8-10 GB) and server cards (40-80 GB), and lists the sources of memory use during training: model weights, optimizer state, intermediate activations, and input data.
Memory-saving techniques for inference vs. training (6:55)
For inference-only networks, activations can be recycled through two alternating buffers regardless of network depth, since each layer's output is only needed by the next layer. Training breaks this trick because backward-pass gradient computation for each layer needs that layer's forward-pass activation, so a naive implementation must keep O(n) activations alive for an n-layer network.
Activation checkpointing (14:57)
The lecture introduces checkpointing: store only selected ("colored") activations during the forward pass and discard the rest, then during the backward pass recompute a short forward segment to refill a deleted activation just before it's needed for gradient computation. Checkpointing every k layers costs O(n/k) for the checkpoints plus O(k) for each recomputation segment; choosing k = sqrt(n) gives O(sqrt(n)) total memory, at roughly 25% additional compute since only one extra forward pass is required overall.
Model-parallel and pipeline-parallel training (26:56)
When a single model doesn't fit on one device, the computational graph can be partitioned across workers, with send/receive operations inserted at partition boundaries. Because a single micro-batch leaves most workers idle, pipeline parallelism runs multiple micro-batches concurrently so different workers process different micro-batches at the same time, keeping the pipeline busy.
Data-parallel training via allreduce and parameter server (32:32)
Data parallelism replicates the model on every worker and splits a mini-batch across them. The allreduce abstraction sums each worker's local gradient array element-wise across all workers and returns the total to every worker, requiring no change to the model code itself. The parameter-server alternative sends gradients to a central server that sums and applies updates, which allows it to proceed without waiting for every worker and simplifies recovery when a worker restarts.
Overlapping communication with computation (41:05)
Because gradients for later layers become available before earlier-layer gradients finish computing, their communication (via allreduce or parameter server) can be overlapped with ongoing backward computation, and prioritized based on when each layer's updated weight is next needed. The lecture closes by summarizing model versus data parallelism and pointing to further techniques such as Microsoft's ZeRO for advanced memory sharing.
Before you watch
- Review the course's GPU programming lecture, particularly the GPU memory hierarchy and shared/global memory distinction.
- Be familiar with how automatic differentiation builds a computational graph and computes gradients via backward passes.
Check your understanding
- Why can inference reuse just two buffers regardless of network depth, while naive training cannot?
- How does choosing a checkpoint interval of
k = sqrt(n)lead toO(sqrt(n))memory cost, and what is the compute trade-off? - What is the key structural difference between allreduce-based and parameter-server-based data parallel training?
- Why does overlapping communication with computation matter for data-parallel training speed?
Vocabulary
- memory footprint (noun)
- The total amount of memory a program or model uses.
Training has a much larger memory footprint than inference. - scaling (noun)
- Making a system work well as it grows much larger.
This lecture covers scaling training across many devices. - global memory (noun)
- The main, larger memory space on a GPU, as opposed to fast on-chip memory.
Model size is often limited by global memory. - optimizer state (noun)
- Extra values an optimizer keeps between steps, such as momentum.
Optimizer state adds to a model's memory use. - ping-pong buffer (noun)
- Two memory buffers used alternately so one can be reused while the other is active.
Inference can reuse two ping-pong buffers regardless of depth. - sublinear (adjective)
- Growing more slowly than the size of the input.
Checkpointing gives a sublinear memory cost. - activation checkpointing (noun)
- A technique that saves only some layer outputs and recomputes the rest when needed.
Activation checkpointing trades extra compute for less memory. - recompute (verb)
- To calculate a value again instead of keeping it stored.
The backward pass may recompute a deleted activation. - on demand (phrase)
- Only when it is actually needed, not in advance.
Segments are recomputed on demand during backpropagation. - model parallelism (noun)
- Splitting one model's computation across multiple devices.
Model parallelism partitions the graph across workers. - partition (verb)
- To divide something into separate parts.
The computational graph is partitioned across devices. - pipeline parallelism (noun)
- Running different stages of computation on different devices at the same time.
Pipeline parallelism uses micro-batches to keep workers busy. - micro-batch (noun)
- A very small portion of a mini-batch, processed as one pipeline stage.
Multiple micro-batches keep the pipeline workers occupied. - data parallelism (noun)
- Copying the same model onto multiple devices and splitting the data between them.
Data parallelism replicates the model on every worker. - replicate (verb)
- To make an identical copy of something.
Data parallelism replicates the full model on each device. - allreduce (noun)
- An operation that combines values from all workers and shares the total result back to everyone.
Allreduce sums gradients across all workers. - parameter server (noun)
- A central machine that collects updates from workers and applies them.
A parameter server can tolerate a slow worker. - tolerate (verb)
- To keep working correctly despite a problem.
The parameter server can tolerate dead workers. - overlap (verb)
- To let two processes happen at the same time instead of one after another.
Communication can overlap with backward computation. - prioritize (verb)
- To deal with something before other things because it matters more urgently.
Gradient communication is prioritized by when it's needed next.
Chapters
- 0:00 Intro
- 0:43 Elements of machine learning systems
- 1:49 Recap: GPU memory hierarchy
- 4:40 Sources of memory consumption
- 6:55 Techniques for memory saving inference only
- 10:17 Activation memory cost for training
- 14:59 Checkpointing techniques in AD
- 20:12 Sublinear memory cost
- 26:09 Parallel training problem
- 26:55 Model parallel training
- 29:43 Breaking up the computation for model parallelism
- 33:55 Allreduce abstraction
- 36:07 Data parallel training via allreduce
- 38:09 Parameter server abstraction
- 38:42 Data parallel training via parameter server
- 41:17 Communication computation overlap
- 44:47 Parallelization summary
- 45:46 Advanced parallelization methods
From the YouTube description
This lecture studies techniques to reduce memory consumption and scale up model training.
← Lecture 14: Implementing Convolutions · Lecture 16: Generative Adversarial Networks →
