Build a distributed training stack on CPU
Build distributed training from the wire up: ring collectives checked against gloo, DDP, ZeRO-1 sharding, pipeline bubble analysis and atomic sharded checkpoints, composed into a 4-rank GPT run that resumes exactly.
Build it step by step
- 1Collective Ops From ScratchPhase 19: Capstone projects
- 2Data Parallel DDP From ScratchPhase 19: Capstone projects
- 3ZeRO Optimizer State ShardingPhase 19: Capstone projects
- 4Pipeline Parallel and Bubble AnalysisPhase 19: Capstone projects
- 5Sharded Checkpoint and Atomic ResumePhase 19: Capstone projects
- 6End-to-End Distributed TrainingPhase 19: Capstone projects
What You'll Build
The core of a distributed training framework, written by hand and verified on CPU. Ring allreduce, broadcast, allgather and reduce_scatter run over a multiprocessing.Queue mesh and are checked against torch.distributed gloo. On top of them you build a DDP wrapper, ZeRO stage 1 optimizer-state sharding, a simulated GPipe pipeline with bubble measurement, and per-rank sharded checkpoints with an atomic manifest. The finished stack trains a tiny GPT on text you choose across 4 ranks, checkpoints at step 10, and resumes to the same final loss.
Requirements
- Collectives. Ring allreduce in two passes (reduce-scatter then allgather), tree broadcast, allgather and reduce_scatter over a queue mesh. Each one matches a gloo reference within float32 tolerance for world sizes 2 and 4, and a byte counter shows per-rank traffic of 2T(N-1)/N for allreduce.
- DDP. Broadcast parameters from rank 0 at construction, allreduce-sum then divide by world size after backward, the seed pattern from lesson 77 (shared seed for init, rank-offset seed for data), and a per-step comparison against a single-process reference showing equal loss and parameter checksums.
- ZeRO-1. Flatten parameters, reduce_scatter the flat gradient, run Adam on the local shard of the fp32 master and moments, and allgather updated parameters. Print a memory table comparing your measured optimizer bytes per rank with vanilla DDP and with the formula.
- Pipeline. Split a model into 4 stages, simulate the GPipe schedule, print a stage-by-microbatch Gantt chart, and compare measured bubble fraction with (N-1)/(M+N-1) for at least three values of M.
- Sharded checkpoint. Per-rank shard files and a manifest with
world_size,step, per-shardsha256,param_shard_offset,param_shard_numelandschema_version, written with temp files, fsync and rename. Demonstrate that a wrong world size, a missing shard and a truncated shard each fail loudly on load. - End-to-end run. A 2-layer GPT (embed 32, 4 heads, sequence 16) trained for 20 steps on 4 ranks with DDP init plus ZeRO-1 steps, on a byte-level tokenized text of your choice instead of the synthetic corpus. Check the lesson 81 invariants: loss trends down within noise, parameter norm is identical across ranks (print the drift), per-rank optimizer memory equals 12P/N bytes, and the step-10 checkpoint reloads byte-equal ("RESUME VERIFIED"). Exit 0.
- Real resume. Restart from the step-10 checkpoint in fresh processes, continue to step 20, and show the final loss matches the uninterrupted run.
Constraints
- CPU only:
glooplustorch.multiprocessing. Four ranks run fine on a laptop with 4 or more cores; with fewer cores use 2 ranks and say so in the README. No GPU is needed. - Moving to GPUs means
nccl, device tensors andtorchrun; describe that change in the README, but it is not required or graded. - The model is tiny on purpose (a few thousand parameters). The goal is correct composition and exact verification, not a good language model.
Stretch Goals
- Implement the 1F1B schedule and show bounded activation memory with the same bubble.
- Add gradient bucketing and measure the speedup against one allreduce per parameter.
- Re-shard a checkpoint from 4 ranks to 2 by reading the manifest and re-slicing.
How to Submit
Public repo with dist/ (mesh, collectives, ddp, zero, pipeline, checkpoint), train_e2e.py, resume.py, tests/ and results/ (collective verification table, memory table, Gantt and bubble table, loss logs for the full and resumed runs, a sample manifest). The README must give run commands, your core count and world size, what text you trained on, the four invariants with your numbers, the three checkpoint failure demos, when you would choose ZeRO-1 vs ZeRO-3 vs pipeline, and the hardest bug you hit (for example a deadlock or a seed mismatch).
How It's Reviewed
Professor Katalock reads your repository and the evidence you paste, and scores each criterion out of 100. You pass with a weighted total of 70 or more and no criterion below 40. A copied or padded submission is flagged and fails.
Submit
Push your work to a public GitHub repository with a README that explains how to run it, then paste the evidence below. Up to 3 reviews a day, free.
- Output of the collectives verification run, including the byte counter
- Full output of `python train_e2e.py`
- Output of `python resume.py` with the final-loss comparison
- Output of the three checkpoint failure demos
- The pipeline Gantt chart and bubble table
- Output of `python -m pytest -q`
Reviews are done by AI against the rubric above. They check the evidence in your repository; they are not a substitute for a human code review, and a review can be wrong. If you think it is, improve the README so the evidence is unmistakable and resubmit.