动手学深度学习第二版之环境配置(RTX2060+pytorch1.8.1+cuda11.1)

动手学深度学习第二版之环境配置(RTX2060+pytorch1.8.1+cuda11.1)

1、电脑硬件环境

CPU :i7-10750H

GPU :rtx2060 显存6G

双系统 ubuntu18.04 win10

2、安装miniconda

参考:https://zh-v2.d2l.ai/chapter_installation/index.html

3、安装显卡驱动

首先检查是否安装显卡驱动

nvidia-smi

如果没有安装,则安装

ubuntu-drivers devices
(base) sunshine@sunshine-NH5x-7xDCx-DDx:~$ ubuntu-drivers devices
== /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0 ==
modalias : pci:v000010DEd00001F15sv00001558sd00008521bc03sc00i00
vendor   : NVIDIA Corporation
driver   : nvidia-driver-460-server - distro non-free recommended
driver   : nvidia-driver-450 - distro non-free
driver   : nvidia-driver-460 - distro non-free
driver   : nvidia-driver-450-server - distro non-free
driver   : nvidia-driver-455 - third-party free
driver   : xserver-xorg-video-nouveau - distro free builtin

== /sys/devices/pci0000:00/0000:00:14.3 ==
modalias : pci:v00008086d000006F0sv00008086sd000002A4bc02sc80i00
vendor   : Intel Corporation
manual_install: True
driver   : backport-iwlwifi-dkms - distro free

driver : nvidia-driver-460-server - distro non-free recommended

sudo apt install nvidia-driver-460

安装完成后更新

sudo apt upgrade

最后进行重启

使用下面命令查看是否安装成功

nvidia-smi

如果是这样的就成功了

(base) sunshine@sunshine-NH5x-7xDCx-DDx:~$ nvidia-smi
Sat Apr 24 16:51:03 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 455.23.05    Driver Version: 455.23.05    CUDA Versi(base) sunshine@sunshine-NH5x-7xDCx-DDx:~$ nvidia-smi
Sat Apr 24 16:51:03 2021       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 455.23.05    Driver Version: 455.23.05    CUDA Version: 11.1     |
|-------------------------------+----------------------+----------------------+
| 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  GeForce RTX 2060    On   | 00000000:01:00.0 Off |                  N/A |
| N/A   41C    P8     7W /  N/A |   1322MiB /  5934MiB |     10%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      2326      G   /usr/lib/xorg/Xorg                 28MiB |
|    0   N/A  N/A      2879      G   /usr/bin/gnome-shell               50MiB |
|    0   N/A  N/A      4586      G   /usr/lib/xorg/Xorg                205MiB |
|    0   N/A  N/A      4771      G   /usr/bin/gnome-shell               40MiB |
|    0   N/A  N/A      5736      G   ...AAAAAAAAA= --shared-files      113MiB |
|    0   N/A  N/A     17366      C   python                            839MiB |
|    0   N/A  N/A     17568      G   ...AAAAAAAAA= --shared-files       35MiB |
+-----------------------------------------------------------------------------+
on: 11.1     |
|-------------------------------+----------------------+----------------------+
| 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  GeForce RTX 2060    On   | 00000000:01:00.0 Off |                  N/A |
| N/A   41C    P8     7W /  N/A |   1322MiB /  5934MiB |     10%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      2326      G   /usr/lib/xorg/Xorg                 28MiB |
|    0   N/A  N/A      2879      G   /usr/bin/gnome-shell               50MiB |
|    0   N/A  N/A      4586      G   /usr/lib/xorg/Xorg                205MiB |
|    0   N/A  N/A      4771      G   /usr/bin/gnome-shell               40MiB |
|    0   N/A  N/A      5736      G   ...AAAAAAAAA= --shared-files      113MiB |
|    0   N/A  N/A     17366      C   python                            839MiB |
|    0   N/A  N/A     17568      G   ...AAAAAAAAA= --shared-files       35MiB |
+-----------------------------------------------------------------------------+

注意我这里驱动版本成为450而不是460是因为后面安装cuda时给降低了版本。我是按照后面的参考链接安装cuda 和cudnn了的,其实现在应该不用单独安装cuda 和cudnn了,在安装pytorch gpu版本的时候会自动安装。如果下面老哥有成功的话记得在下面评论一下。记得换源(推荐清华)。

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传动手学深度学习第二版之环境配置(RTX2060+pytorch1.8.1+cuda11.1)_第1张图片

pytorch网址

换源后安装pytorchgpu版本时候把==-c pytoch==去掉

其实我执行上面命令结果给我安装了个cpu的,不知道什么情况

(base) sunshine@sunshine-NH5x-7xDCx-DDx:~$ conda install pytorch torchvision torchaudio cudatoolkit=11.1 -c conda-forge
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/sunshine/miniconda3

  added / updated specs:
    - cudatoolkit=11.1
    - pytorch
    - torchaudio
    - torchvision


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    cudatoolkit-11.1.1         |       h6406543_8        1.20 GB  conda-forge
    libgcc-ng-9.3.0            |      h2828fa1_19         7.8 MB  conda-forge
    llvm-openmp-11.1.0         |       h4bd325d_1         4.7 MB  conda-forge
    mkl-2020.4                 |     h726a3e6_304       215.6 MB  conda-forge
    ninja-1.10.2               |       h4bd325d_0         2.4 MB  conda-forge
    pytorch-1.8.0              |cpu_py38hd248515_1        43.2 MB  conda-forge
    torchvision-0.9.0          |py38h3f3a366_0_cpu         6.7 MB  conda-forge
    ------------------------------------------------------------
                                           Total:        1.48 GB

The following NEW packages will be INSTALLED:

  _openmp_mutex      conda-forge/linux-64::_openmp_mutex-4.5-1_llvm
  cudatoolkit        conda-forge/linux-64::cudatoolkit-11.1.1-h6406543_8
  freetype           conda-forge/linux-64::freetype-2.10.4-h0708190_1
  future             conda-forge/linux-64::future-0.18.2-py38h578d9bd_3
  jpeg               conda-forge/linux-64::jpeg-9d-h36c2ea0_0
  lcms2              conda-forge/linux-64::lcms2-2.12-hddcbb42_0
  libblas            conda-forge/linux-64::libblas-3.9.0-8_mkl
  libcblas           conda-forge/linux-64::libcblas-3.9.0-8_mkl
  liblapack          conda-forge/linux-64::liblapack-3.9.0-8_mkl
  libpng             conda-forge/linux-64::libpng-1.6.37-h21135ba_2
  libprotobuf        conda-forge/linux-64::libprotobuf-3.15.8-h780b84a_0
  libtiff            conda-forge/linux-64::libtiff-4.2.0-hdc55705_1
  libwebp-base       conda-forge/linux-64::libwebp-base-1.2.0-h7f98852_2
  llvm-openmp        conda-forge/linux-64::llvm-openmp-11.1.0-h4bd325d_1
  lz4-c              conda-forge/linux-64::lz4-c-1.9.3-h9c3ff4c_0
  mkl                conda-forge/linux-64::mkl-2020.4-h726a3e6_304
  ninja              conda-forge/linux-64::ninja-1.10.2-h4bd325d_0
  numpy              conda-forge/linux-64::numpy-1.20.2-py38h9894fe3_0
  olefile            conda-forge/noarch::olefile-0.46-pyh9f0ad1d_1
  openjpeg           conda-forge/linux-64::openjpeg-2.4.0-hf7af979_0
  pillow             conda-forge/linux-64::pillow-8.1.2-py38ha0e1e83_1
  python_abi         conda-forge/linux-64::python_abi-3.8-1_cp38
  pytorch            conda-forge/linux-64::pytorch-1.8.0-cpu_py38hd248515_1
  sleef              conda-forge/linux-64::sleef-3.5.1-h7f98852_1
  torchaudio         anaconda/cloud/pytorch/linux-64::torchaudio-0.8.0-py38
  torchvision        conda-forge/linux-64::torchvision-0.9.0-py38h3f3a366_0_cpu
  typing_extensions  conda-forge/noarch::typing_extensions-3.7.4.3-py_0
  zstd               conda-forge/linux-64::zstd-1.4.9-ha95c52a_0

The following packages will be UPDATED:

  certifi            anaconda/pkgs/main::certifi-2020.12.5~ --> conda-forge::certifi-2020.12.5-py38h578d9bd_1
  libgcc-ng          anaconda/pkgs/main::libgcc-ng-9.1.0-h~ --> conda-forge::libgcc-ng-9.3.0-h2828fa1_19
  libstdcxx-ng       anaconda/pkgs/main::libstdcxx-ng-9.1.~ --> conda-forge::libstdcxx-ng-9.3.0-h6de172a_19

The following packages will be SUPERSEDED by a higher-priority channel:

  _libgcc_mutex      anaconda/pkgs/main::_libgcc_mutex-0.1~ --> conda-forge::_libgcc_mutex-0.1-conda_forge
  ca-certificates    anaconda/pkgs/main::ca-certificates-2~ --> conda-forge::ca-certificates-2020.12.5-ha878542_0
  conda              anaconda/pkgs/main::conda-4.10.1-py38~ --> conda-forge::conda-4.10.1-py38h578d9bd_0
  openssl            anaconda/pkgs/main::openssl-1.1.1k-h2~ --> conda-forge::openssl-1.1.1k-h7f98852_0


Proceed ([y]/n)? n


CondaSystemExit: Exiting.

可以看到torchvision后面是cpu版的,后来我就把cudatoolkit去掉,就下面这种情况

conda install pytorch torchvision torchaudio
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/sunshine/miniconda3

  added / updated specs:
    - pytorch
    - torchaudio
    - torchvision


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    cudatoolkit-10.2.89        |       hfd86e86_1       365.1 MB  https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
    ------------------------------------------------------------
                                           Total:       365.1 MB

The following NEW packages will be INSTALLED:

  blas               anaconda/pkgs/main/linux-64::blas-1.0-mkl
  bzip2              conda-forge/linux-64::bzip2-1.0.8-h516909a_3
  cudatoolkit        anaconda/pkgs/main/linux-64::cudatoolkit-10.2.89-hfd86e86_1
  ffmpeg             conda-forge/linux-64::ffmpeg-4.3.1-h3215721_1
  freetype           conda-forge/linux-64::freetype-2.10.4-h7ca028e_0
  gmp                conda-forge/linux-64::gmp-6.2.1-h58526e2_0
  gnutls             conda-forge/linux-64::gnutls-3.6.13-h85f3911_1
  intel-openmp       anaconda/pkgs/main/linux-64::intel-openmp-2021.2.0-h06a4308_610
  jpeg               anaconda/pkgs/main/linux-64::jpeg-9b-h024ee3a_2
  lame               conda-forge/linux-64::lame-3.100-h14c3975_1001
  lcms2              anaconda/pkgs/main/linux-64::lcms2-2.12-h3be6417_0
  libiconv           conda-forge/linux-64::libiconv-1.16-h516909a_0
  libpng             conda-forge/linux-64::libpng-1.6.37-h21135ba_2
  libtiff            anaconda/pkgs/main/linux-64::libtiff-4.1.0-h2733197_1
  libuv              anaconda/pkgs/main/linux-64::libuv-1.40.0-h7b6447c_0
  lz4-c              conda-forge/linux-64::lz4-c-1.9.2-he1b5a44_3
  mkl                anaconda/pkgs/main/linux-64::mkl-2020.2-256
  mkl-service        conda-forge/linux-64::mkl-service-2.3.0-py38h1e0a361_2
  mkl_fft            anaconda/pkgs/main/linux-64::mkl_fft-1.3.0-py38h54f3939_0
  mkl_random         conda-forge/linux-64::mkl_random-1.2.0-py38hc5bc63f_1
  nettle             conda-forge/linux-64::nettle-3.6-he412f7d_0
  ninja              anaconda/pkgs/main/linux-64::ninja-1.10.2-hff7bd54_1
  numpy              anaconda/pkgs/main/linux-64::numpy-1.19.2-py38h54aff64_0
  numpy-base         anaconda/pkgs/main/linux-64::numpy-base-1.19.2-py38hfa32c7d_0
  olefile            conda-forge/noarch::olefile-0.46-pyh9f0ad1d_1
  openh264           conda-forge/linux-64::openh264-2.1.1-h8b12597_0
  pillow             anaconda/pkgs/main/linux-64::pillow-8.2.0-py38he98fc37_0
  python_abi         conda-forge/linux-64::python_abi-3.8-1_cp38
  pytorch            anaconda/cloud/pytorch/linux-64::pytorch-1.8.1-py3.8_cuda10.2_cudnn7.6.5_0
  torchaudio         anaconda/cloud/pytorch/linux-64::torchaudio-0.8.1-py38
  torchvision        anaconda/cloud/pytorch/linux-64::torchvision-0.9.1-py38_cu102
  typing_extensions  conda-forge/noarch::typing_extensions-3.7.4.3-py_0
  x264               conda-forge/linux-64::x264-1!152.20180806-h14c3975_0
  zstd               anaconda/pkgs/main/linux-64::zstd-1.4.5-h9ceee32_0

The following packages will be UPDATED:

  certifi            anaconda/pkgs/main::certifi-2020.12.5~ --> conda-forge::certifi-2020.12.5-py38h578d9bd_1

The following packages will be SUPERSEDED by a higher-priority channel:

  ca-certificates    anaconda/pkgs/main::ca-certificates-2~ --> conda-forge::ca-certificates-2020.12.5-ha878542_0
  conda              anaconda/pkgs/main::conda-4.10.1-py38~ --> conda-forge::conda-4.10.1-py38h578d9bd_0



这种就更离谱了,又给我把cuda版本降低了,但是也没办法了,后来就这种完成的。但是检查一下cuda和torch能用不,结果可以,我笑了!!!!

(base) sunshine@sunshine-NH5x-7xDCx-DDx:~$ python
Python 3.8.8 (default, Apr 13 2021, 19:58:26) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch as t
>>> print(t.cuda.is_available())
True
>>> exit()

最后通过nvidia-smi查看版本时候cuda还是11.1,我也不知道我的cuda到底是多少了!!!!

开始后面的学习吧!!!

进入conda虚拟环境

conda activate

退出虚拟环境

conda deactivate

参考链接

Win10双系统安装Ubuntu18.04以及安装Pytorch

Ubuntu18.04下安装Pytorch-GPU(超详细自己安装全过程)

Conda安装软件报错:Solving environment: failed with initial frozen solve. UnsatisfiableError:

你可能感兴趣的:(深度学习(pytorch))