Unit 10 of 13 · about 4 hours · explain
PCIe, NVLink, NVSwitch, NICs, node topology and the NCCL and Gloo backends
The same collective runs at NVLink speed or at network speed depending on placement. Backend and topology vocabulary turns that placement from luck into a decision.
You'll be able to
- Explain the intra-node and inter-node link tiers and which traffic each tier should carry.
- Choose between NCCL and Gloo from the tensor devices and state what each backend expects.
- Read a node topology and NCCL debug output at the level of links, not just rank counts.
Covers
Read
In this order, only the parts listed
0 of 4 done
- Communication backends (page read 2026-10-14)Writing Distributed Applications with PyTorch
Communication Backends: the Gloo, MPI and NCCL paragraphs with the one-GPU-per-process device lines
Skip the MPI rebuild steps. Note the Gloo GPU paragraph as vocabulary, not as a performance recommendation.
- Library landscape and topology-aware routingMachine Learning Systems Volume II - Collective Communication
The Communication Library Landscape with NCCL, MPI, Gloo and the selection guide, plus Hierarchical Communication with Topology-aware routing
- Hardware glossary and bandwidth vocabularyMachine Learning Engineering Open Book - Communication Patterns
Glossary and concepts: NCCL, peer-to-peer versus all-to-all, NVLS and NVLSTree, SHARP, algorithm versus bus bandwidth, and Unidirectional versus Bidirectional
- NCCL topology, algorithms and communicator lifecycleAI Systems Performance Engineering - Chapter 4 Distributed Networking Communication
Chapter 4 Distributed Networking Communication: NCCL for Distributed Multi-GPU Communication, Topology Awareness in NCCL, NCCL Communication Algorithms, and NCCL Communicator Lifecycle and Environment Gotchas
Focus on
- Inside a node, GPUs meet over NVLink and NVSwitch with PCIe to the host. Between nodes, NICs carry traffic over InfiniBand or Ethernet at an order less bandwidth. Keep the heavy bytes on the fast tier.
- Use NCCL for CUDA tensors and Gloo for CPU tensors. NCCL needs one GPU per rank; Gloo runs the same collective vocabulary on CPU without GPU-tuned speed.
- NVLink numbers come in pairs: the H100 figure of 900 GB/s is bidirectional, which is 450 GB/s one-way, and only the one-way rate enters . Mixing the two doubles or halves every prediction.
- Companion code
format_bandwidthreports total gathered bytes over time for all-gather, which equals algorithm bandwidth, not bus bandwidth: https://github.com/cfregly/ai-performance-engineering/blob/b57e4c6a9e261c09ac09208705d040c81b03d35e/code/ch04/nccl_benchmark.py - multiply its all-gather rate by before comparing with bus-bandwidth figures.
Common mistakes · 3
- Reading CPU gloo timings as interconnect evidence. They cross loopback or office TCP with CPU overhead, so they cannot speak about NVLink or InfiniBand.
- Assuming one GPU is enough for multi-rank NCCL practice. One GPU means at most one NCCL rank; further ranks need more GPUs or the gloo CPU path.
- Treating MPI as a pip-install backend. PyTorch binaries exclude it, so MPI needs a source rebuild and stays vocabulary here.
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.Eight ranks span 2 nodes of 4 GPUs. Which tier should carry the bulk of an all-reduce, and why?Answer
The intra-node NVLink tier. A hierarchical plan reduces inside each node first and sends only shards between nodes, because the inter-node tier is far slower per byte.
2.Four CPU processes need broadcast and all-reduce. Which backend, and what changes with 4 GPUs?Answer
Gloo on CPU. With 4 GPUs use NCCL with one GPU per rank, since NCCL carries the GPU-tuned collectives and Gloo GPU paths are unoptimized.
3.A table quotes 900 GB/s for NVLink. What value enters the - formula, and why?Answer
450 GB/s one-way. The formula counts bytes in one direction, while 900 GB/s is the bidirectional total.
4.
NCCL_DEBUG=INFOshowsNET/IBfor some ranks andNET/Socketfor others. What does that tell you?AnswerTraffic split across tiers: some ranks use InfiniBand and some fall back to sockets. Placement or interface settings disagree across the run.
Practice
- Stas
all_reduce_bench.py:timed_allreducereading and conditional runtimed_allreducewithdist.barrierand CUDA events, thebusbw_coeffline inrun, plus thetorch.distributed.runrendezvous command linesWith two or more GPUs, run the 2-process command and label the exact topology. On CPU, read the timing lines and state why gloo numbers are not interconnect evidence.
You're done when
Your backend choices are correct for CPU, single-node and multi-node runs, and you can sketch which tier each collective crosses without notes.
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.
- Machine Learning Engineering Open Book - Communication PatternsStas Bekman · required
Read
network/comms.mdfrom point-to-point through ring all-reduce, thennetwork/README.mdandnetwork/debug/README.mdselectively. Derive bytes and steps before running anything;network/benchmarks/all_reduce_bench.pyneeds 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.distributedreference; Gloo all-to-all runs on CPU in 2.14. - 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.pyfrom the companion repository and label the exact topology.
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.distributedexample 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.pyPart 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_managerandstep3_dataloaderwith their diffs and the Part 1 video (model, process group manager and dataloader). Rebuild the rank grid yourself before reading the solution. - CS336 Assignment 2 (Spring 2026) - Sections 5.1 and 8.1Stanford University · required
Complete
distributed_communication_single_nodewith 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 solvealternate_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.
- nccl-tests and its performance notesNVIDIA · support
With two or more GPUs, run
all_reduce_perfover a message-size sweep and readdoc/PERFORMANCE.mdfor 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_groupwith timeout anddevice_id,new_groupandnew_subgroups, theWorkandasync_opcontract,monitored_barrier,destroy_process_groupandTORCH_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_SIZEandLOCAL_RANK, plus flags--standalone,--nnodes,--nproc-per-node,--rdzv-backendand--rdzv-endpoint. Launch every CPU run withtorchrun --standaloneand a distinct port per run.