Unit 2 of 13 · about 4 hours · explain, implement
Rendezvous, stores, launchers and default and nested process groups
Collectives run inside named groups, not on bare machines. The store handshake and the group grid decide who talks to whom before any tensor moves.
You'll be able to
- Explain rendezvous, stores and launchers, and what the process-group lifecycle owns.
- Build the default world group plus nested subgroups for a stated 2 by 2 layout.
- Predict init hangs from a mismatched world size, endpoint or mesh shape.
Covers
Read
In this order, only the parts listed
0 of 4 done
- Initialization methods (page read 2026-10-14)Writing Distributed Applications with PyTorch
Initialization Methods: Environment Variable, Shared File-System with the fcntl locking warning, and TCP
- Single-node and elastic launch flagsPyTorch 2.14 torchrun (elastic launch) reference
Single-node multi-worker through the elastic membership rows:
RANK,WORLD_SIZEandLOCAL_RANK, plus flags--standalone,--nnodes,--nproc-per-node,--rdzv-backendand--rdzv-endpoint - ProcessGroupManager grid and subgroup enumerationPicotron - Process Groups and Communication Files
ProcessGroupManagerthroughsetup_process_group_manager: thearangegrid overdp,pp,cpandtpplusnew_subgroups_by_enumeration - Steps 1 to 3 with diffs and the Part 1 videoPicotron Tutorial - Steps 1 to 3 and Part 1 Video
step2_process_group_manager and step3_dataloader with their diffs and the Part 1 video on the model, the process group manager and the dataloader
Rebuild the rank grid yourself before reading the solution.
Focus on
- A store is a key-value handshake; the rendezvous stores are
TCPStoreandFileStore. The launcher starts the processes, rendezvous introduces them, anddist.init_process_groupbuilds the world group. - The default group holds all ranks.
dist.new_groupcarves named subsets, one rank may belong to several groups at once, and each group orders its own collectives. - Picotron lays ranks out as
torch.arange(world).view(dp, pp, cp, tp)and enumerates one subgroup per axis. Every rank must build the identical grid or the groups disagree silently. - File init needs a nonexistent or empty shared file with fcntl locking. Mesh shapes must match on all ranks or setup hangs.
Common mistakes · 3
- Reusing one fixed MASTER_PORT for several concurrent runs. The second job fails or joins the wrong rendezvous, so use a distinct port per run.
- Deriving the local rank from the global rank in example code, as in
rank % torch.cuda.device_count(). It breaks when nodes hold different GPU counts or ranks are not packed node by node; read theLOCAL_RANKthe launcher sets. - Assuming subgroups inherit a barrier or an ordering from the world group. Each group needs its own calls in the same order.
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.What does the store do, and when is it no longer needed?Answer
Ranks exchange their addresses through it during init, so they can find each other. It stays in use after init:
new_groupcoordinates through it,monitored_barrierreports through it, and errors are shared through it. Collective payloads never pass through the store.2.World size 4 with dp 2 and tp 2 in Picotron order: which ranks share a tensor-parallel group, and which share a data-parallel group?Answer
Tensor-parallel groups are {0, 1} and {2, 3}. Data-parallel groups are {0, 2} and {1, 3}.
3.Rank 0 of a subgroup calls
all_reducebut rank 1 of the same subgroup callsbroadcast. What happens?AnswerThe calls never pair up. On gloo with the default debug level both ranks block until the timeout; with
TORCH_DISTRIBUTED_DEBUG=DETAILthe wrapper compares collective fingerprints and both ranks fail at once with "Detected mismatch between collectives on ranks". Every member must issue the same sequence, and subgroups do not inherit ordering from the world group.4.Two jobs on one machine share MASTER_PORT. What goes wrong?Answer
The second job either fails to bind or rendezvous with the wrong peers. Give each run its own port.
Practice
- Picotron Tutorial: Steps 1 to 3 (process group manager and dataloader)
step2_process_group_manager and step3_dataloader with their diffs: rebuild the rank grid yourself, then diff against the solution
Keep the Part 1 video for the second pass over the same steps.
You're done when
Your hand-drawn groups match the subgroup enumeration on CPU, and a subgroup barrier passes on four processes.
Only when you can do this without notes.
Leads to
Notes
Resources · 4 for this unit, 11 more in the section
- 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. - 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. - 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.
Also in this 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.
- 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. - 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. - 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.
- 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. - 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.