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

完结!

相关推荐
贝塔西塔12 小时前
PytorchLightning最佳实践基础篇
pytorch·深度学习·lightning·编程框架
小猪和纸箱13 小时前
通过Python交互式控制台理解Conv1d的输入输出
pytorch
墨染枫19 小时前
pytorch学习笔记-使用DataLoader加载固有Datasets(CIFAR10),使用tensorboard进行可视化
pytorch·笔记·学习
九章云极AladdinEdu1 天前
GitHub新手生存指南:AI项目版本控制与协作实战
人工智能·pytorch·opencv·机器学习·github·gpu算力
z are1 天前
PyTorch 模型开发全栈指南:从定义、修改到保存的完整闭环
人工智能·pytorch·python
点云SLAM2 天前
Pytorch中cuda相关操作详见和代码示例
人工智能·pytorch·python·深度学习·3d·cuda·多gpu训练
mpr0xy2 天前
编译支持cuda硬件加速的ffmpeg
ai·ffmpeg·nvidia·cuda
cwn_2 天前
Sequential 损失函数 反向传播 优化器 模型的使用修改保存加载
人工智能·pytorch·python·深度学习·机器学习
老鱼说AI2 天前
Transformer Masked loss原理精讲及其PyTorch逐行实现
人工智能·pytorch·python·深度学习·transformer
空中湖2 天前
PyTorch武侠演义 第一卷:初入江湖 第5章:玉如意的秘密
人工智能·pytorch·neo4j