首页 > 解决方案 > Pytorch 找不到 CUDA 设备

问题描述

我尝试在我的设置中使用 Pytorch 中的 Cuda,但无法检测到它,我不知道为什么。

torch.cuda.is_available()

返回False。深层发掘,

torch._C._cuda_getDeviceCount()

返回 0。使用 1.5 版,例如

$ pip freeze | grep torch
torch==1.5.0

我试图编写一个小的 C 程序来做同样的事情,例如

#include <stdio.h>
#include <cuda_runtime_api.h>

int main() {
   int count = 0;
   cudaGetDeviceCount(&count);
   printf("Device count: %d\n", count);
   return 0;
}

打印 1,因此 Cuda 运行时显然可以找到设备。另外,运行nvidia-smi

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 435.21       Driver Version: 435.21       CUDA Version: 10.1     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 106...  Off  | 00000000:02:00.0  On |                  N/A |
|  0%   41C    P8     9W / 200W |    219MiB /  6075MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

那么我的 Cuda 设备在 Python 中消失在哪里了?

标签: pytorch

解决方案


我现在才意识到,如果 Pytorch 对于每个不同的 CUDA 次要版本都有不同的版本,所以在我的情况下,版本torch==1.5.0显然默认为 CUDA 10.2,而特殊包torch==1.5.0+cu101可以工作。

我希望这可以让其他喜欢我的人开始阅读 PyPi 上的文档(如果您知道在哪里可以查看更多最新文档:https ://pytorch.org/get-started/locally/ )


推荐阅读