当前位置:   article > 正文

Ubuntu 深度学习环境配置方案_ubuntu配置深度学习环境

ubuntu配置深度学习环境

一、 依据设备条件配置显卡驱动

1.1 手动安装

ubuntu-drivers devices # 查看可用显卡型号
  • 1
❯ ubuntu-drivers devices
== /sys/devices/pci0000:00/0000:00:01.1/0000:01:00.0 ==
modalias : pci:v000010DEd000024DDsv000017AAsd00003A4Fbc03sc00i00
vendor   : NVIDIA Corporation
driver   : nvidia-driver-515 - distro non-free
driver   : nvidia-driver-525-open - distro non-free recommended
driver   : nvidia-driver-470 - distro non-free
driver   : nvidia-driver-515-open - distro non-free
driver   : nvidia-driver-515-server - distro non-free
driver   : nvidia-driver-470-server - distro non-free
driver   : nvidia-driver-510 - distro non-free
driver   : nvidia-driver-525 - distro non-free
driver   : xserver-xorg-video-nouveau - distro free builtin
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
sudo apt install nvidia-driver-525 # 此处为安装525型号的驱动
nvidia-smi # 安装完成后查看显卡信息
  • 1
  • 2

可显示类似下面信息即为安装成功:

❯ nvidia-smi
Thu Feb  2 16:33:22 2023       
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 525.60.11    Driver Version: 525.60.11    CUDA Version: 12.0     |
|-------------------------------+----------------------+----------------------+
| 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:01:00.0  On |                  N/A |
| N/A   38C    P8    19W /  N/A |    551MiB /  8192MiB |      1%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+
                                                                               
+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|    0   N/A  N/A      1048      G   /usr/lib/xorg/Xorg                 84MiB |
|    0   N/A  N/A      1639      G   /usr/lib/xorg/Xorg                127MiB |
|    0   N/A  N/A      1771      G   /usr/bin/gnome-shell              110MiB |
|    0   N/A  N/A      2729      G   ...641282633524493272,131072      216MiB |
+-----------------------------------------------------------------------------+

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

1.2 自动安装

可通过软件和更新中的附属驱动自行选择安装
附属驱动

二、 安装 anaconda/miniconda

通过 anaconda选择需要的版本进行下载

bash <anaconda_name>.sh # 执行安装
conda activate # 激活环境
conda --version # 查看conda版本
  • 1
  • 2
  • 3

可正确显示版本号即为安装成功

❯ conda --version
conda 22.9.0
  • 1
  • 2

三、 使用conda安装 pytorch、cuda 与 cudnn

通过查看PyTorch官网选择需要的版本进行安装,安装过程中会同时安装pytorch以及相应的库,其中包括 cuda

# 以安装 CUDA 11.6 为例
conda create -n test python=3.8 -y # 先创建一个测试环境,环境名为 test,可自行决定
conda activate test # 激活 test 环境
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.6 -c pytorch -c conda-forge -y 
  • 1
  • 2
  • 3
  • 4

检验是否安装成功

# 在python中执行以下命令
import torch
print(torch.__version__) #查看pytorch版本
print(torch.cuda.is_available()) #查看cuda是否可用 输出为True 或者False
print(torch.version.cuda) # 查看cuda版本
print(torch.backends.cudnn.version()) # 查看cudnn版本
print(torch.cuda.get_device_name(0)) # 查看GPU类型
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

可正常显示版本号即为安装成功

❯ python
Python 3.8.15 (default, Nov 24 2022, 15:19:38) 
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch

print(torch.cuda.is_available()) #查看cuda是否可用 输出为True 或者False
print(torch.version.cuda) # 查看cuda版本
print(torch.backends.cudnn.version()) # 查看cudnn版本
print(torch.cuda.get_device_name(0)) # 查看GPU类型>>> print(torch.__version__) #查看pytorch版本
1.12.1
>>> print(torch.cuda.is_available()) #查看cuda是否可用 输出为True 或者False
True
>>> print(torch.version.cuda) # 查看cuda版本
11.6
>>> print(torch.backends.cudnn.version()) # 查看cudnn版本
8302
>>> print(torch.cuda.get_device_name(0)) # 查看GPU类型
NVIDIA GeForce RTX 3070 Laptop GPU
>>> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小惠珠哦/article/detail/985504
推荐阅读
相关标签
  

闽ICP备14008679号