Resilience¶
Long training runs die — preempted, NaN’d, a GPU falls off the bus. KempnerForge’s resilience module handles the recoverable failures so the run picks up from the last checkpoint instead of burning a re-submit.
Three failure modes the module addresses:
Preemption / manual stop — SLURM sends a termination signal, KempnerForge catches it, writes an emergency checkpoint, and exits.
Numerical blow-up — NaN / Inf loss or gradient norm detected; with the default
nan_action, optimizer step skipped and gradients zeroed. If it persists, stop so a human can roll back.Silent distributed hangs — periodic NCCL liveness ping detects a dead peer before the training loop deadlocks.
At a glance¶
Component |
Source |
Wired into |
|---|---|---|
|
|
always-on |
|
|
always-on; the handler’s forced-exit timeouts for |
|
|
always-on; |
|
|
opt-in via |
|
|
no — manual utility |
|
|
|
|
|
at checkpoint load time |
Everything in the first column is importable from
kempnerforge.resilience.
Config¶
[train]
# shutdown_timeout_sec = 90.0 # forced exit this long after a rank starts shutting down (0 = disabled);
# unset by default: a SIGTERM gets 3/4 of KEMPNERFORGE_SHUTDOWN_LEAD_SEC,
# else 600, and a SIGUSR1 600
nccl_health_check_interval = 0 # NCCL ping every N steps (0 = disabled)
nan_action = "warn" # on a NaN/Inf step: "warn" or "skip" (the loop skips it either way),
# or "raise" (every rank raises RuntimeError)
nan_max_consecutive = 10 # NaN/Inf steps in a row that stop the run for a manual rollback
Four knobs, all in [train]. The last two set the NaNDetector that
the training loop checks every step; see NaN detection.
SLURM launch¶
The reference preemption-resilient launch script is
scripts/slurm/7b_requeue.sh:
#SBATCH --signal=SIGTERM@120 # SIGTERM to the ranks before the time limit
#SBATCH --requeue # auto-resubmit on preempt
export KEMPNERFORGE_SHUTDOWN_LEAD_SEC="${KEMPNERFORGE_SHUTDOWN_LEAD_SEC:-120}" # the --signal lead
srun --kill-on-bad-exit=1 uv run python scripts/train.py "${CONFIG}"
The export tells the training process how long its ranks have after the
SIGTERM, so with train.shutdown_timeout_sec unset the forced-exit
timer fires at three quarters of it, before the time limit; see
SLURM preemption § Forced-exit timer.
Pair with a checkpoint interval of a few hundred steps (~1.5 hours for a 7B run on 16 H100s), so the emergency checkpoint never loses more than that.
Pages¶
See also¶
Checkpointing § Auto-resume — what a requeued job does on startup.
Training § Training loop — where
shutdown_handler.should_shutdown()andnan_detector.check_loss()are polled each step.Configuration §
[train]— the resilience-related config fields.