SLURM distributed setup¶
KempnerForge ships three SLURM launch scripts under
scripts/slurm/:
Script |
Launcher |
Scope |
|---|---|---|
|
|
1 node, N GPUs |
|
|
2+ nodes, N×M GPUs |
|
|
attach to |
This page explains when to use each, what environment the scripts assemble, and how preemption + auto-resume compose with them.
Single node: singlenode.sh¶
sbatch scripts/slurm/singlenode.sh configs/train/debug.toml \
--checkpoint.dir=checkpoints/debug_slurm
sbatch scripts/slurm/singlenode.sh configs/train/7b.toml \
--data.dataset_path=<your shards> --train.max_steps=1000
The script:
Reads
SLURM_GPUS_PER_NODE(default 4) to buildtorchrun --nproc_per_node=$NGPUSDetects the first UP InfiniBand interface (
ip -br addr) and exportsNCCL_SOCKET_IFNAME/GLOO_SOCKET_IFNAMEto itLaunches
torchrun --standaloneso there’s no rendezvous coordination needed (single-host)
Edit the header for your cluster:
#SBATCH --partition=<partition-name>
#SBATCH --account=<account-name>
#SBATCH --gpus-per-node=4
#SBATCH --time=24:00:00
<partition-name> and <account-name> are the values your PI gave you.
scripts/slurm/7b_requeue.sh needs a preemptible partition that requeues, and
both it and scripts/slurm/13b_validation.sh pin a GPU model through
#SBATCH --constraint=<gpu-type>, such as h200, h100 or a100.
Multi-node: multinode.sh¶
sbatch --nodes=4 scripts/slurm/multinode.sh configs/train/7b.toml \
--data.dataset_path=<your shards>
sbatch --nodes=8 scripts/slurm/multinode.sh \
configs/train/7b.toml --data.dataset_path=<your shards> --train.max_steps=50000
Two things make multi-node different from single-node on this codebase:
Launch method is
srundirect, nottorchrun. Each srun task is one process bound to one GPU. SLURM already setsSLURM_PROCID/SLURM_LOCALID/SLURM_NTASKS, andget_world_infomaps them toRANK/LOCAL_RANK/WORLD_SIZE. No torchrun in the loop.--ntasks-per-nodemust equal--gpus-per-node. This is the load-bearing invariant. Violate it and local rank maps incorrectly, processes land on the wrong GPU, and NCCL fails silently or crashes at first collective.
#SBATCH --nodes=2
#SBATCH --ntasks-per-node=4 # ← must match gpus-per-node
#SBATCH --gpus-per-node=4
#SBATCH --signal=SIGTERM@120 # SIGTERM to the srun ranks before the time limit
#SBATCH --requeue # auto-resubmit on preemption
The script then:
Extracts
MASTER_ADDRviascontrol show hostnames $SLURM_JOB_NODELIST | head -n 1Picks a random free port in
[15000, 20000]forMASTER_PORT(so two jobs on the same node don’t collide)Detects the first UP IB interface and binds both NCCL and Gloo to it
Exports
KEMPNERFORGE_SHUTDOWN_LEAD_SEC, the--signallead,120unless it is already set, so aSIGTERM’s forced-exit timer fires within it (see below)Launches
srun uv run python scripts/train.py $CONFIG
Why Gloo needs the same IB interface¶
Async DCP checkpointing uses a CPU-side Gloo process group for
coordination. Without GLOO_SOCKET_IFNAME pointed at the IB
interface, Gloo falls back to the management Ethernet (em4 on
Kempner nodes), which is on a different subnet, so peer connections
time out and the checkpoint never completes.
NCCL environment the script sets¶
NCCL_SOCKET_IFNAME=ib0 # OOB bootstrap + socket transport
NCCL_IB_DISABLE=0 # enable IB verbs transport
NCCL_NET_GDR_LEVEL=2 # GPU-direct RDMA
NCCL_IB_GID_INDEX=3 # H100/H200 fabric config
GLOO_SOCKET_IFNAME=ib0
NCCL_IB_GID_INDEX=3 is specific to the RoCE/IB fabric on Kempner
H100/H200 nodes. On other clusters this may need to be 0 or 1; check
with your admins or ibv_devinfo.
No environment variable bounds a hung collective: neither NCCL nor
PyTorch reads NCCL_TIMEOUT. distributed.nccl_timeout_sec (default
1800 seconds) is the timeout of the default process group and of the
group of every mesh dimension (TP, PP, EP, HSDP). Set it in the config or
with --distributed.nccl_timeout_sec=<seconds>.
Interactive / existing allocation: interactive.sh¶
When you already have an allocation (salloc or a queued job) and
want to attach training to it without a new sbatch:
# Pass the JOBID of the existing allocation, then the config:
bash scripts/slurm/interactive.sh 3565401 configs/train/debug.toml
bash scripts/slurm/interactive.sh 3565401 configs/train/7b.toml \
--data.dataset_path=<your shards> --train.max_steps=50
The script resolves NODELIST / MASTER_ADDR via squeue -j $JOBID
and scontrol show hostnames, auto-detects the IB interface, then
dispatches srun --jobid=$JOBID with --ntasks-per-node=$GPUS_PER_NODE.
Useful for debugging on a reserved node without going through the
queue again.
Preemption, SIGTERM, auto-resume¶
The full mechanics live in Resilience § SLURM preemption; the short version:
#SBATCH --signal=SIGTERM@120tells SLURM to sendSIGTERMto every job step, that is, to everysrun-launched rank, 120 to 180 seconds before the time limit. The batch shell is not signaled.singlenode.shhas no job step, so it keeps--signal=B:SIGTERM@120(batch shell only) and forwards oneSIGTERMtouv run torchrunfrom atrap; see Resilience § SLURM preemption.The training loop’s
ShutdownHandlercatches SIGTERM, flipsshould_shutdown()toTrue, and the step loop writes an emergency DCP checkpoint before exiting cleanly.#SBATCH --requeueputs a preempted job back in the queue. When it starts again,CheckpointManagerfollows thelatestsymlink incheckpoint.dirand resumes at the exact step / sample.
The 120-second window is a design parameter: the step in flight and the
emergency checkpoint must finish within it, and with the default
forced-exit timer within three quarters of it, 90 seconds. At the time
limit the ranks get SIGTERM again and may be killed at once rather
than after KillWait, so plan for the save to finish before the timer
fires. Async DCP
save times depend on model size, FSDP degree, and filesystem, so measure
them on your cluster with checkpoint.async_mode = "async" and a test run
before trusting the default for 70B+. If your save consistently overruns,
raise #SBATCH --signal=SIGTERM@<seconds> accordingly, and set
KEMPNERFORGE_SHUTDOWN_LEAD_SEC=<seconds> with it, in the script or in
the environment you submit from, since the script keeps a value already
set: the forced-exit timer defaults to three quarters of that lead, so a hung
save ends in its own Graceful shutdown timed out log line before the
limit rather than in SLURM’s kill. Under singlenode.sh, torchrun
gives its workers its shutdown timeout after the signal, 30 seconds by
default, whatever the lead, and the script always exports 30 to match, so the
forced exit fires at 22.5 seconds. On torch 2.14, the version the lock
file pins, torchrun --shutdown-timeout or TORCH_ELASTIC_SHUTDOWN_TIMEOUT
raises that timeout; raise the script’s export with it. The script sets
neither, since neither is confirmed on torch 2.12 and 2.13, the oldest
that pyproject.toml allows.
Auto-resume in practice¶
With --requeue set, you can monitor a preempted-and-restarted job:
squeue -j <jobid> # see current state
sacct -j <jobid> --format=JobID,State,ExitCode,Start,End
scontrol show job <jobid> | grep RestartCount
On first launch, SLURM_RESTART_COUNT is 0; after a requeue it
increments. The script echoes this so the log makes it obvious:
Restart cnt: 2
If you see rising restart counts but training never crosses step
eval_interval, something is preempting the job faster than it can
checkpoint. Lower checkpoint.interval: a preempted job gets no
--signal lead on a partition without a preemption grace time, so the
periodic checkpoints are what it resumes from.
Checking the launch worked¶
First time you run on a new cluster, verify:
All ranks start: the script’s banner line should print once per rank, and rank 0 log should show
world_size = N × M.NCCL talks over IB: set
NCCL_DEBUG=INFOin the script once to see the negotiated transport. Each rank should logNET/IB(notNET/Socket).First all-reduce succeeds: rank 0 reports model build and step 1 loss within a minute or two. A multi-minute hang at step 1 usually means Gloo is on the wrong interface (DCP init fails) or IB GID is wrong.
If step 1 hangs, kill the job and re-run with:
export NCCL_DEBUG=INFO
export TORCH_DISTRIBUTED_DEBUG=DETAIL
What the SLURM scripts don’t do¶
Tokenizer caching: you still need to pre-cache HuggingFace tokenizers on a login node (compute nodes are usually air-gapped). See Prepare tokenized data § Cache the tokenizer first.
Data staging:
configs/train/*.tomlexpects your dataset atdata.dataset_path. Pre-copy or symlink beforesbatch.Env mounts: the scripts assume
uv run pythonresolves the repo’s.venv. If your cluster uses different mount points, edit theuv runlines.
See also¶
Resilience § SLURM preemption: the full
ShutdownHandlertimeline and SLURM requeue dance.Distributed § DeviceMesh: how
init_distributedturns rank info into a mesh.End-to-end training run: runs through the single-node path before this page scales it.
Scaling guide: which parallelism combo to pick at each GPU count; this page tells you how to launch it.
scripts/slurm/multinode.sh: the reference script this page documents.