Unit 11 of 12 · about 4 hours · measure

Synchronized timing under fixed work and gradient-ready and bucket timelines

Unsynchronized, unwarmmed timings are fiction on async runtimes. The bucket timeline is the only honest picture of overlap.

You'll be able to

  • Apply warmup, synchronization and fixed global work to every timing.
  • Instrument gradient-ready and bucket all-reduce start and end per rank.
  • Read a timeline to say whether communication hid behind compute or stayed exposed.

Covers

Warmup, fixed global work and synchronized timingGradient-ready and bucket timeline instrumentation
1

Read

In this order, only the parts listed

0 of 3 done

  1. Benchmark hygiene and Nsight overlap proofCS336 Assignment 2 (Spring 2026) - Section 5 Distributed Data Parallel Training

    Section 5.1.1 Best Practices for Benchmarking Distributed Applications (p. 32): warmup, synchronize, same-machine comparison, cross-rank aggregation; Section 5.3.2 benchmarking (p. 36): two Nsight screenshots proving overlapped versus sequential backward plus communication

  2. Synchronized per-phase timersDistributed Training Guide - Chapter 2 DDP

    timers dict over data, forward, backward and update (lines 127, 140 to 159); LocalTimer synchronizes the device before and after each region and reports average ms (lines 283 to 309)

  3. Streams, events and overlap readingAI Systems Performance Engineering - Chapter 4 Overlap and DDP Strategies

    Chapter 13: Concurrency with CUDA Streams and Overlapping Communication and Computation; Stream Synchronization with Events (with two or more GPUs, read bucket all-reduces on the communication stream against backward compute)

2

Focus on

  • Warm up (5 iters per CS336), synchronize both sides of every region, fix the global batch, aggregate across ranks, report mean plus spread. These are the rules from Streams, asynchronous copies and honest timing and Profiling training phases and verifying optimizations.
  • Stamp grad-ready plus all-reduce start and end per bucket per rank. Interleaved all-reduces during backward are hidden; the tail wait after backward is exposed.
  • One bucket gives one end-of-backward all-reduce: fully exposed. The CS336 screenshots show the same contrast under Nsight.
  • CPU timelines prove ordering and the hidden-versus-exposed reading. GPU overlap claims need two or more GPUs.
Common mistakes · 3
  • Timing CUDA without synchronize. Async launches return at once; you time submission.
  • Timing the first step as steady state. Allocator prep plus DDP bucket rebuild make it slower; warmup excludes it.
  • Comparing timelines across different global batches. Fix work first; the scaling unit enforces it.
3

Try it yourself

Closed-book, before checking anything

On 2 CPU ranks, log per-bucket ready plus all-reduce start and end stamps around a 2-bucket backward on a step after the first, once DDP has rebuilt its buckets; print the interleave and compute the exposed tail as the time from the last grad-ready stamp to the end of the last all-reduce.
4

Quiz yourself

Answer first, then mark it. Missed ones go to Review.

0 got · 0 missed

  1. 1.Why synchronize before and after the timed region?Answer

    Launches are async: without sync you time submission, and earlier work bleeds into the region.

  2. 2.All-reduces sit entirely after backward. Reading?Answer

    Fully exposed, no overlap. Check the bucket count; one bucket explains it.

  3. 3.First step 3 times slower, rest flat. Bug?Answer

    Usually not: allocator prep, DDP's single all-parameter bucket on the first iteration and the bucket rebuild after it. Warmup exists for this.

  4. 4.CPU timeline interleaves perfectly. Claim GPU overlap?Answer

    No. Ordering logic transfers; timing does not across streams, NCCL and kernels.

You're done when

Your 2-rank timeline labels hidden and exposed intervals under fixed global work without notes.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 8 more in the section
  • CS336 Assignment 2 (Spring 2026) - Section 5 Distributed Data Parallel TrainingStanford University · primary

    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.

  • Distributed Training Guide - Chapter 2 DDPLambda Labs · support

    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.

  • AI Systems Performance Engineering - Chapter 4 Overlap and DDP StrategiesChris Fregly (O'Reilly) · support

    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.

Also in this section

  • Picotron - Data ParallelismHugging Face · required

    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.

  • Picotron Tutorial - Steps 5 and 6 and Part 3 VideoHugging Face · support

    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.

  • Ultra-Scale Playbook - Data ParallelismHugging Face · required

    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.

  • PyTorch DDP Tutorial, Design Note and Communication HooksPyTorch · support

    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) · support

    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) · support

    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 · support

    Solve Synchronize Data-Parallel Gradients before the CS336 DDP tests.

  • PyTorch SyncBatchNorm APIPyTorch · reference

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