Week 09 Companion - Distributed Training, All-Reduce Cost, and NCCL Support
<- Companion index · Master Plan · cert plan · build project
Prerequisite Checklist
- You can explain data parallel training: each GPU gets different data, then gradients are synchronized.
- You know what an all-reduce does.
- You can distinguish process, rank, local rank, world size, and process group.
- You can read basic
torch.distributedcode. - You have the cloud multi-GPU setup plan open before Monday.
Mini Lesson
DDP works because every worker starts from the same weights, computes gradients on different mini-batches, averages gradients, and applies the same optimizer step. The synchronization primitive is all-reduce.
Ring all-reduce has two phases:
- reduce-scatter: split and reduce chunks around the ring;
- all-gather: circulate reduced chunks so every rank has the full result.
Math Insight
For tensor size S bytes and N GPUs, ring all-reduce moves roughly this much data per rank:
bytes_per_rank ~= 2 * (N - 1) / N * S
Latency also matters because the ring has 2 * (N - 1) communication steps. This explains why small tensors can be latency-bound while large gradient buckets are bandwidth-bound.
Scaling efficiency:
efficiency = single_gpu_time / (num_gpus * multi_gpu_time)
Playbook Bridge
Read the Week 9 Ultra-Scale Playbook bridge. Use the playbook to place your manual DDP work in the larger ladder: replicated data parallelism first, DDP overlap second, then ZeRO/FSDP sharding when replicated optimizer state becomes the memory wall.
Programming Primer
RANKis the global process index;LOCAL_RANKselects the GPU on the node.- NCCL is the GPU collective backend;
NCCL_DEBUG=INFOis your first visibility tool. - DDP overlaps communication with backward using gradient buckets and hooks.
- FSDP shards parameters/gradients/optimizer state to reduce memory.
25-Minute Gate
- Explain all-reduce to a non-specialist in three sentences.
- For
N=2and a 1 GB gradient tensor, estimate ring all-reduce bytes per rank. - Define rank, local rank, and world size.
- Confirm the cloud GPU budget and teardown steps before launching anything.