skip to content

Job Launch & Fault Tolerance

Slurm, Ray Train and torchrun's elastic rendezvous launch multi-node jobs, and Distributed Checkpoint lets them resume after a node dies. Interviewers ask what happens when a node fails at hour 40.

on this pageshow

questions

6

With PyTorch's torchrun and --max-restarts=3, what is actually restarted when one worker on one node crashes, and what must the training script do?

level: middleimportance: must knowfreq 18%

answer

  1. the whole group, not one process
  2. default is zero restarts
  3. every node re-enters the rendezvous
  4. RANK may change after a restart
  5. load the latest checkpoint at startup

basics

~20 s

torchrun stops every worker in the job and reruns the script on all nodes after a fresh rendezvous, up to --max-restarts times (default 0). The script must load its latest checkpoint at startup, or it starts again from step zero.

solid answer

~40 s

In PyTorch 2.14, torchrun runs one elastic agent per node that supervises that node's workers. When a worker exits with an error, its agent stops all its local workers, spends one of its `--max-restarts` (default `0`, so by default the job just fails) and re-enters the rendezvous; agents on healthy nodes see a node waiting, stop their own workers and rejoin, and that membership-driven restart does not spend their budget. Every worker then runs the script again from the top with the same arguments and freshly assigned `RANK` and `WORLD_SIZE`; `TORCHELASTIC_RESTART_COUNT` says which attempt it is. Nothing in memory survives, so the script must load the latest complete checkpoint before training and save often enough that the lost work is acceptable. The docs' fault-tolerant recipe uses `--rdzv-backend=c10d` with a shared `--rdzv-endpoint` and `--rdzv-id`.

go deeper

for a junior

Remember that torchrun restarts the whole worker group, that it does not restart anything by default, and that the script must resume from a checkpoint.

for a middle

Walk through the agent loop: failure detected, budget spent, re-rendezvous, new ranks, script rerun from the top, and which flags set each step.

for a senior

Show how membership changes differ from failures, why ranks must not be cached, and when restarts burn out on a deterministic bug so the outer scheduler must take over.

for a principal

Decide how much retry lives in torchrun versus the cluster scheduler, and how that choice interacts with checkpoint cadence and on-call load.

## Two layers: the agent and its workers `torchrun` is PyTorch's elastic launcher. On each node it starts an **agent** process, and the agent spawns `--nproc-per-node` **workers**, one per GPU, each running your training script. The agents of all nodes meet in a **rendezvous**: a shared key-value store (with `--rdzv-backend=c10d`, hosted at `--rdzv-endpoint`) where they agree on who is in the job and hand out ranks. The agent, not the worker, owns fault tolerance: it watches its workers every `--monitor-interval` seconds and decides whether to restart them. ## What happens when one worker crashes Suppose a job runs on 8 nodes with `--max-restarts=3` and a worker on node 5 dies from a CUDA error at hour 40: 1. Node 5's agent sees a failed worker, stops **all** of its local workers and, because it still has restarts left, spends one (3 -> 2). 2. It re-enters the rendezvous, which opens a new round. 3. The agents on the other seven nodes notice a node waiting, stop their own healthy workers and rejoin. This path is a **membership change**, and the PyTorch 2.14 agent does not charge it to their restart budget. (If their workers had already crashed on a broken collective, that crash counts as their own failure.) 4. The new round assigns fresh `RANK`, `LOCAL_RANK`, `GROUP_RANK` and `WORLD_SIZE` values, and every worker starts the script **from the top with the same arguments**. 5. If node 5's agent has no restarts left, it stops its workers and exits with the failure instead, and the job ends. The default is `--max-restarts=0`: without the flag, the first worker error ends the job. A worker that the NCCL watchdog tears down after a collective times out counts like any other crash here; why the collective hung is a separate diagnosis. ## Nodes joining and leaving With `--nnodes=MIN:MAX` (for example `--nnodes=4:8`) the job is **elastic**: - The rendezvous completes once `MIN` nodes have joined, after waiting `last_call_timeout` (30 s by default) for more, and gives up if `MIN` is not reached within `join_timeout` (600 s by default); both are set through `--rdzv-conf`. - A node that **arrives** while the group is healthy makes every agent stop its workers and re-form the group with new ranks; this costs no restart. - A node that **dies** takes its agent with it; the survivors' workers fail on their next collective, each surviving agent spends a restart, and the group re-forms with fewer nodes as long as at least `MIN` remain. ## What the script must do - **Load first, train second.** The documented structure is `load_checkpoint()`, then `init_process_group()`, then the loop. Anything since the last complete checkpoint is lost on every restart. - **Never hard-code ranks.** The torchrun docs state that `RANK` is not stable across restarts, and with elasticity `WORLD_SIZE` can change too; read both from the environment each time. - **Make side effects restart-safe.** A restart replays the steps since the checkpoint, so per-step logging or output files must tolerate being written twice. - **Decorate the entry point with `@record`** (from `torch.distributed.elastic.multiprocessing.errors`) so the agent's failure summary includes the worker's traceback, not just its exit code. ## The settings at a glance | flag | default in PyTorch 2.14 | effect | |---|---|---| | `--max-restarts` | `0` | worker-group restarts per agent before the job fails | | `--nnodes` | `1:1` | a single number is fixed; `MIN:MAX` is elastic | | `--rdzv-backend` | `static` | `c10d` is the recommended backend for multi-node and elastic jobs | | `--rdzv-endpoint` | empty | host:port of the rendezvous; the port defaults to 29400 when omitted | | `--rdzv-id` | `none` | must be the same unique id on every node | ## Where restarts stop helping Restarts absorb transient faults: a flaky GPU, a dropped link, a node that comes back. They do not fix a deterministic bug, which simply burns the budget three times in a row, and they cannot bring back a node that is gone when the job is not elastic. That is where the outer scheduler takes over, for example a Slurm batch job submitted with `--requeue`, starting the whole launch again from the same checkpoint directory. Two habits make the budget meaningful. Size it to the faults you expect within one allocation — a handful, not dozens — so a crash loop ends quickly and pages someone. And log `TORCHELASTIC_RESTART_COUNT` at startup and alert when it rises: a job that restarts every few hours is still running, but it is paying the rework cost each time.

  • How can the script tell that it is running after a restart rather than on the first attempt?
    torchrun sets `TORCHELASTIC_RESTART_COUNT` (restarts so far) and `TORCHELASTIC_MAX_RESTARTS` in every worker's environment. The script can log the attempt number, but it should resume from whatever checkpoint exists regardless, because a fresh submission after a requeue starts at count 0 too.
  • Why does the failed node's agent stop its healthy local workers as well, not just the one that crashed?
    The workers form one process group with fixed ranks; a single replacement process cannot rejoin collectives that the others are already blocked in. torchrun therefore tears down the whole local group and re-forms the job through a new rendezvous, which is also what lets ranks and world size change.
  • A job keeps failing at the same step and exhausts --max-restarts within minutes. What does that tell you?
    The fault is deterministic — a bad batch, a shape bug, an out-of-memory at a fixed point — not a transient hardware error. More restarts will not help; read the `@record` traceback from the first failing rank and fix the cause.

  • torchrun restarts only the worker that crashed and keeps the others running.
  • torchrun retries failed workers a few times by default.
  • After a restart each worker keeps the same RANK it had before.
  • The training state in GPU memory survives a torchrun restart.
  • A node joining an elastic job uses up one of the restarts.

Assumes PyTorch 2.14: --max-restarts defaults to 0, --rdzv-backend defaults to static, and membership changes are not charged to the restart budget.

open as a page

On a Slurm cluster, when do you launch a 64-node PyTorch job as one torchrun per node versus one srun task per GPU?

level: middleimportance: should knowfreq 14%

basics

~20 s

Run one torchrun per node (srun --ntasks-per-node=1) when you want torchrun's c10d rendezvous and in-place restarts; run one srun task per GPU (--ntasks-per-node=8) when Slurm should own every process and you map SLURM_PROCID and SLURM_LOCALID to ranks yourself.

open as a page

A 512-GPU PyTorch run saved with torch.distributed.checkpoint must resume on 256 GPUs after half the cluster goes down — how does the load work, and what else must change?

level: seniorimportance: should knowfreq 9%

basics

~20 s

Distributed Checkpoint reshards at load time: build and shard the model for 256 ranks, call dcp.load, and each rank reads only the saved chunks overlapping its new shards. Global batch, data position and per-rank RNG state are yours to adjust.

open as a page

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%

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.

open as a page

How do you choose the checkpoint interval for a month-long 512-GPU pretraining run that loses a node every few days, and what does PyTorch's DCP async_save change?

level: principalimportance: should knowfreq 8%

basics

~20 s

Balance each save's blocking time against the work lost per failure: an interval near sqrt(2 x blocking cost x mean time between failures) minimises the sum. DCP async_save shrinks the blocking cost to a CPU staging copy, allowing far more frequent saves.

open as a page

In Ray Train 2.59, how do ScalingConfig and FailureConfig decide how many workers a TorchTrainer runs and how many failures it survives?

level: middleimportance: nice to knowfreq 7%

basics

~20 s

ScalingConfig sets the worker group: num_workers (an int, or a (min, max) tuple for elastic runs), use_gpu and resources_per_worker. FailureConfig(max_failures), default 0, sets how many failures Ray Train recovers from by restarting every worker from the latest reported checkpoint.

open as a page