Unexpected error from cudaGetDeviceCount 错误解决

Unexpected error from cudaGetDeviceCount 错误解决

  • [0. 背景](#0. 背景)
  • [1. 解决方法](#1. 解决方法)

0. 背景

新配置了1台服务器,有4张4090显卡。

在 wsl-ubuntu 里执行 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

执行 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

完结!

相关推荐
ZhengEnCi7 小时前
05-自注意力机制详解 🧠
人工智能·pytorch·深度学习
xier_ran14 小时前
【BUG问题】5060Ti显卡Windows配置Anaconda中的CUDA及Pytorch,sm_120问题
人工智能·pytorch·windows
郝学胜-神的一滴17 小时前
深度学习损失函数:从原理到实战之 Smooth L1 Loss
人工智能·pytorch·python·深度学习·机器学习·数据挖掘
MATLAB代码顾问1 天前
Transformer时序预测:PatchTST原理与PyTorch实现
pytorch·深度学习·transformer
fpcc2 天前
并行编程实战——异步编程的屏障的整体分析
人工智能·cuda
EnCi Zheng2 天前
04-缩放点积注意力代码实现 [特殊字符]
人工智能·pytorch·python
β添砖java2 天前
深度学习(17)卷积层里的多输入多输出通道
人工智能·pytorch·深度学习
江南十四行3 天前
CNN进阶:Batch Normalization与Layer Normalization对比 + 网络结构设计与PyTorch实现
pytorch·cnn·batch
早日退休!!!3 天前
PyTorch适配NPU
人工智能·pytorch·python
盼小辉丶3 天前
PyTorch强化学习实战——构建生成对抗网络生成Atari游戏画面
pytorch·游戏·生成对抗网络