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_mb and 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

Bucket size, launch count and exposed communicationAutograd hooks and compute-communication overlap
1

Read

In this order, only the parts listed

0 of 4 done

  1. Bucketed overlap implementationPicotron - Data Parallelism

    BucketManager._initialize_buckets: params grouped by bucket_size elements with per-param views into grad_data; Bucket.sync_gradient: divide by group size then async all_reduce; mark_param_as_ready launches when the bucket fills; wait blocks in _post_backward

  2. DataParallelBucket wrapperPicotron - Data Parallelism

    Class DataParallelBucket: bucket_size from bucket_cap_mb with 4 bytes per fp32 grad; grad-accumulator hooks accumulate into main_grad; no_sync skips marking; _post_backward waits then copies main_grad to param.grad

  3. 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

  4. 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

2

Focus on

  • Bucket count follows the cap and parameter boundaries. On PyTorch 2.14.1 with 2 gloo ranks and eight 6.25 MiB fp32 weights (50 MiB), bucket_cap_mb=25 gave 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_grad bucket view, fires async all-reduce per full bucket during backward, and copies back to param.grad after 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.
3

Try it yourself

Closed-book, before checking anything

On a 4-param toy with a cap covering exactly one param versus all params, count the launches per step (4 versus 1) and show identical averaged grads; state the launch-count rule.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.50 MiB of fp32 grads in eight equal weights with bucket_cap_mb=25. Buckets and launches per step?Answer

    2 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. 2.Why can smaller buckets hurt?Answer

    Per-launch latency and overhead dominate, and fragmentation grows; the middle range wins.

  3. 3.What does _post_backward do and when does it run?Answer

    Queued once per backward; waits for all bucket handles, then copies main_grad into param.grad before the optimizer step.

  4. 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.

5

Practice

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.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.

  • 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.

  • 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

  • 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.

  • 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.

  • 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.

  • 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_batchnorm to convert BatchNorm layers before wrapping with DDP, and read the training-only sync plus single-GPU-per-process limits.