5.3 Parallelism
1. Learn
Section titled “1. Learn”- Stanford CS336: Language Modeling from Scratchlectures 7 and 8 "Parallelism" (April 22 slides, April 24 trace)
- How to Scale Your Model (Google DeepMind)part 5 "Training" (data, tensor and pipeline parallelism)
2. Bridge
Section titled “2. Bridge”Data parallelism. Every GPU holds the whole model and processes a slice of the batch, then the gradients are averaged with an all-reduce. In the ring algorithm each GPU sends about twice the gradient size, however many GPUs there are. Frameworks group gradients into buckets and start each bucket’s all-reduce as soon as its gradients are ready, overlapping communication with the rest of the backward pass (Li et al. 2020, §3).
Sharding the state. Data parallelism stores the full 16 bytes per parameter (5.1) on every GPU. ZeRO splits the optimizer state, then the gradients, then the weights across the data-parallel GPUs. Each GPU updates only its slice, and weights are gathered just before they are needed (Rajbhandari et al. 2020). PyTorch’s version is FSDP.
Tensor parallelism splits each weight matrix across GPUs. In the MLP, the first matrix is split by columns: each GPU computes its own block of hidden units and applies the nonlinearity locally. The second is split by rows, so the partial outputs only need to be summed, one all-reduce per block in each direction (Shoeybi et al. 2019, §3). It needs fast links, so it stays within one machine.
Pipeline parallelism gives each GPU a block of layers and streams microbatches through them. GPUs idle while the pipeline fills and drains: the bubble shrinks as the number of microbatches grows (Huang et al. 2019; Narayanan et al. 2021). Large runs combine all of these (How to Scale Your Model, part 5).
3. Explore
Section titled “3. Explore”First, simulate it in NumPy, with each worker an entry in a list: the ring all-reduce, data parallelism, DDP’s buckets, ZeRO’s memory, tensor parallelism and the pipeline bubble.
stubs/m5_3_parallel.pyLoading starter file…
Prefer your own editor? Edit exercises/stubs/m5_3_parallel.py and run mlc check 5.3. The tests are identical; import the results on the progress page.
Then run real DDP. Open notebooks/5.3-ddp.ipynb on Kaggle with GPU T4 x2. Write a naive DDP wrapper (broadcast the initial weights, all-reduce every gradient after the backward pass), then a bucketed one. The bucketed version uses your bucketize and gradient hooks to launch asynchronous all-reduces during the backward pass, as in CS336 Assignment 2. The script runs one process per GPU with torchrun and checks that both train exactly like one process on the full batch. Without GPUs it runs two CPU processes over the gloo backend instead.
5. Check
Section titled “5. Check”- not yet: All tests pass (0/?)
- not yet: Checkpoint quiz ≥ 80%
Learner log: time spent and points of confusion
Every confusion you note becomes a fix before the module is marked stable. Export it from the progress page and attach it to an issue.