Data Parallelism and Overlap
Data parallelism is the cleanest place to prove distributed optimization equivalence. It also exposes the central performance pattern of making communication begin as gradients become ready.
Section 3 of 10 · 12 units · about 47 hours
By the end you can Match one-process updates with two-process DDP under fixed global batch, prove sampler disjointness, show a gradient-bucket timeline, and explain a measured or simulated case where overlap does and does not help.
Units
- Replicated state, disjoint data ownership and DistributedSampler invariants3h
- Loss reduction, update equivalence and the single-process oracle4h
- Global batch across workers and accumulation, and `no_sync`4h
- Minimal data parallelism with an explicit all-reduce4h
- DDP construction, parameter registration and reducer buckets4h
- Bucket size, launch count, autograd hooks and compute-communication overlap5h
- Unused parameters, static graphs and divergent control flow4h
- Rank-consistent loss and metrics, and distributed batch normalization3h
- DDP communication hooks, compression contracts and a PowerSGD experiment4h
- Stragglers, weak and strong scaling, parallel efficiency and hierarchical DP5h
- Synchronized timing under fixed work and gradient-ready and bucket timelines4h
- Failure cleanup and rank-attributed logs in data-parallel training3h
Build it
Mini project · about 12 to 16 hours
Data-parallel training with overlapped buckets
Build data-parallel training in parallel/ on the comm/ layer: disjoint sharding, explicit averaging, bucketed overlap and honest timelines. This is the first distributed optimizer step in trainlab, and its oracle discipline carries into sharded and model-parallel sections.
- 1Shard the corpus with
DistributedSampler, proving disjointness and union on every rank under both padding policies; callset_epocheach epoch and show epoch resume reproduces the interrupted order. - 2Fix a single-process oracle for a small model, then match it step for step with hand-rolled broadcast, shard, all-reduce average and a per-rank update; pass the CS336 DDP tests for plain and tied-weight models.
- 3Hold the global batch fixed while accumulating over micro-steps with
no_syncon non-final steps; prove equivalence with the oracle, show the mis-scoped variant still syncs, and check the loss-scaling rule. - 4Group gradients into buckets that all-reduce asynchronously during backward and match the oracle; compare launch counts across bucket caps, and bound a compressed hook plus a small PowerSGD experiment against vanilla averaging with accuracy evidence.
- 5Record per-rank gradient-ready and bucket-collective intervals under fixed global work and label hidden against exposed communication; derive scaling efficiency from fixed-work runs and localize an injected slow rank, keeping GPU timing claims to runs with two or more GPUs.
- 6Reduce rank shard losses and counts to one global metric with the correct denominator; reduce BatchNorm sums and counts by hand on CPU, where
SyncBatchNormrejects training input, and on your GPU convert withconvert_sync_batchnormbefore wrapping, and attribute a rank crash to its first cause from rank-tagged logs with bounded teardown.
What you hand in
- Disjoint sharding with sampler tests and the single-process oracle.
- Explicit, bucketed and overlapped data-parallel steps with equivalence and timeline evidence.
- Compression bounds, scaling-efficiency numbers and the crash-attribution log.
How to check it
- Self-grade with the rubric below
- CS336 Assignment 2 DDP tests
Pass both model variants on CPU with the oracle comparison after every step.
- TensorTonic: Synchronize Data-Parallel Gradients
Pass the public averaging cases before wiring the collective version.
- PyTorch DDP communication hooks PowerSGD experiment
Run the register-and-compare example on CPU; keep error and accuracy evidence.
How it's graded
Shard ownership
Pass: Shards are proved disjoint with union coverage under both policies, and epoch resume reproduces the interrupted order.
Great: A seeded overlap is caught by the tests and padding tokens are excluded from the reported batch.
Update equivalence
Pass: Explicit, accumulated and bucketed steps each match the oracle within a stated tolerance, including tied weights.
Great: The suite passes repeatedly and the tolerance is derived from a rounding study, not guessed.
Overlap honesty
Pass: Timelines label hidden against exposed intervals under fixed work, and launch counts follow the cap.
Great: A bucket-size crossover is measured with the losing side kept, and compression keeps its accuracy bound.
Failure attribution
Pass: Metrics use the global denominator, and the crash run names its first cause within a bounded time.
Great: A divergent-control hang is drilled and distinguished from a dead rank.
Resources
- CS336 Assignment 2 (Spring 2026) - Section 5 Distributed Data Parallel TrainingStanford University
Complete
naive_ddp,naive_ddp_benchmarking,minimal_ddp_flat_benchmarking,ddp_overlap_individual_parametersand its benchmarking problem with your own implementation.tests/test_ddp.pyruns on CPU with Gloo; keep the benchmark method and written derivations even when multiple GPUs are unavailable. This year's handout has no bucketed problem: build buckets from Picotron. - Picotron - Data ParallelismHugging Face
Read
data_parallel/bucket.pyand theDataParallelBucketpath besidetrain.py, and rebuild bucketed overlap with an equality test against one process. ReadDataParallelNaiveas a trap: itsregister_post_accumulate_grad_hookhook receives the parameter, so it averages parameters and leaves gradients local; show the unequal gradients on two CPU ranks. - Ultra-Scale Playbook - Data ParallelismHugging Face
Read Data Parallelism through Revisiting global batch size and Our journey up to now (overlap, bucketing, accumulation and the global batch equation). Derive replicated-state memory, gradient communication and batch constraints for your tiny model before measuring it; ZeRO belongs to DT-4.
- Picotron Tutorial - Steps 5 and 6 and Part 3 VideoHugging Face
Follow
step5_data_parallel_naiveandstep6_data_parallel_bucketwith the Part 3 video. Step 5 carries the same parameter-hook trap as Picotron; use step 6 for the equivalence gate. - Distributed Training Guide - Chapter 2 DDPLambda Labs
Apply Chapter 2 to a tiny causal-LM loop:
torchrun, rank-aware logs,DistributedSampler, rank-zero side effects and the ZeRO memory subsection, plus the gradient-accumulation and effective-batch related topics. Its README saysoptimizer.step()synchronizes gradients; DDP averages them during backward, so correct that line in your notes. - PyTorch DDP Tutorial, Design Note and Communication HooksPyTorch
Use the tutorial for setup,
DistributedSampler,no_sync, unused parameters and teardown, the design note at https://docs.pytorch.org/docs/2.14/notes/ddp.html for buckets and gradient-ready order, and https://docs.pytorch.org/docs/2.14/ddp_comm_hooks.html for communication hooks. Consult them after the from-scratch path so wrappers do not replace the mechanism model. - PyTorch Distributed: Experiences on Accelerating Data Parallel TrainingLi et al. (VLDB 2020)
Read the design sections on gradient bucketing, overlap with backward,
no_syncand unused-parameter detection. Use them to explain why buckets follow reverse registration order. - Deep Learning at Scale - Chapter 7 Data ParallelismSuneeta Mall (O'Reilly)
Read Data Partitioning, Sampling Strategies, DDP and the data-pipeline sections, and use the small DDP exercises as extra practice. Its FSDP and ZeRO material predates FSDP2.
- TensorTonic - Synchronize Data-Parallel GradientsTensorTonic
Solve Synchronize Data-Parallel Gradients before the CS336 DDP tests.
- AI Systems Performance Engineering - Chapter 4 Overlap and DDP StrategiesChris Fregly (O'Reilly)
Read Overlapping Communication and Computation, Achieving Maximal Overlap in Practice and Distributed Data Parallel Strategies in Chapter 4, and the Chapter 13 streams section on overlapping communication. With two or more GPUs, compare
code/ch04/ddp_no_overlap.pyandddp_overlap.py; they refuse one-rank runs. - PyTorch SyncBatchNorm APIPyTorch
Use
convert_sync_batchnormto convert BatchNorm layers before wrapping with DDP, and read the training-only sync plus single-GPU-per-process limits.