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

完结!

相关推荐
scdifsn4 小时前
动手学深度学习12.7. 参数服务器-笔记&练习(PyTorch)
pytorch·笔记·深度学习·分布式计算·数据并行·参数服务器
海盗儿6 小时前
Attention Is All You Need (Transformer) 以及Transformer pytorch实现
pytorch·深度学习·transformer
聚客AI12 小时前
PyTorch玩转CNN:卷积操作可视化+五大经典网络复现+分类项目
人工智能·pytorch·神经网络
YYXZZ。。15 小时前
PyTorch——优化器(9)
pytorch·深度学习·计算机视觉
点云SLAM15 小时前
PyTorch 中contiguous函数使用详解和代码演示
人工智能·pytorch·python·3d深度学习·contiguous函数·张量内存布局优化·张量操作
西猫雷婶20 小时前
pytorch基本运算-导数和f-string
人工智能·pytorch·python
顽强卖力20 小时前
第二十八课:深度学习及pytorch简介
人工智能·pytorch·深度学习
述雾学java20 小时前
深入理解 transforms.Normalize():PyTorch 图像预处理中的关键一步
人工智能·pytorch·python
晓枫-迷麟1 天前
【使用conda】安装pytorch
人工智能·pytorch·conda
爱补鱼的猫猫1 天前
Pytorch知识点2
人工智能·pytorch·python