常用写法
常用写法
CUDA_VISIBLE_DEVICES=2 nvidia-smi # 只看物理 2 号卡
CUDA_VISIBLE_DEVICES=0,3 python run.py # 物理 0/3 映射为逻辑 0/1
CUDA_VISIBLE_DEVICES=GPU-xxxx python run.py # 按 UUID 固定映射获取 UUID 并核对
获取 UUID 并核对
nvidia-smi -L # 输出形如 GPU 0: ... (UUID: GPU-xxxx)
CUDA_VISIBLE_DEVICES=1 python -c "import torch; print(torch.cuda.device_count())"变量在进程启动时读取,运行中修改无效;子进程会继承父进程的可见集合,在目标执行环境里用 nvidia-smi -L 核对更直接。