安装
安装 pytorch 运行环境 本文基于Ubuntu 20.04 server版 安装pytorch相关。
安装cuda cudnn
参考文章 cuda113 cudNN.
显卡驱动
查看硬件 显卡信息
lspci | grep -e VGA
04:00.0 VGA compatible controller: NVIDIA Corporation GP104 [GeForce GTX 1080] (rev a1)
05:00.0 VGA compatible controller: NVIDIA Corporation GP104 [GeForce GTX 1080] (rev a1)
08:00.0 VGA compatible controller: NVIDIA Corporation GP104 [GeForce GTX 1080] (rev a1)
09:00.0 VGA compatible controller: NVIDIA Corporation GP104 [GeForce GTX 1080] (rev a1)
0c:00.0 VGA compatible controller: ASPEED Technology, Inc. ASPEED Graphics Family (rev 30)
84:00.0 VGA compatible controller: NVIDIA Corporation GP104 [GeForce GTX 1080] (rev a1)
85:00.0 VGA compatible controller: NVIDIA Corporation GP104 [GeForce GTX 1080] (rev a1)
88:00.0 VGA compatible controller: NVIDIA Corporation GP104 [GeForce GTX 1080] (rev a1)
89:00.0 VGA compatible controller: NVIDIA Corporation GP104 [GeForce GTX 1080] (rev a1)
查看当前显卡驱动
dpkg -l | grep nvidia
查看显卡可用驱动
ubuntu-drivers devices
卸载旧的
sudo apt-get purge nvidia*
sudo apt autoremove
更新最新的驱动
sudo add-apt-repository ppa:graphics-drivers/ppa -y
sudo apt update
sudo apt install nvidia-driver-510 -y
nvidia-smi 查看驱动 cuda nvcc
nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Mon_May__3_19:15:13_PDT_2021
Cuda compilation tools, release 11.3, V11.3.109
Build cuda_11.3.r11.3/compiler.29920130_0
安装pytorch
进去 Pytorch 官网
根据需求进行配置
安装命令
pip3 install torch==1.10.2+cu113 torchvision==0.11.3+cu113 torchaudio==0.10.2+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html
IDE. Pycharm
安装
进入pycharm官网 下载需要的版本
配置远程调试
配置SSH
配置interpreter
pythorch 打印 cuda等信息
import torch
def print_torch():
print(torch.__version__)
print('device:', torch.cuda.current_device())
print('count:', torch.cuda.device_count())
print('name:', torch.cuda.get_device_name(0))
print('gpu:', torch.cuda.is_available())
if __name__ == '__main__':
print_torch()
打印结果:
1.10.2+cu113
device: 0
count: 8
name: NVIDIA GeForce GTX 1080
gpu: True
Process finished with exit code
参考
|