高端營(yíng)銷網(wǎng)站泰州百度公司代理商
Unexpected error from cudaGetDeviceCount 錯(cuò)誤解決
- 0. 背景
- 1. 解決方法
0. 背景
新配置了1臺(tái)服務(wù)器,有4張4090顯卡。
在 wsl-ubuntu 里執(zhí)行 python -c “import torch;print(torch.cuda.is_available());” 命令時(shí),會(huì)報(bào)以下錯(cuò)誤。
/root/miniconda3/envs/chatglm3-demo/lib/python3.10/site-packages/torch/cuda/__init__.py:107: UserWarning: CUDA initialization: Unexpected error from cudaGetDeviceCount(). Did you run some cuda functions before calling NumCudaDevices() that might have already set an error? Error 2: out of memory (Triggered internally at ../c10/cuda/CUDAFunctions.cpp:109.)return torch._C._cuda_getDeviceCount() > 0
False
執(zhí)行 nvidia-smi 也能正常輸出結(jié)果。
網(wǎng)上查了很多文章,大部分都是說(shuō)重啟就解決了,或者說(shuō) cuda 和 pytorch 版本不符等需要安裝同一版本之類的。
我的另外一臺(tái)電腦,也是同樣安裝的,所以個(gè)人分析不是上面問(wèn)題。
1. 解決方法
后來(lái)從是不是4張4090顯卡需要什么特殊設(shè)置這個(gè)角度,有查了很多文章,后來(lái)終于通過(guò)設(shè)置,
CUDA_DEVICE_ORDER="PCI_BUS_ID" CUDA_VISIBLE_DEVICES=0,4 python -c "import torch;print(torch.cuda.is_available());"
得到了正確的輸出,
True
完結(jié)!