【发布时间】:2019-08-26 22:36:09
【问题描述】:
我们正在使用 SLURM 来管理一个小型本地集群。我们管理的一个关键资源是 GPU。当用户通过 --gpus=2 请求 GPU 时,CUDA_VISIBLE_DEVICES 环境变量会设置为 SLURM 分配给用户的 GPU。
$ srun --gpus=2 bash -c 'echo $CUDA_VISIBLE_DEVICES'
0,1
我们有一个小团队,可以相信我们的用户不会滥用系统(他们很容易覆盖环境变量),所以这很有效。但是,意外绕过这个有点太容易了,因为当未指定 --gpus 时,$CUDA_VISIBLE_DEVICES 未设置,因此用户可以使用任何 GPU(我们通常使用 PyTorch)。
换句话说,以下命令可以正常工作(只要它位于 GPU 节点上),但我希望它失败(因为没有请求 GPU)。
srun sudo docker run -e CUDA_VISIBLE_DEVICES --runtime=nvidia pytorch/pytorch:1.1.0-cuda10.0-cudnn7.5-runtime python -c 'import torch; print(torch.tensor([1., 2.], device=torch.device("cuda:0")))'
如果将$CUDA_VISIBLE_DEVICES 设置为-1,它将失败。
$ CUDA_VISIBLE_DEVICES=-1 sudo docker run -e CUDA_VISIBLE_DEVICES --runtime=nvidia pytorch/pytorch:1.1.0-cuda10.0-cudnn7.5-runtime python -c 'import torch; print(torch.tensor([1., 2.], device=torch.device("cuda:0")))'
THCudaCheck FAIL file=/opt/conda/conda-bld/pytorch_1556653099582/work/aten/src/THC/THCGeneral.cpp line=51 error=38 : no CUDA-capable device is detected
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/opt/conda/lib/python3.6/site-packages/torch/cuda/__init__.py", line 163, in _lazy_init
torch._C._cuda_init()
RuntimeError: cuda runtime error (38) : no CUDA-capable device is detected at /opt/conda/conda-bld/pytorch_1556653099582/work/aten/src/THC/THCGeneral.cpp:51
如果未指定 --gpus,如何配置 SLURM 以将 CUDA_VISIBLE_DEVICES 设置为 -1?
【问题讨论】:
-
可能,你最好的方法是有不同的分区,因为你想要做的修改意味着调整代码并重新编译 Slurm。