Expected all tensors to be on the same device, but found at least two devices, cuda:3

我是在linux系统下的RTX3090,多显卡下训练的。此时有两个显卡空着所以报错如下:
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:3

解决方案:

先用命令:nvidia-smi查询空闲的显卡
Expected all tensors to be on the same device, but found at least two devices, cuda:3_第1张图片
可以看出0号是空闲的,看最左边的号码。

所以,运行代码时使用如下命令:

CUDA_VISIBLE_DEVICES=0 python3 main.py

成功运行:
Expected all tensors to be on the same device, but found at least two devices, cuda:3_第2张图片

tips:

linux中退出命令行的命令如下:

1.Ctrl+c

2.Ctrl+d

3.Ctrl+x

4.exit 或者exit()

我经常在运行过程中不小心用了第一种,然后代码运行就中断了,提示:
KeyboardInterrupt

你可能感兴趣的:(linux)