Ranks, Collectives and Topology
Every higher parallel strategy reduces to ordered communication among named groups. Exact tensor ownership, collective order and a simple cost model turn hangs and slowdowns into diagnosable mechanisms.
Section 2 of 10 · 13 units · about 50 hours
By the end you can Simulate and test the five core collectives across multiple CPU processes, match results to tensor-ownership invariants, validate one cost prediction, and diagnose three injected rank, order or metadata mismatches.
Units
- Processes, global and local rank, world size and one process per device3h
- Rendezvous, stores, launchers and default and nested process groups4h
- Point-to-point transfers, broadcast and reduce ownership4h
- All-reduce, gradient averaging and the all-gather and reduce-scatter duality4h
- All-to-all semantics and token exchange3h
- Barriers, collective ordering and shape and dtype agreement4h
- Asynchronous collective handles, CUDA streams, events and completion4h
- Ring and tree collectives and the \(\alpha\)-\(\beta\) cost model5h
- Per-rank bytes, critical paths, message size and effective bandwidth4h
- PCIe, NVLink, NVSwitch, NICs, node topology and the NCCL and Gloo backends4h
- Rank-local logs, collective sequence numbers, timeouts, aborts and teardown4h
- A CPU multiprocess collective correctness suite4h
- Hierarchical collectives and compressed communication with accuracy controls3h
Build it
Mini project · about 12 to 16 hours
Ordered collectives with a CPU correctness suite
Build the rank and group layer in comm/ and check every collective against a single-process oracle on CPU processes. Exact ordering, ownership and cost reasoning here prevents hangs and silent mismatch in every parallel design that follows.
- 1Launch CPU processes with
torchrun, map global ranks to devices through the launcher variables, and build the default group plus nested subgroups for a small grid, each run on a distinct port withgloo. - 2Exchange tensors with matched blocking and non-blocking send and receive pairs, then broadcast and reduce; prove which ranks hold valid results and show an early buffer touch corrupts the handoff.
- 3Implement all-reduce, all-gather, reduce-scatter and all-to-all on several CPU processes, checking every rank against single-process oracles; pass the TensorTonic collectives cases and derive the per-rank byte factor for each.
- 4Run the order-swap drill with a short timeout and attribute the hang with
monitored_barrierand debug output; issue one async collective with compute between issue and wait, reporting CPU timings as issue cost only. - 5Derive ring and tree all-reduce costs from the latency-bandwidth model and locate the crossover; pass the TensorTonic bandwidth cases and sweep sizes with warmup and synchronization, adding a measured variant only with two or more GPUs while recording backend and link tier beside every number.
- 6Ship the CPU multiprocess collective suite in
tests/covering ranks, subgroups, dtypes and edges with deterministic seeds; keep rank-attributed logs with collective sequence numbers, bounded teardown, and one injected fault that fails its exact assertion.
What you hand in
- The
comm/rank and group layer with launch, mapping and subgroup construction. - The CPU collective suite with oracle comparisons, edge coverage and the injected-fault demonstration.
- Cost derivations, the CPU sweep table and rank-attributed logs with teardown evidence.
How to check it
- Self-grade with the rubric below
- TensorTonic: Simulate Distributed Collectives
Pass the gather, scatter and all-to-all cases in your harness before the multiprocess runs.
- TensorTonic: Calculate Collective Effective Bandwidth
Pass the public byte-factor cases before computing bandwidth from your own sweep.
How it's graded
Collective correctness
Pass: Every collective matches the single-process oracle on every rank across subgroups, dtypes and edge cases.
Great: An uneven-split case and a subgroup case are added beyond the named suites.
Ordering discipline
Pass: The swapped order times out on a short fuse, the fixed order passes, and the guilty rank is named from evidence.
Great: A second mismatch class, shape or dtype, is drilled with its distinct symptom.
Cost honesty
Pass: Byte factors are derived per collective, CPU sweeps carry warmup, backend and commit, and no CPU number is quoted as link bandwidth.
Great: The crossover prediction is tested against a sweep and the residual is attributed.
Suite rigor
Pass: The suite is green with deterministic seeds and distinct ports, and the injected fault fails its exact assertion.
Great: Fault coverage extends to a second class and teardown leaves no orphan holding the port.
Resources
- Machine Learning Systems Volume II - Collective CommunicationML Systems Textbook
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
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
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
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
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.
- Machine Learning Engineering Open Book - Communication PatternsStas Bekman
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
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. - CS336 Assignment 2 (Spring 2026) - Sections 5.1 and 8.1Stanford University
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. - CS336 Spring 2025 - Lecture 8 Parallelism (executable lecture)Stanford University
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 Tutorial - Steps 1 to 3 and Part 1 VideoHugging Face
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. - TensorTonic - Collective Simulation ProblemsTensorTonic
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)
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. - nccl-tests and its performance notesNVIDIA
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
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
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.