Unit 7 of 13 · about 4 hours · explain, measure

Asynchronous collective handles, CUDA streams, events and completion

Overlap starts with issuing work without waiting. A handle used wrong corrupts buffers, and a timing without dependencies proves nothing about concurrency.

You'll be able to

  • Explain the Work handle contract for async_op and state exactly when buffers are safe to touch.
  • Explain CUDA streams, events and dependency ordering around async collectives.
  • Measure sync versus async issue time on CPU and state what would prove true overlap on a GPU.

Covers

Synchronous calls, asynchronous handles and completionCUDA streams, events and dependency ordering
1

Read

In this order, only the parts listed

0 of 3 done

  1. Non-blocking point-to-point and the Work handle (page read 2026-10-14)Writing Distributed Applications with PyTorch

    Point-to-Point Communication: the Non-blocking listing with dist.isend, dist.irecv and req.wait plus the two undefined-behaviour rules

  2. Async launch, streams and device syncBuilding a Distributed Training Framework from First Principles

    From 10:07:22 to about 10:15:00 (hours:minutes:seconds): why an all-reduce can launch while backward continues, CUDA streams, and when torch.cuda.synchronize is required

  3. Communication-computation overlapMachine Learning Systems Volume II - Collective Communication

    Communication-Computation Overlap with Layer-by-layer overlap, Bucket fusion and Overlap limits

    Read for the overlap vocabulary and the exposed-versus-hidden distinction. Leave bucket tuning for the data-parallelism section.

2

Focus on

  • Passing async_op=True returns a Work handle at once. The collective completes only after handle.wait(), and buffers on both sides are unsafe until then.
  • A CUDA stream orders work; an event marks a point in a stream. Dependencies between compute and communication streams, not mere async issue, decide what actually overlaps.
  • Overlap hides transfer time behind compute only when compute outlasts the transfer and no dependency forces a wait. Async issue without such cover is just deferred waiting.
  • CPU time.perf_counter around async calls measures issue overhead, not GPU concurrency. Event-attributed timelines on a GPU are the proof; treat CPU numbers as issue-cost examples only.
Common mistakes · 3
  • Reading the result tensor right after an async call without wait. The values are undefined until completion.
  • Claiming overlap from a shorter async wall time on CPU. The CPU returns early by construction; concurrency needs stream dependency proof on a GPU.
  • Writing to a buffer that an async collective still uses. Call handle.wait() first; with NCCL that call only makes the current CUDA stream wait for the collective, so a CPU timer or a host read still needs torch.cuda.synchronize().
3

Try it yourself

Closed-book, before checking anything

On 2 gloo CPU processes, issue dist.all_reduce with async_op=True, run a fixed local matrix multiply, then wait and assert the reduced value. Time the same script with a blocking call and report both numbers as issue costs, not as overlap evidence.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.What does dist.all_reduce with async_op=True return, and when may the input buffer be reused?Answer

    A Work handle. The buffer may be touched only after handle.wait() confirms completion.

  2. 2.What is the difference between a CUDA stream and a CUDA event in overlap work?Answer

    A stream orders queued work; an event records that a stream reached a point. Code waits on events to express that communication may proceed only after some compute finished.

  3. 3.An async all-reduce script runs faster on CPU than its blocking twin. Does that prove communication overlapped with compute?Answer

    No. The async call returns before the transfer finishes, so a shorter Python wall time only shows deferred waiting. Proof needs GPU timelines showing transfer and compute on overlapping intervals with satisfied dependencies.

  4. 4.Where must the wait go if a second collective consumes the first collective's output?Answer

    Between them on every rank that consumes the data. Issuing the consumer early reads an incomplete buffer.

5

Practice

  • Writing Distributed Applications with PyTorch: async handles drill

    The Non-blocking listing extended to dist.all_reduce with async_op=True on 2 gloo CPU processes: wait, assert the sum, then add a local compute between issue and wait and time both variants

    Report both timings as issue costs with backend, world size and PyTorch version. Do not present them as interconnect results.

You're done when

The async script passes on two processes with correct wait placement, and you can state what a GPU timeline must show before you claim overlap.

Only when you can do this without notes.

Leads to

Notes

Resources · 3 for this unit, 12 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.

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

  • 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

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

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

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