为什么 PyTorch 找不到用于 CUDA 支持的 NVDIA 驱动程序?

Chr*_*ian 11 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)
Run Code Online (Sandbox Code Playgroud)

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                                       |
+-----------------------------------------------------------------------------+
Run Code Online (Sandbox Code Playgroud)

根据NVIDIA 文档,驱动程序版本 390.xx 允许运行 CUDA 9.1 (9.1.85) 。由于这也是 Ubuntu 存储库中的版本,我简单地安装了 CUDA Toolkit:

$ sudo apt-get-installed nvidia-cuda-toolkit
Run Code Online (Sandbox Code Playgroud)

再一次,这似乎没问题:

$ 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
Run Code Online (Sandbox Code Playgroud)

$ 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
Run Code Online (Sandbox Code Playgroud)

最后,我用 conda 从头开始​​安装了 PyTorch

conda install pytorch torchvision -c pytorch
Run Code Online (Sandbox Code Playgroud)

据我所知,还有错误:

$ conda list
...
pytorch                   1.0.0           py3.7_cuda9.0.176_cudnn7.4.1_1    pytorch
...
Run Code Online (Sandbox Code Playgroud)

但是,PyTorch 似乎没有找到 CUDA:

$ python -c 'import torch; print(torch.cuda.is_available())'
False
Run Code Online (Sandbox Code Playgroud)

更详细地说,如果我强制 PyTorch 将张量转换x为 CUDA ,则会x.cuda()出现错误:

Found no NVIDIA driver on your system. Please check that you have an NVIDIA GPU and installed a driver from 82 http://...
Run Code Online (Sandbox Code Playgroud)

我在这里缺少什么?我对此很陌生,但我想我已经在网上查了很多,以找到像 NVIDIA 驱动程序和 CUDA 工具包版本这样的任何警告?

编辑:来自 PyTorch 的更多输出:

print(torch.cuda.device_count())   # --> 0
print(torch.cuda.is_available())   # --> False
print(torch.version.cuda)          # --> 9.0.176
Run Code Online (Sandbox Code Playgroud)

pro*_*sti 0

CUDA_VISIBLE_DEVICES=GPU_ID由于您有两个图形卡,因此根据此说明选择卡 ID应该可以解决问题。