高端營銷網站泰州百度公司代理商
Unexpected error from cudaGetDeviceCount 錯誤解決
- 0. 背景
- 1. 解決方法
0. 背景
新配置了1臺服務器,有4張4090顯卡。
在 wsl-ubuntu 里執(zhí)行 python -c “import torch;print(torch.cuda.is_available());” 命令時,會報以下錯誤。
/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 也能正常輸出結果。
網上查了很多文章,大部分都是說重啟就解決了,或者說 cuda 和 pytorch 版本不符等需要安裝同一版本之類的。
我的另外一臺電腦,也是同樣安裝的,所以個人分析不是上面問題。
1. 解決方法
后來從是不是4張4090顯卡需要什么特殊設置這個角度,有查了很多文章,后來終于通過設置,
CUDA_DEVICE_ORDER="PCI_BUS_ID" CUDA_VISIBLE_DEVICES=0,4 python -c "import torch;print(torch.cuda.is_available());"
得到了正確的輸出,
True
完結!