skip to content

How do you confirm that one straggler rank is slowing a 512-GPU Slurm training run by 30%, and what do you do about it?

level: seniorimportance: should knowfreq 12%

answer

  1. everyone waits for the slowest
  2. fast ranks wait inside collectives
  3. time compute per rank, not the step
  4. gather timings, map rank to host
  5. exclude the node, resume from checkpoint

basics

~20 s

Every collective finishes only when the slowest rank arrives, so one slow rank slows all 512. Time each rank's own compute and data wait, gather the numbers with hostnames, then exclude the outlier's node and resume from the last checkpoint.

solid answer

~50 s

A straggler shows up as every rank's step getting slower at once with no error, because synchronous training cannot finish a collective until all ranks reach it; the fast ranks spend the difference waiting inside it. Whole-step time is therefore useless for finding it — it is the same everywhere. Time the parts each rank does alone: data-loader wait and forward compute, recorded with `torch.cuda.Event(enable_timing=True)`, then `dist.all_gather_object` the numbers with each rank's hostname to rank 0 every few hundred steps. The rank whose own work is consistently longest is the straggler; its hostname (or torchrun's `${hostname}` log prefix in PyTorch 2.14) names the node. Fix the cause if it is data imbalance; if it is hardware — a throttling GPU, a degraded link, a busy host — save, resubmit with `sbatch --exclude=<node>` and resume from the checkpoint. Raising timeouts does not help: nothing is timing out.

code

python · 25 lines
python
import socket, time
import torch
import torch.distributed as dist

# body of the training loop at step `step`
t0 = time.perf_counter()
inputs, targets = next(batches)             # data wait on this rank
data_ms = (time.perf_counter() - t0) * 1000

fwd_start = torch.cuda.Event(enable_timing=True)
fwd_end = torch.cuda.Event(enable_timing=True)
fwd_start.record()
loss = loss_fn(model(inputs), targets)      # forward compute on this GPU
fwd_end.record()
loss.backward()
optimizer.step()
torch.cuda.synchronize()
fwd_ms = fwd_start.elapsed_time(fwd_end)

if step % 500 == 0:
    rows = [None] * dist.get_world_size()
    dist.all_gather_object(rows, (dist.get_rank(), socket.gethostname(), data_ms, fwd_ms))
    if dist.get_rank() == 0:
        for rank, host, d, f in sorted(rows, key=lambda r: r[3], reverse=True)[:5]:
            print(f"rank {rank} on {host}: data {d:.0f} ms, forward {f:.0f} ms")

go deeper

for a junior

Know that synchronous training runs at the speed of its slowest rank, so one slow GPU slows the whole job without any error.

for a middle

Explain why fast ranks show the delay as waiting inside collectives and which per-rank timings separate the slow rank from the others.

for a senior

Find the straggler with gathered per-rank timings and hostnames, tell hardware from data imbalance, and remove the node through a checkpointed resubmit or an elastic restart.

for a principal

Make per-rank timing and node draining part of the platform, so a degrading node is caught before it costs hours of a large run.

## Why one rank slows all of them In synchronous data-parallel training every rank must contribute its gradients before any rank can take the optimizer step; with sharded engines, parameter gathers add more such meeting points. A collective (all-reduce, all-gather, reduce-scatter) completes only when **every** rank has arrived. A **straggler** is a rank that consistently arrives late. The others do not fail; they wait inside the collective, and the whole job runs at the straggler's pace. The arithmetic is unforgiving. If the healthy step is 400 ms and one GPU now needs 520 ms for the same work, every step becomes about 520 ms — the reported 30% slowdown — and 511 GPUs each idle roughly 120 ms per step, about 61 GPU-seconds of waste per step. ## Symptoms that point to a straggler - Step time rose for **all** ranks at once, often at a specific moment (a node swap, a reboot, a hot afternoon). - No error, no timeout: the slow rank is late, not stuck. A rank that never arrives is a hang, which is a different diagnosis. - GPU utilisation dips on most GPUs and stays high on one. - In a profiler trace of a healthy rank, time inside communication kernels grows while compute kernels keep their length. ## Finding the rank 1. **Time what each rank does alone.** The data-loader wait (host clock) and, under plain data parallelism, the forward pass (CUDA events) contain little cross-rank waiting, so they differ between ranks; whole-step time does not. Sharded engines gather parameters inside the forward pass, so there compare compute-kernel time in a trace instead. 2. **Gather and rank the numbers.** Every few hundred steps, `dist.all_gather_object` collects `(rank, hostname, data_ms, fwd_ms)` from every rank; rank 0 prints the slowest few. 3. **Check persistence.** A one-off spike (a garbage collection, a checkpoint write) is noise; the same rank on top for hundreds of steps is a straggler. 4. **Map rank to host.** Ranks are not stable across restarts, so record the hostname with the timing rather than inferring it from the rank number. torchrun's `--log-line-prefix-template "${hostname}:${rank}: "` in PyTorch 2.14 puts the host on every log line too. ## What the numbers tell you | per-rank signal | likely cause | response | |---|---|---| | long forward, normal data wait | GPU thermal or power throttling, a weak GPU | drain the node | | long data wait, normal forward | slow storage path or a busy host CPU on that node | fix the node's input path or drain it | | normal forward and data, but every rank waits longer in collectives | a degraded network link or port | hand to network diagnosis | | long forward on different ranks each step | uneven sample lengths, not hardware | balance batches by token count | The last row matters: a rank that is slow because its batch holds the longest sequences moves around from step to step, and no node exclusion will help. ## Removing it from the job - **Slurm batch job:** wait for or trigger the next checkpoint, cancel, and resubmit with `sbatch --exclude=<node>` (or ask the administrators to drain the node). The job resumes from the checkpoint on healthy nodes. - **Elastic torchrun job (`--nnodes=MIN:MAX`):** stopping the straggler node's agent removes it; the survivors re-form the group without it and reload the last checkpoint, provided at least `MIN` nodes remain. - **Do not raise collective timeouts.** Nothing is timing out; a longer timeout only hides the next real hang. - **Do not shrink the slow rank's batch.** Under data parallelism every rank's gradient is weighted equally, so a smaller batch on one rank changes the training math rather than repairing the node. ## Keeping it from coming back Log per-rank timing permanently at low frequency, not only during an incident. A straggler that appears after a maintenance window, or one node whose forward time creeps up over days, can be drained before it costs a night of a 512-GPU run. A cheap standing check is to record the per-rank forward time every few hundred steps and alert when the slowest rank exceeds the median by a set margin, say 15%, for several consecutive samples. The margin keeps ordinary jitter quiet, and the consecutive-sample rule separates a degrading node from a single slow batch.

  • Why is the whole-step time per rank useless for finding a straggler?
    Because the step ends with collectives that release all ranks together, every rank reports roughly the same step time. The difference hides inside the collective as waiting on the fast ranks, so only the parts each rank does alone — data wait and forward compute — separate the slow rank from the rest.
  • The slow rank moves to a different rank every step. Is it still a hardware straggler?
    Probably not. A failing GPU or node stays slow on the same host. A slow rank that wanders usually means uneven work — batches with longer sequences landing on different ranks — and the fix is batching by token count, not excluding a node.

A convoy moves at the speed of its slowest truck: the fast trucks are not broken, they spend the trip braking, and you find the slow one by timing each truck alone, not the convoy.

  • A straggler always ends in a collective timeout error.
  • The straggler is the rank with the longest total step time.
  • Raising the process-group timeout fixes a slow rank.
  • Giving the slow rank a smaller batch is a safe fix.
  • A higher --max-restarts lets torchrun replace a slow worker automatically.

Assumes PyTorch 2.14, whose torchrun accepts --log-line-prefix-template with the ${hostname} and ${rank} macros.