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

0/12

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

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.

  1. 1Shard the corpus with DistributedSampler, proving disjointness and union on every rank under both padding policies; call set_epoch each epoch and show epoch resume reproduces the interrupted order.
  2. 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.
  3. 3Hold the global batch fixed while accumulating over micro-steps with no_sync on non-final steps; prove equivalence with the oracle, show the mis-scoped variant still syncs, and check the loss-scaling rule.
  4. 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.
  5. 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.
  6. 6Reduce rank shard losses and counts to one global metric with the correct denominator; reduce BatchNorm sums and counts by hand on CPU, where SyncBatchNorm rejects training input, and on your GPU convert with convert_sync_batchnorm before 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
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_parameters and its benchmarking problem with your own implementation. tests/test_ddp.py runs 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.py and the DataParallelBucket path beside train.py, and rebuild bucketed overlap with an equality test against one process. Read DataParallelNaive as a trap: its register_post_accumulate_grad_hook hook 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_naive and step6_data_parallel_bucket with 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 says optimizer.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_sync and 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.py and ddp_overlap.py; they refuse one-rank runs.

  • PyTorch SyncBatchNorm APIPyTorch

    Use convert_sync_batchnorm to convert BatchNorm layers before wrapping with DDP, and read the training-only sync plus single-GPU-per-process limits.