Ubuntu 下 Pytorch, Tensorflow 對應的Python、英偉達顯卡驅動、CUDA、CUDNN版本與環境信息查看方法

人工神經網絡已然成爲現今最流行的機器學習工具,框架平臺也在不斷地完善升級,對GPU的依賴也越來越嚴重,在框架們升級的過程中會改進原有版本的錯誤並且提供很多美好的合理的新特性,會給使用者帶來更多的便利,也讓使用者對這個框架更有信心,讓框架更加光彩奪目。
但是事實上,在大家爲新版本的Pytorch和Tensorflow千呼萬喚始出來歡呼雀躍的時候,角落裏卻有一小撮人爲莫名其妙的環境錯誤抓耳撓腮。因爲框架的正確運行需要配套固定版本的python、顯卡驅動、CUDA、CUDNN,低了不行高了也不行。

那怎麼查看各個環境的版本呢,各個框架需要什麼版本的運行環境呢,每裝一次查一次的我受夠了,於是有了這篇博客,希望能幫大家多走一些彎路,少走一些捷徑。

我的系統爲Ubuntu 16.04

 

一、環境查看的方法

查看python版本

其實命令行進入python就會顯示版本;

也可以:

~$ python --version

查看CUDA版本

~$ cat /usr/local/cuda/version.txt

查看GPU 型號

~$ lspci | grep -i nvidia

查看NVIDIA驅動版本

~$ sudo dpkg --list | grep nvidia-*

查看cudnn版本

cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

這裏會顯示一些宏
比如我的顯示:

#define CUDNN_MAJOR 7
#define CUDNN_MINOR 4
#define CUDNN_PATCHLEVEL 1
--
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)

#include "driver_types.h"

按照 CUDNN_VERSION的宏定義計算出來的是7401

但是CuDNN版本實際上爲 7.4.1

查看Tensorflow版本

如果安裝了pip或者conda可以運行

pip list

或者

conda list

找到其中Tensorflow查看版本

也可以進入python環境:

import tensorflow as tf
tf.__version__

查看Pytorch版本

安裝了pip或者conda可以向上面一樣運行

pip list

或者

conda list

找到其中叫做 torch 的包查看版本(注意不叫pytorch)

也可以進入python環境,輸入:

import torch
torch.__version__

查看已經安裝的Pytorch對應的CUDA版本

進入python環境,輸入:

import torch
torch.version.cuda

查看已經安裝的Pytorch對應的CUDNN版本

進入python環境,輸入:

import torch
torch.backends.cudnn.version()

二、各環境版本配套要求

好啦,我們已經知道自己的環境是啥版本了,然後我們瞭解一下各個套件之間的依賴關係和配套的要求。

CUDA與NVIDIA驅動版本

https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html

CUDA Toolkit and Compatible Driver Versions

CUDA Toolkit and Compatible Driver Versions
CUDA Toolkit Linux x86_64 Driver Version Windows x86_64 Driver Version
CUDA 10.1 (10.1.105 general release, and updates) >= 418.39 >= 418.96
CUDA 10.0.130 >= 410.48 >= 411.31
CUDA 9.2 (9.2.148 Update 1) >= 396.37 >= 398.26
CUDA 9.2 (9.2.88) >= 396.26 >= 397.44
CUDA 9.1 (9.1.85) >= 390.46 >= 391.29
CUDA 9.0 (9.0.76) >= 384.81 >= 385.54
CUDA 8.0 (8.0.61 GA2) >= 375.26 >= 376.51
CUDA 8.0 (8.0.44) >= 367.48 >= 369.30
CUDA 7.5 (7.5.16) >= 352.31 >= 353.66
CUDA 7.0 (7.0.28) >= 346.46 >= 347.62

TensorFlow與Python, CUDA, cuDNN的版本對應關係

https://tensorflow.google.cn/install/source#linux

版本 Python 版本 編譯器 編譯工具 cuDNN CUDA
tensorflow_gpu-2.0.0-alpha0 2.7、3.3-3.6 GCC 4.8 Bazel 0.19.2 7.4.1以及更高版本 CUDA 10.0 (需要 410.x 或更高版本)
tensorflow_gpu-1.13.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.19.2 7.4 10
tensorflow_gpu-1.12.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.15.0 7 9
tensorflow_gpu-1.11.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.15.0 7 9
tensorflow_gpu-1.10.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.15.0 7 9
tensorflow_gpu-1.9.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.11.0 7 9
tensorflow_gpu-1.8.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.10.0 7 9
tensorflow_gpu-1.7.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.9.0 7 9
tensorflow_gpu-1.6.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.9.0 7 9
tensorflow_gpu-1.5.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.8.0 7 9
tensorflow_gpu-1.4.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.5.4 6 8
tensorflow_gpu-1.3.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.4.5 6 8
tensorflow_gpu-1.2.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.4.5 5.1 8
tensorflow_gpu-1.1.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.4.2 5.1 8
tensorflow_gpu-1.0.0 2.7、3.3-3.6 GCC 4.8 Bazel 0.4.2 5.1 8

CUDA、CUDNN和顯卡驅動

引用自:https://blog.csdn.net/qq_27825451/article/details/89082978

1、顯卡驅動與CUDA

CUDA和顯卡驅動沒有一一對應的關係

NVIDIA的顯卡驅動器與CUDA並不是一一對應的哦,CUDA本質上只是一個工具包而已,所以我可以在同一個設備上安裝很多個不同版本的CUDA工具包,比如我的電腦上同事安裝了 CUDA 9.0、CUDA 9.2、CUDA 10.0三個版本。一般情況下,我只需要安裝最新版本的顯卡驅動,然後根據自己的選擇選擇不同CUDA工具包就可以了,但是由於使用離線的CUDA總是會捆綁CUDA和驅動程序,所以在使用多個CUDA的時候就不要選擇離線安裝的CUDA了,否則每次都會安裝不同的顯卡驅動,這不太好,我們直接安裝一個最新版的顯卡驅動,然後在線安裝不同版本的CUDA即可。

2、cuDNN與CUDA

cuDNN與CUDA沒有一一對應的關係

cuDNN是一個SDK,是一個專門用於神經網絡的加速包,注意,它跟我們的CUDA沒有一一對應的關係,即每一個版本的CUDA可能有好幾個版本的cuDNN與之對應,但一般有一個最新版本的cuDNN版本與CUDA對應更好。

NVIDIA顯卡以及對應的顯卡驅動

https://developer.nvidia.com/cuda-gpus

列出部分常見的Nvidia顯卡型號

臺式機

GeForce Desktop Products
GPU Compute Capability
NVIDIA TITAN RTX 7.5
Geforce RTX 2080 Ti 7.5
Geforce RTX 2080 7.5
Geforce RTX 2070 7.5
Geforce RTX 2060 7.5
NVIDIA TITAN V 7
NVIDIA TITAN Xp 6.1
NVIDIA TITAN X 6.1
GeForce GTX 1080 Ti 6.1
GeForce GTX 1080 6.1
GeForce GTX 1070 6.1
GeForce GTX 1060 6.1
GeForce GTX 1050 6.1
GeForce GTX TITAN X 5.2
GeForce GTX TITAN Z 3.5
GeForce GTX TITAN Black 3.5
GeForce GTX TITAN 3.5
GeForce GTX 980 Ti 5.2
GeForce GTX 980 5.2
GeForce GTX 970 5.2
GeForce GTX 960 5.2
GeForce GTX 950 5.2
GeForce GTX 780 Ti 3.5
GeForce GTX 780 3.5
GeForce GTX 770 3
GeForce GTX 760 3
GeForce GTX 750 Ti 5
GeForce GTX 750 5
GeForce GTX 690 3
GeForce GTX 680 3
GeForce GTX 670 3
GeForce GTX 660 Ti 3
GeForce GTX 660 3
GeForce GTX 650 Ti BOOST 3
GeForce GTX 650 Ti 3
GeForce GTX 650 3
GeForce GTX 560 Ti 2.1
GeForce GTX 550 Ti 2.1
GeForce GTX 460 2.1
GeForce GTS 450 2.1
GeForce GTS 450* 2.1
GeForce GTX 590 2
GeForce GTX 580 2
GeForce GTX 570 2
GeForce GTX 480 2
GeForce GTX 470 2
GeForce GTX 465 2
GeForce GT 740 3
GeForce GT 730 3.5
GeForce GT 730 DDR3,128bit 2.1
GeForce GT 720 3.5
GeForce GT 705* 3.5
GeForce GT 640 (GDDR5) 3.5
GeForce GT 640 (GDDR3) 2.1
GeForce GT 630 2.1
GeForce GT 620 2.1
GeForce GT 610 2.1
GeForce GT 520 2.1
GeForce GT 440 2.1
GeForce GT 440* 2.1
GeForce GT 430 2.1
GeForce GT 430* 2.1

筆記本

GeForce Notebook Products
GPU Compute Capability
Geforce RTX 2080 7.5
Geforce RTX 2070 7.5
Geforce RTX 2060 7.5
GeForce GTX 1080 6.1
GeForce GTX 1070 6.1
GeForce GTX 1060 6.1
GeForce GTX 980 5.2
GeForce GTX 980M 5.2
GeForce GTX 970M 5.2
GeForce GTX 965M 5.2
GeForce GTX 960M 5
GeForce GTX 950M 5
GeForce 940M 5
GeForce 930M 5
GeForce 920M 3.5
GeForce 910M 5.2
GeForce GTX 880M 3
GeForce GTX 870M 3
GeForce GTX 860M 3.0/5.0(**)
GeForce GTX 850M 5
GeForce 840M 5
GeForce 830M 5
GeForce 820M 2.1
GeForce 800M 2.1
GeForce GTX 780M 3
GeForce GTX 770M 3
GeForce GTX 765M 3
GeForce GTX 760M 3
GeForce GTX 680MX 3
GeForce GTX 680M 3
GeForce GTX 675MX 3
GeForce GTX 675M 2.1
GeForce GTX 670MX 3
GeForce GTX 670M 2.1
GeForce GTX 660M 3
GeForce GT 755M 3
GeForce GT 750M 3
GeForce GT 650M 3
GeForce GT 745M 3
GeForce GT 645M 3
GeForce GT 740M 3
GeForce GT 730M 3
GeForce GT 640M 3
GeForce GT 640M LE 3
GeForce GT 735M 3
GeForce GT 635M 2.1
GeForce GT 730M 3
GeForce GT 630M 2.1
GeForce GT 625M 2.1
GeForce GT 720M 2.1
GeForce GT 620M 2.1
GeForce 710M 2.1
GeForce 705M 2.1
GeForce 610M 2.1
GeForce GTX 580M 2.1
GeForce GTX 570M 2.1
GeForce GTX 560M 2.1
GeForce GT 555M 2.1
GeForce GT 550M 2.1
GeForce GT 540M 2.1
GeForce GT 525M 2.1
GeForce GT 520MX 2.1
GeForce GT 520M 2.1
GeForce GTX 485M 2.1
GeForce GTX 470M 2.1
GeForce GTX 460M 2.1
GeForce GT 445M 2.1
GeForce GT 435M 2.1
GeForce GT 420M 2.1
GeForce GT 415M 2.1
GeForce GTX 480M 2
GeForce 710M 2.1
GeForce 410M 2.1

Pytorch與CUDA的對應關係

Pytorch沒有Tensorflow那麼明確的表格,但是https://pytorch.org/get-started/locally/提供了最新的Pytorch各個環境的安裝命令,從表格中可以看到環境需求。

現在(2019.08.28)最新的Pytorch爲1.2 需求CUDA版本9.2或10.0

以往的Pytorch版本安裝命令如下:

https://pytorch.org/get-started/previous-versions/

Installing with CUDA 9

conda install pytorch=0.4.1 cuda90 -c pytorch

or

conda install pytorch=0.4.1 cuda92 -c pytorch

Installing with CUDA 8

conda install pytorch=0.4.1 cuda80 -c pytorch

Installing with CUDA 7.5

conda install pytorch=0.4.1 cuda75 -c pytorch

Installing without CUDA

conda install pytorch=0.4.1 -c pytorch

PyTorch Linux binaries compiled with CUDA 7.5

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章