[Ubuntu 18.04] Environment construction for using PyTorch with RTX3090


Since PyTorch 1.7 supports RTX 3090, I will leave it as a memo of the environment construction.

Target environment

I want torch.cuda.is_available () to be True ...!


0. Replace GPU

(If you don't have this work, please skip it)

Originally I was using GTX1080Ti, so I replaced the hardware first. I replaced it without uninstalling the driver. (I wonder if it was okay ...) For the time being, the environment at the time of GTX1080Ti is shown below.

And when I started it, the resolution was strange. Well, I think it's natural that something goes wrong with the original driver.

1. Delete existing drivers, CUDA, cuDNN, PyTorch, etc.

(If you don't need this work, skip it)

Use the following command in the terminal to erase the remaining nvidia driver, CUDA and cuDNN.

$ sudo apt remove --purge nvidia*
$ sudo apt remove --purge cuda*
$ sudo apt remove --purge libcudnn*
$ sudo apt remove --purge libnvidia*
$ sudo apt autoremove

Erase PyTorch etc. I managed it with pip, so I typed the following command.

$ pip uninstall torch
% pip uninstall torchvision

Just in case, let's restart the PC here.

$ sudo reboot

2. Install nvidia-driver

Use the following command to find out which nvidia-driver is right for your RTX 3090.

$ sudo ubuntu-drivers devices

Since nvidia-driver-455 was recommended, I installed it by typing the following command.

$ sudo apt install nvidia-driver-455 # 2021/01/As of 07

After the installation is complete, let's reboot here.

$ sudo reboot

Maybe the resolution is back to normal. Let's check the driver status etc. with nvidia-smi.

$ nvidia-smi

3. Install CUDA

When I checked with nvidia-smi, it says CUDA 11.1 in the upper right. But PyTorch 1.7 is supported by CUDA 11.0.

I'm not sure, but let's install CUDA 11.0 ... I chose Linux> x86_64> Ubuntu> 18.04> deb (network) from the CUDA 11.0 Archive Site (https://developer.nvidia.com/cuda-11.0-update1-download-archive). Enter the command listed there.

###Please copy and paste the above site below.###
$ wget https://developer.download.nvidia.com/....
$ sudo apt-get update
###So far###

Note the command on the last line here. If you do not specify the version as shown below, the latest version will be installed, so let's set it as cuda-11-0.

$ sudo apt-get -y install cuda-11-0

If you don't go through the path, add the following to the last line of ~/.bashrc.

$ sudo vi ~/.bashrc


export PATH="/usr/local/cuda/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda/lib64:$LD_LIBRARY_PATH"

In vim, paste with [Ctrl] + [Shift] + [v], switch to NORMAL mode with the [Esc] key, and overwrite and save with : wq. You have now installed CUDA 11.0. Let's check with the following command.

$ nvcc -V

4. Install cuDNN

Select the latest version for CUDA 11.0 from cuDNN Archive Site. I chose v8.0.4. Among them,

I chose and downloaded it.

I will be downloaded to the ~/Downloads directory, so

$ cd Downloads

Then, type the commands in the following order to install cuDNN.

$ sudo dpkg -i libcudnn8_8.0.4.30-1+cuda11.0_amd64.deb
$ sudo dpkg -i libcudnn8-dev_8.0.4.30-1+cuda11.0_amd64.deb
$ sudo dpkg -i libcudnn8-samples_8.0.4.30-1+cuda11.0_amd64.deb

Just in case, let's restart the PC here.

$ sudo reboot

5. Install PyTorch

PyTorch official website Type the command to install. As of January 07, 2021, the command was as follows.

$ pip install torch==1.7.1+cu110 torchvision==0.8.2+cu110 torchaudio===0.7.2 -f https://download.pytorch.org/whl/torch_stable.html


Confirmation with PyTorch

$ python
Python 3.6.7 (default, Sep  7 2020, 17:00:49) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()

Confirmation of CUDA

$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Wed_Jul_22_19:09:09_PDT_2020
Cuda compilation tools, release 11.0, V11.0.221
Build cuda_11.0_bu.TC445_37.28845127_0

Confirmation with nvidia-smi

$ nvidia-smi
Thu Jan  7 23:35:29 2021       
| NVIDIA-SMI 460.27.04    Driver Version: 460.27.04    CUDA Version: 11.2     |
| 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 3090    On   | 00000000:65:00.0  On |                  N/A |
| 51%   67C    P2   295W / 350W |   5855MiB / 24267MiB |      0%      Default |
|                               |                      |                  N/A |

Why is it CUDA 11.2?


After this I trained the model with PyTorch and it worked fine. I wrote it in a messy way, so if you have any questions or mistakes, please comment etc. m (_ _) m

It's a convenient world.

Recommended Posts

[Ubuntu 18.04] Environment construction for using PyTorch with RTX3090
Environment construction procedure for using PowerMock with JUnit
Environment construction with Docker for beginners
Environment construction with Docker (Ubuntu20.04) + Laravel + nginx
[Flutter] Ubuntu 20.04 environment construction
Stable development environment construction manual for "Rails6" with "Docker-compose"
[Java] Environment construction procedure for developing struts 1.3 with Eclipse
Prepare the environment for java11 and javaFx with Ubuntu 18.4
Java + Spring development environment construction with VirtualBox + Ubuntu (Xfce4)
Pytorch execution environment with Docker
[Docker] Rails 5.2 environment construction with docker
Laravel environment construction (Ubuntu 18.04 LTS)
React environment construction with Docker
Case that gave up environment construction of react with ubuntu
Configuration script for using docker in proxy environment on ubuntu 20.04.1
Rails + MySQL environment construction with Docker
[Windows] WSL2 + Ubuntu + Node.js environment construction
Node.js environment construction with Docker Compose
Environment construction for Servlet application development
Let's create Ubuntu environment with vmware
[Environment construction with Docker] Rails 6 & MySQL 8
[Java & SpringBoot] Environment Construction for Mac
Use cuda11.0 with pytorch using Docker
"Rails 6 x MySQL 8" Docker environment construction procedure for sharing with teams
Notes for using BLE with iOS apps
GPU environment construction with Docker [October 2020 version]
Laravel development environment construction with Docker (Mac)
Rails API server environment construction using docker-compose
Laravel + MySQL + phpMyadmin environment construction with Docker
Prepare the environment for CUDA, Nvida-Driver, and cuDNN on an Ubuntu 18.04 PC equipped with Geforce RTX2080 SUPER.
Modern Java environment for Windows using Chocolatey
Using Material Design for Bootstrap with Rails 5.2
Environment construction summary with rvm and postgresql
Spring Boot environment construction with Docker (January 2021 version)
Try running ScalarDB on WSL Ubuntu (Environment Construction)
Introduction to Robot Battle with Robocode (Environment Construction)
[Jakarta EE 8 application development with Gradle] 1. Environment construction
Protobuf and gRPC C ++ environment construction on Ubuntu 18.04
Environment construction command memo with Docker on AWS
Kaggle environment construction using official Docker and vscode
CI / CD practice for beginners --Part1 --Environment construction
Rails6 [API mode] + MySQL5.7 environment construction with Docker
Create ubuntu20.04 (or windows10) + anaconda + pytorch or tensorflow environment
Tips for using the Spotify app on Ubuntu
Development environment construction using IntelliJ IDEA + Maven + Tomcat 9
[Note] Struts2 environment construction using Gradle in Eclipse
DB environment construction with DBFlute Intro + H2 Database
React + Django + Nginx + MySQL environment construction with Docker
Build mecab (NEologd dictionary) environment with Docker (ubuntu)
How to build a Pytorch environment on Ubuntu
Introduction to kotlin for iOS developers ①-Environment construction
Tips for testing with mock for classes using @value
Django development environment construction using Docker-compose (personal memorandum)
Wordpress local environment construction & development procedure with Docker
Build a local development environment for Open Distro for Elasticsearch with multiple nodes using Docker
Java environment construction
How to quit Docker for Mac and build a Docker development environment with Ubuntu + Vagrant
[Spring] Environment construction
Docker environment construction
I built an Ubuntu environment on Windows 10 using WSL2.
How to build docker environment with Gradle for intelliJ