Unit 8 of 13 · about 5 hours · derive

Ring and tree collectives and the \(\alpha\)-\(\beta\) cost model

Algorithm choice is a size question, not a brand question. The same ring that wins on gigabyte gradients loses on kilobyte tokens, and the crossover is one equation.

You'll be able to

  • Derive ring and tree all-reduce costs from the - model and locate the crossover.
  • Classify a message as latency-bound or bandwidth-bound from its size against the crossover size.
  • Adjust a textbook prediction with the measured NCCL small-message overhead.

Covers

Ring and tree collective algorithmsLatency, bandwidth and - cost models
1

Read

In this order, only the parts listed

0 of 4 done

  1. Cost models, ring and tree algorithms with the crossoverMachine Learning Systems Volume II - Collective Communication

    Mapping the Terrain with The - cost model, The LogP model and Theory vs. practice: The NCCL reality gap, then Engineering the Flow with Ring AllReduce, Tree AllReduce and The algorithm crossover point

  2. Ring costs as rendered equationsCS336 Assignment 2 (Spring 2026) - Sections 5.1 and 8.1

    Section 8.1, Communication Primitives (pp. 40 to 41): the ring all-gather, reduce-scatter and all-reduce costs plus the alternate ring problem

    Read the rendered PDF, not an extracted text copy: the text layer drops fraction bars, so N-1 over N reads as N-1N.

  3. Intra-node collective costs on GPUsHow to Scale Your Model - Sharded Matrices and GPU Collectives

    How Do Collectives Work on GPUs, Intra-node collectives: the ring all-gather and reduce-scatter time approaching bytes over egress bandwidth

  4. Unchunked ring sketch (page read 2026-10-14)Writing Distributed Applications with PyTorch

    Our Own Ring-Allreduce: the isend and recv ring with the torch.chunk exercise left to the reader

2

Focus on

  • Every message costs : a startup tax plus a transit fee per byte. The crossover size separates latency-bound small messages from bandwidth-bound large ones.
  • Ring all-reduce costs : many latency steps but minimal bytes. Tree forms pay about steps with more bytes per step, so trees win small and rings win large.
  • Chunking is what makes the ring cheap: each of the steps moves bytes per rank. A ring that forwards whole buffers keeps the steps but sends far more per step; CS336 writes the per-device egress bandwidth as , which is here, not the world size.
  • In the book's illustrative DGX H100 table, NCCL small-message latency runs 7 to 8 times the wire , so the real crossover sits above the textbook one. Measure effective on the target fabric before choosing.
Common mistakes · 3
  • Quoting bandwidth only. Below the crossover size the byte count barely matters and startup dominates.
  • Assuming reduce-scatter always costs half an all-reduce. That holds for ring all-reduce, which is reduce-scatter plus all-gather; NCCL may run all-reduce as a tree or with in-switch reduction, so measure both before using the ratio.
  • Copying TPU link constants from the scaling-book answers into NCCL predictions. Redo every answer with your own and .
3

Try it yourself

Closed-book, before checking anything

Closed-book, derive ring all-reduce time from reduce-scatter plus all-gather, then evaluate 4 ranks and a 1 GB payload at and GB/s: latency 12 microseconds plus 30 ms of bandwidth, about 30.01 ms. Then state which side of the 100 KB crossover a 4 KB token message sits on.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.On a link with and GB/s, what is the crossover size, and is a 4 KB MoE token message latency-bound or bandwidth-bound?Answer

    The crossover is bytes, about 100 KB. A 4 KB message sits 25 times below it, so it is latency-bound and fusing helps more than adding bandwidth.

  2. 2.Derive the ring all-reduce bandwidth term from its two halves.Answer

    Reduce-scatter moves bytes per rank and all-gather moves the same again, so the ring total is plus latency steps.

  3. 3.Eight ranks ring all-reduce a 64 MB gradient ( bytes) with and GB/s. Compute both terms and say which dominates.Answer

    Latency is . Bandwidth is ms. Bandwidth dominates by about 64 times, so this message is far above the crossover.

  4. 4.A textbook crossover says rings win above 1 MB, but NCCL measurements prefer trees up to several MB. Why?Answer

    The textbook is the wire value. NCCL protocol setup inflates effective small-message latency several-fold, which pushes the real crossover upward.

5

Practice

  • CS336 Assignment 2: alternate_ring_all_reduce

    Section 8.1, problem alternate_ring_all_reduce (p. 41): derive the (N-1) S over W time with the one-sentence justification

    Answer from the ring derivation before reading any solution, and write the cost with for egress bandwidth so it does not clash with world size.

You're done when

You derive both ring and tree costs without notes, classify messages against the crossover, and your alternate-ring answer states the missing chunking saving.

Only when you can do this without notes.

Leads to

Notes

Resources · 4 for this unit, 11 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.

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

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

Also in this section

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

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

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

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

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

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