Unit 3 of 13 · about 4 hours · implement

Point-to-point transfers, broadcast and reduce ownership

Pipelines move activations along single edges, not group averages. One unmatched send or one read of a stale root buffer corrupts the handoff silently.

You'll be able to

  • Implement matched send and receive pairs with blocking and non-blocking calls.
  • Implement broadcast and reduce and state exactly which ranks hold valid results.
  • Predict the deadlock or stale read from an unmatched pair or an early buffer access.

Covers

Point-to-point send and receive semanticsBroadcast and reduce ownership semantics
1

Read

In this order, only the parts listed

0 of 4 done

  1. Point-to-point listings and wait rules (page read 2026-10-14)Writing Distributed Applications with PyTorch

    Point-to-Point Communication: the blocking listing, the non-blocking listing with dist.isend and dist.irecv, and the two undefined-behaviour rules before req.wait()

  2. Broadcast and reduce bullets (page read 2026-10-14)Writing Distributed Applications with PyTorch

    Collective Communication: the dist.broadcast and dist.reduce bullets plus the ReduceOp list with SUM

  3. Point-to-point, Broadcast and ReduceMachine Learning Engineering Open Book - Communication Patterns

    Point-to-point communications with send, recv, isend and irecv, then Broadcast and Reduce with their call signatures

  4. Send, receive and pipeline handoffsBuilding a Distributed Training Framework from First Principles

    From 7:08:05 to about 7:10:00 (hours:minutes:seconds): send and receive as point-to-point primitives, with the pipeline send near 9:59:00 to 10:00:00 as the use case

2

Focus on

  • Every dist.send names a dst and every dist.recv names a src, with a preallocated buffer of matching shape and dtype on the receiving rank. Blocking calls return after completion; immediates return a Work handle that requires req.wait().
  • After dist.isend, writing the sent tensor is undefined until wait. After dist.irecv, reading the receive buffer is undefined until wait. After wait, the transfer is guaranteed.
  • Broadcast copies one source tensor to all ranks. Reduce combines every rank into dst only; other ranks' tensors are left undefined, and gloo uses them as scratch for partial sums.
  • A send with no matching receive, or a receive with no send, blocks until the group timeout. The matched pair is the unit that must agree.
Common mistakes · 3
  • Allocating the receive buffer with the wrong shape or dtype. On gloo the receiving process aborts with "Received data size doesn't match expected size", killing the rank instead of raising a Python error; other backends may hang or corrupt. Allocate from the agreed shape.
  • Reading a reduce result on a non-root rank. Only dst holds the combined value.
  • Reusing a send buffer right after isend without wait. The transfer may still be in flight.
3

Try it yourself

Closed-book, before checking anything

Closed-book, write the two-process exchange: rank 0 builds a 3-element tensor and sends it to rank 1 with isend and irecv plus wait, then rank 1 broadcasts it back so both ranks hold it. State every buffer each rank allocates.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.What is the observable difference between dist.send with dist.recv and dist.isend with dist.irecv?Answer

    The blocking pair returns after the transfer completes. The immediate pair returns a Work handle at once, and the transfer is only guaranteed after req.wait().

  2. 2.Rank 0 calls isend on a tensor, then overwrites the tensor before wait. Rank 1 receives after its own wait. What can rank 1 hold?Answer

    Anything, including a mix of old and new values. Writing a sent buffer before wait is undefined behaviour.

  3. 3.Four ranks call dist.reduce with dst=0 and SUM. Afterwards rank 2 reads its tensor. What does it see?Answer

    Nothing it can rely on. Only rank 0 is guaranteed the sum; on gloo in PyTorch 2.14.1 a 4-rank run with inputs 1 to 4 left partial sums such as [9, 9, 10, 10, 2, 2, 5, 5] in rank 1's tensor. Treat non-destination buffers as scratch, or broadcast the result if other ranks need it.

  4. 4.Rank 0 sends to rank 1, but rank 1 never posts a receive and instead calls all_reduce. What happens?Answer

    Both block until the timeout. The send waits for a matching receive that never comes, and rank 1 waits at a collective rank 0 never joins.

5

Practice

You're done when

The exchange passes on two processes, and you can name every valid and every stale buffer without notes.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 12 more in the section
  • 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.

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

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.distributed example on Gloo and annotate tensor ownership before moving to higher parallelism.

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

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

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