KatalockAi AcademyBack to KatalockAi
Build track, required for the Phase 17 certificate

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.

about 24 h 6 guided steps Reviewed against a 7-point rubric
Submit your project Get coached by Professor Katalock

Build it step by step

  1. 1Collective Ops From ScratchPhase 19: Capstone projects
  2. 2Data Parallel DDP From ScratchPhase 19: Capstone projects
  3. 3ZeRO Optimizer State ShardingPhase 19: Capstone projects
  4. 4Pipeline Parallel and Bubble AnalysisPhase 19: Capstone projects
  5. 5Sharded Checkpoint and Atomic ResumePhase 19: Capstone projects
  6. 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. Sharded checkpoint. Per-rank shard files and a manifest with world_size, step, per-shard sha256, param_shard_offset, param_shard_numel and schema_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.
  6. 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.
  7. 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: gloo plus torch.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 and torchrun; 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.

CriterionWeightHow it's checked
End-to-end invariants25Pasted `python train_e2e.py` output shows the 20-step loss table, cross-rank norm drift near zero, optimizer memory equal to 12P/N, RESUME VERIFIED and exit 0; resume.py output reaches a final loss matching the uninterrupted run.
Collectives correctness15Verification table shows all four primitives matching gloo for N=2 and N=4, and the byte counter matches 2T(N-1)/N.
DDP and ZeRO-115Per-step DDP vs single-process comparison matches; ZeRO-1 code uses reduce_scatter and allgather on a flat buffer; memory table compares measured and formula values.
Checkpoint and failure modes15Manifest has the required fields; code writes temp, fsyncs and renames; pasted output shows world-size mismatch, missing shard and truncated shard each rejected.
Pipeline analysis5Gantt chart and a bubble table for three or more M values matching (N-1)/(M+N-1).
Code quality10Collectives are reused by DDP, ZeRO and the e2e loop instead of re-implemented; processes are cleaned up; tests run without hanging.
README and reasoning15README covers run commands, hardware and world size, the learner's own invariant numbers, failure demos, a reasoned choice between ZeRO stages and pipeline, and the hardest bug.

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.