【问题标题】:Pytorch with CUDA local installation fails on Ubuntu带有 CUDA 本地安装的 Pytorch 在 Ubuntu 上失败
【发布时间】:2022-11-14 04:52:57
【问题描述】:

我正在尝试使用 CUDA 安装 PyTorch。 我按照中提到的说明(使用 conda 安装)进行了操作 https://pytorch.org/get-started/locally/

conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c 火炬

conda install 命令运行没有给出任何错误:

康达清单显示以下内容:

# Name                    Version                   Build  Channel

cudatoolkit               11.3.1               h2bc3f7f_2
pytorch                   1.11.0          py3.9_cuda11.3_cudnn8.2.0_0    pytorch
pytorch-mutex             1.0                        cuda    pytorch
torch                     1.10.2                   pypi_0    pypi
torchaudio                0.11.0               py39_cu113    pytorch
torchvision               0.11.3                   pypi_0    pypi

但是当我检查 PyTorch 是否启用和访问 GPU 驱动程序和 CUDA 时

torch.cuda.is_available()

返回假。

在安装 Pytorch 之前,我检查并确认了中提到的先决条件

https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#system-requirements https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#pre-installation-actions

这是我的 ubuntu 服务器详细信息:

环境

  • 操作系统/内核:

Ubuntu 18.04.6 LTS(GNU/Linux 4.15.0-154-generic x86_64)

表下脚注:表 1. CUDA 11.6 中的本机 Linux 发行版支持 提到

对于 x86-64 上的 Ubuntu LTS,服务器 LTS 内核(例如 4.15.x 18.04) 在 CUDA 11.6 中受支持。

  • 海合会

gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

  • GLIBC

ldd (Ubuntu GLIBC 2.27-3ubuntu1.5) 2.27

图形处理器

GeForce GTX 1080 钛

内核头文件和开发包

$ uname -r
4.15.0-176-generic

据我了解,使用 CUDA 安装 conda pytorch 也会安装 CUDA 驱动程序。

我不确定我哪里出错了。 提前致谢。

编辑:

$ 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

nvcc 显示 CUDA 版本 9.1

然而

$ nvidia-smi
Wed May 11 06:44:31 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 410.104      Driver Version: 410.104      CUDA Version: 10.0     |
|-------------------------------+----------------------+----------------------+
| 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 108...  Off  | 00000000:05:00.0 Off |                  N/A |
| 25%   40C    P8    11W / 250W |     18MiB / 11177MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   1  GeForce GTX 108...  Off  | 00000000:06:00.0 Off |                  N/A |
| 25%   40C    P8    11W / 250W |      2MiB / 11178MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+
|   2  GeForce GTX 108...  Off  | 00000000:09:00.0 Off |                  N/A |
| 25%   35C    P8    11W / 250W |      2MiB / 11178MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      4119      G   /usr/lib/xorg/Xorg                             9MiB |
|    0      4238      G   /usr/bin/gnome-shell                           6MiB |
+-----------------------------------------------------------------------------+

nvidia-smi 显示 CUDA 版本 10.0

https://varhowto.com/check-cuda-version/ 本文提到 nvcc 指的是 CUDA-toolkit 而nvidia-smi 指的是 NVIDIA 驱动程序。

Q1:这是否表明在系统范围内有两种不同的 CUDA 安装?

Nvidia Cudatoolkit vs Conda Cudatoolkit 我在我的 conda 环境中安装的 CUDA 工具包(版本 11.3.1)不同于作为系统范围级别安装的工具包(由 nvccnvidia-smi 的输出显示)。

Q2:根据上面的stackoverflow线程答案,它们可以分开。还是我本地安装cuda失败的原因?

【问题讨论】:

    标签: python pytorch cuda


    【解决方案1】:

    我已经解决了这个问题。

    免责声明: 我是CUDA的新手。 以下答案基于 a) 我在其他主题中阅读的内容 b) 我基于这些讨论的经验。

    核心逻辑: CUDA 驱动程序版本 >= CUDA 运行时版本

    参考:Different CUDA versions shown by nvcc and NVIDIA-smi

    在大多数情况下,如果 nvidia-smi 报告的 CUDA 版本是 在数值上等于或高于 nvcc -V 报告的值,这 不必担心。这是定义的兼容性路径 CUDA(较新的驱动程序/驱动程序 API 支持“较旧的”CUDA 工具包/运行时 API)。

    当我使用 conda 的 cudatoolkit 时:

    • 驱动程序 API:nvidia-smi
    • 运行时 API:conda 的 cudatoolkit

    为了cudatoolkit11.3.1,我正在使用英伟达-smiCUDA 版本:10.0

    解决方案: 升级 NVIDIA 驱动程序。

    按照https://linuxconfig.org/how-to-install-the-nvidia-drivers-on-ubuntu-18-04-bionic-beaver-linux 的说明升级了 NVIDIA 驱动程序

    升级后,这是输出英伟达-smi

    +-----------------------------------------------------------------------------+
    | NVIDIA-SMI 470.103.01   Driver Version: 470.103.01   CUDA Version: 11.4     |
    |-------------------------------+----------------------+----------------------+
    | GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
    | Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
    |                               |                      |               MIG M. |
    |===============================+======================+======================|
    |   0  NVIDIA GeForce ...  Off  | 00000000:05:00.0 Off |                  N/A |
    | 27%   46C    P8    12W / 250W |     19MiB / 11177MiB |      0%      Default |
    |                               |                      |                  N/A |
    +-------------------------------+----------------------+----------------------+
    |   1  NVIDIA GeForce ...  Off  | 00000000:06:00.0 Off |                  N/A |
    | 25%   44C    P8    11W / 250W |      2MiB / 11178MiB |      0%      Default |
    |                               |                      |                  N/A |
    +-------------------------------+----------------------+----------------------+
    |   2  NVIDIA GeForce ...  Off  | 00000000:09:00.0 Off |                  N/A |
    | 25%   39C    P8    11W / 250W |      2MiB / 11178MiB |      0%      Default |
    |                               |                      |                  N/A |
    +-------------------------------+----------------------+----------------------+
    
    +-----------------------------------------------------------------------------+
    | Processes:                                                                  |
    |  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
    |        ID   ID                                                   Usage      |
    |=============================================================================|
    |    0   N/A  N/A      3636      G   /usr/lib/xorg/Xorg                  9MiB |
    |    0   N/A  N/A      4263      G   /usr/bin/gnome-shell                6MiB |
    +-----------------------------------------------------------------------------+
    

    现在驱动程序版本(11.4)>=运行时版本(11.3.1)

    PyTorch 现在可以将 CUDA 与 GPU 一起使用:

    In [1]: import torch
    
    In [2]: torch.cuda.is_available()
    Out[2]: True
    

    【讨论】:

      【解决方案2】:

      Nvidia驱动程序是否正确安装?输入nvida-smi 验证,此问题可能是由于驱动程序版本和cudatoolkit 版本不匹配造成的。

      【讨论】:

      • 1. 我相信你的意思是英伟达-smi? 2.我已经添加了输出英伟达-smi在我的问题中。
      猜你喜欢
      • 1970-01-01
      • 2015-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-10
      • 2016-05-09
      相关资源
      最近更新 更多