Unit 6 of 12 · about 5 hours · implement, measure
Bucket size, launch count, autograd hooks and compute-communication overlap
Bucket size trades launch overhead against exposed communication. The default is a starting point, not an optimum.
You'll be able to
- Derive bucket count, launch count and per-step collective bytes from
bucket_cap_mband the parameter count. - Implement bucketed overlap on the Picotron bucket path with an equality test against one process.
- Explain when smaller buckets help overlap and when launch overhead wins, citing the paper's middle-range result.
Covers
Read
In this order, only the parts listed
0 of 4 done
- Bucketed overlap implementationPicotron - Data Parallelism
BucketManager._initialize_buckets: params grouped bybucket_sizeelements with per-param views intograd_data;Bucket.sync_gradient: divide by group size then asyncall_reduce;mark_param_as_readylaunches when the bucket fills;waitblocks in_post_backward - DataParallelBucket wrapperPicotron - Data Parallelism
Class
DataParallelBucket:bucket_sizefrombucket_cap_mbwith 4 bytes per fp32 grad; grad-accumulator hooks accumulate intomain_grad;no_syncskips marking;_post_backwardwaits then copiesmain_gradtoparam.grad - Bucket-size sweepPyTorch Distributed: Experiences on Accelerating Data Parallel Training
arXiv:2006.15704v1, Section 5.2: bucket-size sweep with 10 to 25MB best on ResNet50 with NCCL, 50MB best on BERT with NCCL and 5MB best with Gloo, on 16 GPUs; extremes lose to launch overhead or late starts
- Bucket and overlap trade-offsAI Systems Performance Engineering - Chapter 4 Overlap and DDP Strategies
Chapter 4: Overlapping Communication and Computation (Pipelining), Reducing Communication Frequency and Volume, and Achieving Maximal Overlap in Practice; default 25MB buckets, large buckets use bandwidth but delay first launch, small buckets start early but add overhead
Focus on
- Bucket count follows the cap and parameter boundaries. On PyTorch 2.14.1 with 2
glooranks and eight 6.25 MiB fp32 weights (50 MiB),bucket_cap_mb=25gave 2 all-reduces per step and the default cap gave 3, because the default keeps the first rebuilt bucket small. The first iteration used one 50 MiB bucket in both. Total bytes stay identical; only launch count and timing change. - Picotron accumulates each ready grad into its
main_gradbucket view, fires async all-reduce per full bucket during backward, and copies back toparam.gradafter the wait. - The paper sweep peaks in the middle: 10 to 25MB best on ResNet50 with NCCL, 50MB best on BERT with NCCL and 5MB best with Gloo, on 16 GPUs. Tiny buckets drown in launch overhead; giant buckets start late and barely overlap.
- One giant bucket means one end-of-backward all-reduce with almost no overlap. Treat any larger-is-sooner claim as workload-specific until your timeline says otherwise.
Common mistakes · 3
- Reading fewer launches as fewer bytes. Bytes are fixed by the parameter count and rank count; bucketing only regroups them.
- Expecting overlap from a single giant bucket. With one bucket the all-reduce waits for the last grad.
- Quoting CPU gloo timings as NCCL evidence. Order and equality transfer; timings do not.
Try it yourself
Closed-book, before checking anything
Quiz yourself
Answer first, then mark it. Missed ones go to Review.
0 got · 0 missed
1.50 MiB of fp32 grads in eight equal weights with
bucket_cap_mb=25. Buckets and launches per step?Answer2 buckets and 2 all-reduces from the second iteration on; the first used one bucket. The bytes match one 50 MiB all-reduce; the timing differs. The default cap gives 3, since its first rebuilt bucket is small.
2.Why can smaller buckets hurt?Answer
Per-launch latency and overhead dominate, and fragmentation grows; the middle range wins.
3.What does
_post_backwarddo and when does it run?AnswerQueued once per backward; waits for all bucket handles, then copies
main_gradintoparam.gradbefore the optimizer step.4.A source says raising the cap launches sooner. Right?Answer
Not in general. Larger buckets fill later; they move bytes more efficiently but start later.
Practice
- CS336 Assignment 2:
minimal_ddp_flat_benchmarkingSection 5.3.1: single flattened all-reduce through
torch._utils._flatten_dense_tensors; compare with the per-tensor version at 1 node by 2 GPUs on the xl model; report time per iter plus comm share plus 1 to 2 sentences - CS336 Assignment 2:
naive_ddp_benchmarkingSection 5.2: per-param all-reduce timing on the xl model at 1 node by 2 GPUs; total step time plus gradient-communication share
- CS336 Assignment 2:
ddp_overlap_individual_parameters_benchmarkingSection 5.3.2: overlapped versus flat versus per-tensor timings plus Nsight screenshots proving overlap
Needs 2 GPUs with NCCL plus Nsight. On CPU or one GPU, run the same three as labeled timing examples only; they are not interconnect evidence.
You're done when
Your bucketed run matches the oracle, and you can predict launch count from the cap and explain a measured crossover.
Only when you can do this without notes.
Leads to
Notes
Resources · 3 for this unit, 8 more in the section
- Picotron - Data ParallelismHugging Face · required
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. - PyTorch Distributed: Experiences on Accelerating Data Parallel TrainingLi et al. (VLDB 2020) · support
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. - 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.pyandddp_overlap.py; they refuse one-rank runs.
Also in this 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_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 Tutorial - Steps 5 and 6 and Part 3 VideoHugging Face · support
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 · 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 saysoptimizer.step()synchronizes gradients; DDP averages them during backward, so correct that line in your notes. - 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. - 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_batchnormto convert BatchNorm layers before wrapping with DDP, and read the training-only sync plus single-GPU-per-process limits.