赞
踩
ubuntu-drivers devices # 查看可用显卡型号
❯ 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
sudo apt install nvidia-driver-525 # 此处为安装525型号的驱动
nvidia-smi # 安装完成后查看显卡信息
可显示类似下面信息即为安装成功:
❯ 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 | +-----------------------------------------------------------------------------+
可通过软件和更新中的附属驱动自行选择安装
通过 anaconda选择需要的版本进行下载
bash <anaconda_name>.sh # 执行安装
conda activate # 激活环境
conda --version # 查看conda版本
可正确显示版本号即为安装成功
❯ conda --version
conda 22.9.0
通过查看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
检验是否安装成功
# 在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类型
可正常显示版本号即为安装成功
❯ 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 >>>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。