skip to content

With PyTorch 2.14's NCCL process group, a job dies on a watchdog timeout after ten minutes; how do you find the rank that diverged?

level: seniorimportance: nice to knowfreq 5%

answer

  1. a watchdog thread per process group
  2. ten minutes unless you pass one
  3. every rank remembers its last collectives
  4. sequence number and op type per rank
  5. trace buffer size and dump on timeout

basics

~20 s

Read the flight recorder: PyTorch 2.14 records each rank's recent NCCL collectives and dumps them on a watchdog timeout. Comparing the last sequence number and operation across ranks shows the rank that issued a different or missing collective.

solid answer

~40 s

In PyTorch 2.14 the NCCL process group times a collective out after 10 minutes by default (other backends wait 30), and the watchdog logs `Watchdog caught collective operation timeout: WorkNCCL(SeqNum=..., OpType=...)`. With `TORCH_NCCL_ASYNC_ERROR_HANDLING` at its default of 3, the process is then torn down. The evidence is the flight recorder: a per-group ring buffer of recent collectives, `TORCH_NCCL_TRACE_BUFFER_SIZE` events long (2000 when unset in the 2.14 source; 0 disables it), dumped on timeout because `TORCH_NCCL_DUMP_ON_TIMEOUT` defaults to on there, to the location `TORCH_NCCL_DEBUG_INFO_TEMP_FILE` sets. Line up every rank's last sequence number and op: one rank behind the rest, or at the same sequence number with a different op or size, is the mismatched collective that stalled everyone. Fix that code path; a longer timeout only waits longer.

code

bash · 8 lines
bash
# PyTorch 2.14 flight-recorder settings, written out explicitly on every node
export TORCH_NCCL_TRACE_BUFFER_SIZE=2000   # 0 would disable the recorder
export TORCH_NCCL_DUMP_ON_TIMEOUT=1
export TORCH_NCCL_DEBUG_INFO_TEMP_FILE=/shared/fr/vit-pretrain-trace

# Debug runs only: check op and shape agreement before every collective
export TORCH_DISTRIBUTED_DEBUG=DETAIL
export TORCH_CPP_LOG_LEVEL=INFO

go deeper

for a junior

Recall that PyTorch's NCCL process group gives up on a stuck collective after a timeout, 10 minutes by default, and that the error names the operation and its sequence number.

for a middle

Explain the watchdog, the async error-handling modes and why the process is torn down, and name the flight-recorder variables that size and dump its buffer.

for a senior

Show the diagnosis: collect every rank's dump, line up sequence numbers and ops, tell a code-path mismatch from a transport stall, then prove the fix with DETAIL checks in a short run.

for a principal

Set timeout and dump policy for a fleet: shorter timeouts free GPUs sooner but can kill slow but healthy steps, and dumps need storage every node can write and someone who reads them.

## Who notices a stuck collective PyTorch launches NCCL collectives asynchronously on CUDA streams, so the Python call returns before the data moves. A **watchdog** thread per NCCL process group checks each pending work item against the group's **timeout**: 10 minutes by default in PyTorch 2.14 (`kProcessGroupNCCLDefaultTimeout`), 30 minutes for other backends, or whatever `init_process_group(timeout=...)` was given. On expiry it logs `Watchdog caught collective operation timeout: WorkNCCL(SeqNum=812, OpType=ALLREDUCE, NumelIn=..., NumelOut=..., Timeout(ms)=600000) ran for ... milliseconds before timing out.` and applies the error-handling mode. | `TORCH_NCCL_ASYNC_ERROR_HANDLING` | Behaviour on a timeout or NCCL error | |---|---| | 0 | No handling | | 1 | Abort the NCCL communicator and tear down the process | | 2 | Abort the communicator only | | 3 (default) | Tear down the process without aborting the communicator | The process is torn down because CUDA work is asynchronous: later kernels may already be queued on data that will never arrive, so it is no longer safe to keep running user code. `TORCH_NCCL_BLOCKING_WAIT=1` instead makes `wait()` block and raise in the calling thread. The unprefixed `NCCL_ASYNC_ERROR_HANDLING` and `NCCL_BLOCKING_WAIT` are still read as legacy aliases; the `TORCH_NCCL_` names are current. A separate monitoring thread, on by default, aborts the process if the watchdog itself stops responding for `TORCH_NCCL_HEARTBEAT_TIMEOUT_SEC` (480 seconds in the 2.14 source). ## Why a mismatch hangs instead of failing NCCL's guide requires every rank to call each collective with the same count and datatype; otherwise the behaviour is undefined, including hangs. The ranks also have to issue the same collectives in the same order. Typical causes: - a data-dependent branch that skips an `all_reduce` on one rank, for example a metric logged only when a batch is non-empty; - two code paths that issue collectives in a different order; - one rank calling `all_gather` where the rest call `all_reduce`; - tensors of different sizes on different ranks. The first three leave most ranks waiting in a collective that one rank never joins; mismatched sizes are undefined behaviour, which can mean a hang or wrong data. From the outside a hang of this kind looks much like a network stall. ## The flight recorder The **flight recorder** is a ring buffer, one per NCCL process group, of recent collective start and end events, each with its sequence number, op type and sizes, plus a stack trace where one could be captured. - `TORCH_NCCL_TRACE_BUFFER_SIZE`: the number of events kept; 2000 when unset in the 2.14 source, 0 disables recording and the dump. - `TORCH_NCCL_DUMP_ON_TIMEOUT`: dump the buffer when the watchdog sees a timeout or exception; on by default in the 2.14 source, and only effective with a buffer larger than 0. - `TORCH_NCCL_DEBUG_INFO_TEMP_FILE`: where the dump is written; point it at storage you can collect from every node. - `TORCH_NCCL_TRACE_CPP_STACK`: also record C++ stacks (off by default). `TORCH_FR_BUFFER_SIZE` is a different variable, read by the TorchComms flight-recorder hook, not by the native NCCL process group. ## Reading the dumps 1. Collect the dump from every rank, not only from the ranks that logged first. 2. For each rank, find the last collective it entered and its sequence number. 3. If one rank's last sequence number is lower than everyone else's, that rank never reached the collective the others are waiting in; look at what it was doing instead. 4. If all ranks show the same sequence number but different op types or sizes, the code issued mismatched collectives at that point. 5. If every rank is in the same op with the same sizes, the code agrees and the fault is below it, in the transport or the fabric; go to NCCL's own debug output. ## Catching it before production - `TORCH_DISTRIBUTED_DEBUG=DETAIL` wraps every process group with a monitored barrier and a check that all ranks call the same function with consistent tensor shapes, so a mismatch crashes with a report instead of hanging. It slows every collective, so keep it to debug runs. - `TORCH_NCCL_DESYNC_DEBUG`, set together with async error handling, helps name the culprit rank of a collective desync. Restarting the job after the timeout is the launcher's business; the point here is to leave enough evidence that the restart does not hit the same mismatch again.

  • Why does PyTorch tear the process down on a timeout instead of raising an exception the training loop could catch?
    CUDA work is asynchronous: when a collective times out, later kernels may already be queued on data that will never arrive, so PyTorch's docs say it is no longer safe to keep running user code. With `TORCH_NCCL_ASYNC_ERROR_HANDLING` at its default of 3 the process is torn down; `TORCH_NCCL_BLOCKING_WAIT=1` instead makes `wait()` block and raise in the calling thread.
  • How can a test run catch a mismatched collective before it becomes a ten-minute hang?
    Set `TORCH_DISTRIBUTED_DEBUG=DETAIL`: PyTorch wraps each process group and, before every collective, runs a monitored barrier and checks that all ranks call the same function with consistent tensor shapes, so a mismatch crashes with a report instead of hanging. It slows every collective, so keep it to short debug runs.

  • The NCCL collective timeout in PyTorch defaults to 30 minutes.
  • Raising the process-group timeout fixes a collective hang.
  • TORCH_FR_BUFFER_SIZE sizes the NCCL process group's flight recorder.
  • NCCL_ASYNC_ERROR_HANDLING is the current name of PyTorch's async error-handling variable.
  • A collective hang always means the network dropped packets.

Assumes PyTorch 2.14: NCCL process groups default to a 10-minute timeout, and the 2.14 source defaults TORCH_NCCL_TRACE_BUFFER_SIZE to 2000 and TORCH_NCCL_DUMP_ON_TIMEOUT to on.