Accelerate on Slurm Spawns Duplicate GPU Ranks Fix
Stop Hugging Face Accelerate on Slurm from spawning double worker processes per node by auditing SLURM_NTASKS, LOCAL_RANK, and single-launcher configs.
Launching accelerate launch inside srun with --ntasks-per-node=8 creates 64 worker processes on an 8-GPU node because Slurm starts 8 tasks and each Accelerate launcher spawns 8 more local processes. Let exactly ONE orchestrator spawn per-GPU processes: set --ntasks-per-node=1 for accelerate launch, or invoke Python directly per task under srun.
- Symptom
[srun task 0] SLURM_PROCID=0 SLURM_LOCALID=0 launching accelerate --num_processes=8 -> spawning 8 workers (local_rank 0..7) [srun task 1] SLURM_PROCID=1 SLURM_LOCALID=1 launching accelerate --num_processes=8 -> spawning 8 workers (local_rank 0..7) [node04:pid=91824] torch.OutOfMemoryError: CUDA out of memory on GPU 0 (2 competing training processes bound to cuda:0)- Root cause
- Nested process fan-out from setting per-GPU Slurm tasks (--ntasks-per-node=GPUS) alongside a local multi-process launcher (accelerate launch).
- Recommended fix
- Print SLURM_JOB_NUM_NODES, SLURM_NTASKS, SLURM_PROCID, SLURM_LOCALID, RANK, and LOCAL_RANK at startup to see whether srun or Accelerate spawned the extra workers.
- How Denpex helps
- Denpex investigates Accelerate on Slurm Spawns Duplicate GPU Ranks Fix using the evidence you provide or your connected workload collects. Earlier rank, host or application evidence is needed to distinguish an initiating failure from a downstream report.
What this failure is
A nested distributed launcher collision where both Slurm srun and Hugging Face Accelerate fan out local GPU worker trees simultaneously.
Is this what broke your run? Paste your log.
You're reading about Accelerate on Slurm Spawns Duplicate GPU Ranks Fix. Paste your own traceback and relevant evidence for an investigation of your workload, with a next action or a specific missing fact. A reference entry does not establish your cause. No account or card for the free diagnosis. Review data handling before submitting sensitive logs.
Before uploading, review cloud data handling and local options.
Upload your log file. Large files are processed in your browser. Only selected evidence is submitted when you run diagnosis.
Why it happens (the mechanism)
Users combine #SBATCH --ntasks-per-node=8 (which tells srun to fork 8 tasks per node) with srun accelerate launch --num_processes=8 (which tells each task to fork 8 local GPU workers). Every GPU then receives multiple competing processes colliding on cuda:0, NCCL ports, or OOM.
What you'll observe
- nvidia-smi shows 16 or 64 python processes packed onto an 8-GPU node with immediate CUDA OOM
- Duplicate LOCAL_RANK=0 processes log Address already in use or fail NCCL initialization
Common symptoms and what they mean
Check possible explanations against the incident evidence. A matching symptom alone does not establish its cause.
| Symptom | Possible explanation |
|---|---|
| Multiple processes print RANK=0 LOCAL_RANK=0 on the same node in Slurm stdout | Nested process fan-out from setting per-GPU Slurm tasks (--ntasks-per-node=GPUS) alongside a local multi-process launcher (accelerate launch). |
| CUDA out of memory or C10d Address already in use right after srun launch | Nested process fan-out from setting per-GPU Slurm tasks (--ntasks-per-node=GPUS) alongside a local multi-process launcher (accelerate launch). |
Which systems are affected
- Hugging Face Accelerate, Transformers Trainer, and torchrun launched under Slurm srun
- Multi-node Slurm GPU clusters (A100, H100, B200)
How to confirm this is the problem
Use this checklist to test the hypothesis against a small reproduction. No single line proves the root cause, so preserve the preceding events and compare one variable at a time.
- ✓Verify nvidia-smi shows one Python PID per allocated GPU (8 PIDs on an 8-GPU node) and WORLD_SIZE equals total cluster GPUs.
Root cause
- Nested process fan-out from setting per-GPU Slurm tasks (--ntasks-per-node=GPUS) alongside a local multi-process launcher (accelerate launch).
The fix and how to prevent it
How to fix it
- Print SLURM_JOB_NUM_NODES, SLURM_NTASKS, SLURM_PROCID, SLURM_LOCALID, RANK, and LOCAL_RANK at startup to see whether srun or Accelerate spawned the extra workers.
- Pattern A (recommended for Accelerate/torchrun): request #SBATCH --ntasks-per-node=1 --gpus-per-node=8 --cpus-per-task=..., then run srun accelerate launch --num_machines=$SLURM_NNODES --num_processes=$((SLURM_NNODES*8)) --machine_rank=$SLURM_NODEID --main_process_ip=... --main_process_port=29500 train.py.
- Pattern B (pure Slurm srun): keep --ntasks-per-node=8 and run srun python3 train.py directly with environment rank mapping instead of wrapping accelerate launch.
Step-by-step remediation
- 1Log SLURM_NTASKS, SLURM_PROCID, RANK, and LOCAL_RANK to confirm duplicate spawning.
- 2Change #SBATCH --ntasks-per-node to 1 when invoking accelerate launch across nodes.
- 3Inspect nvidia-smi on an allocated node to confirm 1 process per GPU and clean WORLD_SIZE.
How to prevent it
- Standardize sbatch templates so ntasks-per-node equals 1 whenever wrapping torchrun or accelerate launch
- Assert exact process count per host before entering distributed model loading
Save this diagnosis and catch the next crash automatically
All root cause, fix, and prevention steps above are free to read. Create a free account with any email or GitHub to keep your saved diagnosis history across the encyclopedia and run cloud checks, or use a work email below for the 30-day Team evaluation. No card required.
Or start a 30-day free Team trial (work email)
Verified work email unlocks all 14 fleet diagnostic tools, Slack alerts, and team history for 30 days. No card and no automatic charge.
Searchable error signature
[srun task 0] SLURM_PROCID=0 SLURM_LOCALID=0 launching accelerate --num_processes=8 -> spawning 8 workers (local_rank 0..7)
[srun task 1] SLURM_PROCID=1 SLURM_LOCALID=1 launching accelerate --num_processes=8 -> spawning 8 workers (local_rank 0..7)
[node04:pid=91824] torch.OutOfMemoryError: CUDA out of memory on GPU 0 (2 competing training processes bound to cuda:0)Use this text as a lookup key in logs and upstream issue trackers. It is not presented as a captured customer log. Confirm the cause from your own preceding events, versions, configuration and the cited references.
Diagnose your own log automatically
The root cause and fix steps above stay free. Create a free account to analyze full job logs, attribute the first failed rank, and keep saved incident history.
Sign up free. Analyze your cluster logsNo credit card. Daily allowance follows verified trust tier. Instant access.
Why the recommended fix works
Setting --ntasks-per-node=1 restricts srun to one coordinator per node so Accelerate handles local rank fan-out exactly once per GPU.
Code examples
# Option A: 1 Slurm task per node, Accelerate spawns GPU workers
#SBATCH --nodes=2
#SBATCH --ntasks-per-node=1
#SBATCH --gpus-per-node=8
srun accelerate launch \
--num_machines=$SLURM_NNODES \
--num_processes=$((SLURM_NNODES * 8)) \
--machine_rank=$SLURM_NODEID \
--main_process_ip=$(scontrol show hostnames $SLURM_JOB_NODELIST | head -n1) \
--main_process_port=29500 \
train.pyThis snippet illustrates the entry-specific check. Verify the installed versions, permissions, target and workload context before using it. A command or API example is not proof of recovery.
Best practices by model family
| Model / Stack | Recommendation | Notes |
|---|---|---|
| Using accelerate launch / torchrun | Set #SBATCH --ntasks-per-node=1 | One controller task per host lets the launcher spawn 1 worker per GPU. |
| Using raw python under srun | Set #SBATCH --ntasks-per-node=8 without accelerate launch | Requires reading SLURM_PROCID/SLURM_LOCALID into env vars. |
With the fix vs without the fix
| Dimension | With the fix | Without the fix |
|---|---|---|
| Process ownership | Single spawner per level (ntasks-per-node=1 + accelerate launch) | Both ntasks-per-node=8 and accelerate launch spawning workers (8x8=64) |
| GPU isolation | 1 Python PID per GPU UUID | Multiple rank-0 collisions on cuda:0 and port 29500 |
Diagnostic note
“This multiplicative fan-out is silent at low log verbosity: job scripts often blame GPU memory capacity after switching frameworks when ntasks-per-node=8 quietly multiplied worker count by 8.”
Diagnose this failure in VS Code
Select the traceback or open the failed terminal, then run Denpex locally to inspect matched failure patterns, supporting evidence and next checks without uploading the log. Verify recommendations against your workload before changing production.
Install the free VS Code extensionSlurm GPU errors in context
Slurm GPU failures can occur before allocation, during cgroup creation or inside the workload. The hub joins job reason, GRES, memory, node-health and distributed-launch evidence.
Compare related slurm gpu errorsRelated failures to investigate next
Frequently asked questions
Questions engineers and on-call staff commonly ask about this failure.
Why does nvidia-smi show 16 or 64 processes when I requested 8 GPUs in Slurm?
Should I fix this by lowering batch size?
Don't just read the fix, diagnose your run
The encyclopedia explains documented failure patterns. Denpex investigates your logs, configuration and stack, shows the supporting evidence, and asks for missing details when needed.