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

完结!

相关推荐
artificiali12 小时前
Anaconda配置pytorch的基本操作
人工智能·pytorch·python
程序员小川12 小时前
Ubuntu22.04安装paddle
ai·cuda·paddle·cudnn
#include<菜鸡>14 小时前
动手学深度学习(pytorch土堆)-04torchvision中数据集的使用
人工智能·pytorch·深度学习
chnyi6_ya15 小时前
深度学习的笔记
服务器·人工智能·pytorch
安逸sgr16 小时前
1、CycleGAN
pytorch·深度学习·神经网络·生成对抗网络
繁依Fanyi1 天前
828 华为云征文|华为 Flexus 云服务器部署 RustDesk Server,打造自己的远程桌面服务器
运维·服务器·开发语言·人工智能·pytorch·华为·华为云
徳一1 天前
【pytorch学习笔记,利用Anaconda安装pytorch和paddle深度学习环境+pycharm安装---免额外安装CUDA和cudnn】
pytorch·深度学习·学习
#include<菜鸡>1 天前
动手学深度学习(pytorch土堆)-05-1神经网络
pytorch·深度学习·神经网络
zhangfeng11331 天前
在 PyTorch 中,除了 pad_sequence 还有哪些其他处理序列数据的函数?时间序列数据 预处理
人工智能·pytorch·python·深度学习
Linux猿2 天前
Pytorch Lightning框架
人工智能·pytorch·python