python - 为什么 PyTorch 找不到我的 NVIDIA 驱动程序来支持 CUDA?

标签 python anaconda pytorch

我在我的机器(运行 Ubuntu 18.04 和 Anaconda 和 Python 3.7)中添加了一个 GeForce GTX 1080 Ti,以便在使用 PyTorch 时利用 GPU。两张卡都正确识别:

$ lspci | grep VGA
03:00.0 VGA compatible controller: NVIDIA Corporation GF119 [NVS 310] (reva1)
04:00.0 VGA compatible controller: NVIDIA Corporation GP102 [GeForce GTX 1080 Ti] (rev a1)

NVS 310 处理我的 2 显示器设置,我只想将 1080 用于 PyTorch。我还安装了当前在存储库中的最新 NVIDIA 驱动程序,这似乎没问题:
$ nvidia-smi 
Sat Jan 19 12:42:18 2019       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 390.87                 Driver Version: 390.87                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  NVS 310             Off  | 00000000:03:00.0 N/A |                  N/A |
| 30%   60C    P0    N/A /  N/A |    461MiB /   963MiB |     N/A      Default |
+-------------------------------+----------------------+----------------------+
|   1  GeForce GTX 108...  Off  | 00000000:04:00.0 Off |                  N/A |
|  0%   41C    P8    10W / 250W |      2MiB / 11178MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0                    Not Supported                                       |
+-----------------------------------------------------------------------------+

驱动程序版本 390.xx 允许根据 NVIDIA docs 运行 CUDA 9.1 (9.1.85) .由于这也是 Ubuntu 存储库中的版本,我简单地安装了 CUDA Toolkit:
$ sudo apt-get-installed nvidia-cuda-toolkit

再一次,这似乎没问题:
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2017 NVIDIA Corporation
Built on Fri_Nov__3_21:07:56_CDT_2017
Cuda compilation tools, release 9.1, V9.1.85


$ apt-cache policy nvidia-cuda-toolkit
nvidia-cuda-toolkit:
  Installed: 9.1.85-3ubuntu1
  Candidate: 9.1.85-3ubuntu1
  Version table:
 *** 9.1.85-3ubuntu1 500
        500 http://sg.archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages
        100 /var/lib/dpkg/status

最后,我用 conda 从头开始​​安装了 PyTorch
conda install pytorch torchvision -c pytorch

据我所知,还有错误:
$ conda list
...
pytorch                   1.0.0           py3.7_cuda9.0.176_cudnn7.4.1_1    pytorch
...

但是,PyTorch 似乎没有找到 CUDA:
$ python -c 'import torch; print(torch.cuda.is_available())'
False

更详细地说,如果我强制 PyTorch 转换张量 x使用 x.cuda() 到 CUDA我收到错误:
Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from 82 http://...

我在这里缺少什么?我是新手,但我想我已经在网上查了很多,找到了像 NVIDIA 驱动程序和 CUDA 工具包版本这样的警告?

编辑: PyTorch 的更多输出:
print(torch.cuda.device_count())   # --> 0
print(torch.cuda.is_available())   # --> False
print(torch.version.cuda)          # --> 9.0.176

最佳答案

由于您有两个图形卡,选择一个卡 ID CUDA_VISIBLE_DEVICES=GPU_ID应该按照这个解决问题 explanation .

关于python - 为什么 PyTorch 找不到我的 NVIDIA 驱动程序来支持 CUDA?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54264338/

相关文章:

python - 使用 Python/Pandas/Numpy 的几何级数(无循环并使用递归)

python - Django 用于什么目的?

python - 带有字典的 pandas 中的列到行?

python - Django 表单不会显示

python - img 应该是 PIL 图片。得到了 <class 'torch.Tensor' >

python - 不能将 PySide 与 Anaconda 一起使用

python - 使用spyder打开Python脚本

python - 在 Rstudio 中安装 Tensorflow?

pytorch - 如何将 PyTorch 模型移动到 Apple M1 芯片上的 GPU?

python - "Numpy not Available"安装Pytorch XLA后