Fall back to first visible GPU when local rank exceeds device count - #3843
rishabhsai wants to merge 1 commit into
Conversation
…e device count Running under `srun --ntasks-per-gpu=1` gives each task a single visible GPU while SLURM_LOCALID still counts tasks on the node, so `torch.cuda.set_device` gets an index that does not exist and every task with a local rank above 0 dies during `idist.initialize`. Use the first visible device in that case and pass the same index to DistributedDataParallel in `auto_model` so it matches `idist.device()`. Fixes pytorch#3259
|
@rishabhsai can you check your PR with on SLURM and first repro the issue and then check the fix? |
|
Haven't been able to get on a multi-GPU machine yet, so I haven't reproduced the original failure end to end. The unit test covers the device-index logic (it fakes the visible device count and fails on I'll follow up when I have access, or happy for you to take it from here if that's faster. One question in the meantime: I can reproduce the same condition on a two-GPU box by setting the SLURM env vars ignite reads with one GPU visible per process, which hits the same |
|
The original issue is with slurm, so first we need to understand in very detail the problem with the config described in the issue and reproduce it on slurm. Next, propose a change that wont break current behavior (with and without slurm) and once approved finally implement it. |
that makes sense, will do! thanks! |
Fixes #3259
Description:
Launching with
srun --ntasks-per-gpu=1 --nodes=2 --gpus-per-node=4gives each task a single visible GPU, butSLURM_LOCALIDkeeps counting tasks on the node, soidist.initialize("nccl")reachestorch.cuda.set_device(3)in a process that can only see device 0 and every task with a local rank above 0 dies.ignite/distributed/comp_models/native.pynow uses the first visible device when the local rank is not a valid device index, which is the fallback suggested in this issue, anddevice()stops warning about the mismatch in that case.auto_modelpasses the current CUDA device toDistributedDataParallelinstead of the local rank, sodevice_idsstays consistent withidist.device(), which is the device the model was already moved to. This was checked with a unit test that fakes the visible device count and with the existing distributed test suites on CPU, not on a real Slurm cluster.Check list: