Unit 9 of 13 · about 4 hours · derive, measure

Per-rank bytes, critical paths, message size and effective bandwidth

Vendor plots quote bus bandwidth while timers measure time. The correction factor between them decides whether a link is saturated or the algorithm is wasteful.

You'll be able to

  • Derive per-rank wire bytes and the critical path for all five core collectives.
  • Convert a measured time into algorithm bandwidth and bus bandwidth with the right correction factor.
  • Run a message-size sweep on CPU and separate the latency-flat sizes from the bandwidth-linear ones.

Covers

Per-rank byte volume and critical-path derivationMessage-size effects, contention and effective bandwidth
1

Read

In this order, only the parts listed

0 of 3 done

  1. Algorithm bandwidth versus bus bandwidthnccl-tests and its performance notes

    Bandwidth with Algorithm bandwidth as S over t, Bus bandwidth with the per-collective correction table, and the AllReduce derivation

  2. Benchmarking formulas and warmup disciplineCS336 Spring 2025 - Lecture 8 Parallelism (executable lecture)

    Benchmarking with all_reduce and reduce_scatter: the sent-bytes lines with the factor of 2 for all-reduce only (the lecture warms up once), plus Section 5.1.1 of the assignment handout for 5 warmups and torch.cuda.synchronize

  3. NCCL reality gap across message sizesMachine Learning Systems Volume II - Collective Communication

    Mapping the Terrain with Theory vs. practice: The NCCL reality gap, including the small-message overhead ratios and the large-message agreement

2

Focus on

  • Per-rank wire bytes with ranks and payload : all-reduce , all-gather and reduce-scatter each, broadcast and reduce through the root bottleneck, all-to-all under contention.
  • Algorithm bandwidth is . Bus bandwidth multiplies by the correction factor: for all-reduce, for all-gather, reduce-scatter and all-to-all, and 1 for broadcast and reduce.
  • Small sizes show flat time against the latency floor; large sizes show time linear in bytes. The knee between them sits near the crossover size of the fabric.
  • CPU gloo sweeps show the shape of that knee and validate the byte factors. They say nothing about GPU link speeds, so never compare a gloo GB/s number with an NVLink or InfiniBand figure.
Common mistakes · 3
  • Calling the TensorTonic algorithm_bytes a bus bandwidth. That problem counts ring wire bytes, while nccl-tests reserves algorithm bandwidth for S over t and applies the correction after.
  • Timing one shot without warmup or synchronization. First iterations pay setup cost and async calls return early, so both inflate bandwidth.
  • Comparing effective bandwidth across different rank counts without the correction. The factor removes the rank-count trend so the remainder reflects the hardware.
3

Try it yourself

Closed-book, before checking anything

On 4 gloo CPU processes, sweep all-reduce payloads from 4 KB to 16 MB with 5 warmups: plot time and bus bandwidth with the 1.5 correction factor, mark the flat and the linear regimes, and state the assumed crossover for comparison.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.Four ranks all-reduce 1024 bytes in 0.001 s. What are the modeled bytes per rank and the bandwidth?Answer

    Bytes per rank are . Bandwidth is bytes/s, which nccl-tests would call bus bandwidth.

  2. 2.Why does the lecture benchmark double the sent bytes for all-reduce but not for reduce-scatter?Answer

    Ring all-reduce performs both halves, reduce-scatter plus all-gather, while reduce-scatter performs only the reduction half. The factor of 2 counts the second pass.

  3. 3.A sweep shows flat time up to 64 KB and linear time above 4 MB. Which regime is which, and what does the flat part measure?Answer

    Flat is latency-bound and linear is bandwidth-bound. The flat part measures startup and software overhead, not link speed.

  4. 4.Your 4-process gloo sweep reports 2 GB/s bus bandwidth. The book quotes 50 GB/s InfiniBand. Is your link 25 times slower?Answer

    No comparison follows. The gloo number ran over loopback or TCP on CPU with different software overhead, so it cannot speak about the GPU fabric.

5

Practice

  • TensorTonic: Calculate Collective Effective Bandwidth

    All three public cases: the pass count of 2 for all-reduce and 1 otherwise, with modeled bytes A and bandwidth B

    Describe only what the cases check: the byte formula and the division by duration. Remember its algorithm_bytes name differs from the nccl-tests one.

  • CS336 Assignment 2: distributed_communication_single_node

    Section 5.1 with the Section 5.1.1 benchmarking practices (p. 32): sizes 1 MB, 10 MB, 100 MB and 1 GB on 2, 4 or 6 processes, with a plot or table plus 2 to 3 sentences

    Run the sweep on CPU gloo with 5 warmups. Each run must finish inside 5 minutes.

You're done when

Your byte factors match the correction table, the TensorTonic cases pass, and your sweep shows the flat-to-linear knee with warmup and synchronization in place.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 12 more in the section
  • Machine Learning Systems Volume II - Collective CommunicationML Systems Textbook · primary

    Read From Parallelism to Communication Patterns, Network Performance Modeling, Collective Operation Primitives, AllReduce Algorithms, Hierarchical Communication and Communication-Computation Overlap. Use its latency and bandwidth model to derive one communication budget, and return to The Distributed Training Step in https://mlsysbook.ai/vol2/distributed_training/distributed_training.html during DT-3.

  • CS336 Spring 2025 - Lecture 8 Parallelism (executable lecture)Stanford University · support

    Read lecture_08.py Part 1 (collective operations, torch.distributed, all-reduce and reduce-scatter benchmarks) and skim Part 2 (data, tensor and pipeline parallelism sketches). Run its CPU examples before the Playbook appendix.

  • nccl-tests and its performance notesNVIDIA · support

    With two or more GPUs, run all_reduce_perf over a message-size sweep and read doc/PERFORMANCE.md for algorithm bandwidth versus bus bandwidth. Without them, use the document to interpret published numbers.

Also in this section

  • How to Scale Your Model - Sharded Matrices and GPU CollectivesGoogle DeepMind · required

    Work the collective-cost problems in Part 3 (all-gather, reduce-scatter, all-reduce and all-to-all volumes, latency versus bandwidth) before opening each answer, then read How Do Collectives Work on GPUs in Part 12 at https://jax-ml.github.io/scaling-book/gpus. The worked answers use TPU link constants; redo them with your own bandwidth and latency.

  • Ultra-Scale Playbook - A0: Parallel Programming Crash CourseHugging Face · required

    Read A0 from processes and ranks through point-to-point communication, broadcast, reduce, all-reduce, all-gather, reduce-scatter, the ring all-reduce and asynchronous operations. Reproduce every small torch.distributed example on Gloo and annotate tensor ownership before moving to higher parallelism.

  • Building a Distributed Training Framework from First PrinciplesUmar Jamil · required

    Watch only 04:32:59 for autograd and distributed mathematics, 05:04:19 for distributed graphs and DDP, 09:48:52 for collectives, and 10:49:41 for DeviceMesh, DDP and FSDP. Pause after each segment to reproduce the rank and tensor transitions with CPU torchrun; the nearly twenty-hour full video is not required.

  • Picotron - Process Groups and Communication FilesHugging Face · required

    Trace picotron/process_group_manager.py plus tp_communications.py, pp_communications.py and cp_communications.py. Draw every group, rank coordinate and tensor transfer for one 2 x 2 layout, then add a failing collective-order test in your own project.

  • Picotron Tutorial - Steps 1 to 3 and Part 1 VideoHugging Face · support

    Follow step2_process_group_manager and step3_dataloader with their diffs and the Part 1 video (model, process group manager and dataloader). Rebuild the rank grid yourself before reading the solution.

  • Machine Learning Engineering Open Book - Communication PatternsStas Bekman · required

    Read network/comms.md from point-to-point through ring all-reduce, then network/README.md and network/debug/README.md selectively. Derive bytes and steps before running anything; network/benchmarks/all_reduce_bench.py needs two or more GPUs and reports bus bandwidth.

  • Writing Distributed Applications with PyTorchPyTorch · required

    Work through process-group setup, point-to-point communication and the collective operations, then adapt the examples to test broadcast, all-reduce, all-gather, reduce-scatter and all-to-all on Gloo with several CPU processes. Check backend support in the 2.14 torch.distributed reference; Gloo all-to-all runs on CPU in 2.14.

  • CS336 Assignment 2 (Spring 2026) - Sections 5.1 and 8.1Stanford University · required

    Complete distributed_communication_single_node with the Section 5.1.1 benchmarking practices on as many processes as you have, then derive the ring all-gather, reduce-scatter and all-reduce costs in Section 8.1 and solve alternate_ring_all_reduce.

  • TensorTonic - Collective Simulation ProblemsTensorTonic · support

    Solve Simulate Distributed Collectives and Calculate Collective Effective Bandwidth. The bandwidth problem counts ring passes; reconcile it with your alpha-beta model and with bus bandwidth before comparing numbers.

  • AI Systems Performance Engineering - Chapter 4 Distributed Networking CommunicationChris Fregly (O'Reilly) · support

    Read NCCL for Distributed Multi-GPU Communication, Topology Awareness in NCCL, NCCL Communication Algorithms, NCCL Communicator Lifecycle and Environment Gotchas, and Profiling and Debugging NCCL. With two or more GPUs, run code/ch04/nccl_benchmark.py from the companion repository and label the exact topology.

  • PyTorch 2.14 `torch.distributed` referencePyTorch · reference

    Look up the backends table, init_process_group with timeout and device_id, new_group and new_subgroups, the Work and async_op contract, monitored_barrier, destroy_process_group and TORCH_DISTRIBUTED_DEBUG. Use it for API lookup beside the tutorial first pass.

  • PyTorch 2.14 torchrun (elastic launch) referencePyTorch · reference

    Read Single-node multi-worker through the elastic membership rows for RANK, WORLD_SIZE and LOCAL_RANK, plus flags --standalone, --nnodes, --nproc-per-node, --rdzv-backend and --rdzv-endpoint. Launch every CPU run with torchrun --standalone and a distinct port per run.