Unit 11 of 13 · about 4 hours · implement

Rank-local logs, collective sequence numbers, timeouts, aborts and teardown

A hang report that names no rank and no sequence number is unactionable. Rank-local logs with sequence numbers turn who waited for whom into a readable fact.

You'll be able to

  • Implement per-rank structured logs with collective sequence numbers and tensor metadata.
  • Set timeouts and teardown correctly and predict orphan behavior on abort.
  • Attribute a slow collective to the guilty rank from aligned rank-local evidence.

Covers

Rank-local structured logs and collective sequence numbersTimeout, abort, teardown and orphan-process behavior
1

Read

In this order, only the parts listed

0 of 4 done

  1. Timeout, teardown, barriers and debug levelsPyTorch 2.14 `torch.distributed` reference

    The init_process_group timeout entry with 10 minutes for NCCL and 30 minutes for other backends, destroy_process_group, the monitored_barrier entry, and TORCH_DISTRIBUTED_DEBUG with OFF, INFO and DETAIL

  2. Network debug checklistMachine Learning Engineering Open Book - Communication Patterns

    How to diagnose NCCL multi-gpu and multi-node connectivity issues with NCCL_DEBUG=INFO, How to check if P2P is supported, How to count NCCL calls, and Useful NCCL Debug Environment Variables

  3. Process-group timeout and teardownBuilding a Distributed Training Framework from First Principles

    From 5:37:40 to about 5:38:10 (hours:minutes:seconds): a higher timeout at group creation, a lower one after the first step, and the short wait before the process exits

  4. Setup and cleanup helpersCS336 Assignment 2 (Spring 2026) - Sections 5.1 and 8.1

    tests/common.py: _setup_process_group and _cleanup_process_group as the setup and teardown pattern behind the DDP and FSDP tests

2

Focus on

  • Log on every rank: rank, group, collective sequence number, tensor shape and dtype, and start and end times. Rank 0 logs alone never show the failing rank.
  • Sequence numbers align the same collective across ranks. A gap or a lone high number on one rank points at the call that diverged.
  • Timeouts bound every wait: 30 minutes default for gloo and other backends, 10 minutes for NCCL. dist.monitored_barrier with a short fuse names the rank that never arrives.
  • Call dist.destroy_process_group on every rank at the end. When one rank dies, the survivors block in their next collective until the timeout; torchrun then stops the other workers, but ranks started by hand in a shell loop can outlive the run and hold the port, so the next rendezvous fails.
Common mistakes · 3
  • Logging only on rank 0. The guilty rank is usually elsewhere, so rank-0 logs show a clean run that waited forever.
  • Keeping default timeouts during fault drills. A 30-minute fuse turns a 10-second diagnosis into a coffee break.
  • Expecting NCCL_DEBUG=INFO to show your call order. By default it reports init and connectivity; per-call lines need NCCL_DEBUG_SUBSYS=COLL, and even those come from NCCL, not your code, so keep your own sequence log.
3

Try it yourself

Closed-book, before checking anything

On 2 gloo CPU processes, log 3 collectives with sequence numbers 0, 1 and 2 plus shapes and durations on both ranks. Then make rank 1 sleep 20 seconds before a monitored_barrier with a 10-second timeout and show the rank 0 report naming rank 1.
4

Quiz yourself

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

0 got · 0 missed

  1. 1.What are the default collective timeouts for NCCL and for gloo, and why do drills override them?Answer

    10 minutes for NCCL and 30 minutes for other backends including gloo. Drills use seconds so a hang reports quickly instead of stalling the session.

  2. 2.Rank 0 logs sequence numbers 0, 1, 2 and rank 1 logs 0, 1, 1. What diverged?Answer

    The third collective. Rank 1 repeated or never advanced past sequence 1, so its call sequence disagrees with rank 0 from number 2 on.

  3. 3.One rank is killed mid-run before destroy_process_group. What do the other ranks do, and what can linger?Answer

    They block in their next collective until the timeout, then fail. torchrun stops the remaining workers of the group; processes started by hand can linger and hold the master port, so check for them before the next run.

  4. 4.Ranks 2 and 3 are both late to a monitored_barrier on 4 ranks. What does rank 0 report with the default arguments, and how do you see both?Answer

    By default rank 0 names only the first rank that missed the timeout. Pass wait_all_ranks=True to collect every late rank in one report, such as "Ranks 2, 3 failed to pass monitoredBarrier".

5

Practice

  • Timeout and teardown drill with monitored_barrier

    The monitored_barrier entry on 2 gloo CPU processes: log 3 collectives with sequence numbers on both ranks, make rank 1 sleep past a 10-second barrier timeout, and report which rank the barrier names

    Keep every log line structured with rank, group, sequence, shape and duration. Compare with the Stas debug checklist for what NCCL output would add on GPUs.

You're done when

Logs from all ranks align by sequence number, and the delay drill attributes the wait to the correct rank with evidence, not guesses.

Only when you can do this without notes.

Leads to

Notes

Resources · 4 for this unit, 11 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.

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

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

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.

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

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