News from this site

 Rental advertising space, please contact the webmaster if you need cooperation


+focus
focused

classification  

no classification

tag  

no tag

date  

2024-11(8)

pytorch1.13 installation

posted on 2023-05-21 16:24     read(669)     comment(0)     like(7)     collect(2)


Situation explanation

  1. Graphics card 3060, cuda version 12.0
  2. There is already a virtual environment installed with cuda11.2 and cudnn8.1.0 and the corresponding tensorflow
  3. Now you need to create a pytorch environment that can use GPU acceleration

installation process

Precautions

pytorch itself has a cuda environment, so there is no need to force it to be consistent with the previous tensorflow environment.
torch1.13.0 does not support cuda10.2 and 11.3 versions

Graphics card configuration view

nvidia-smi
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 526.47       Driver Version: 526.47       CUDA Version: 12.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name            TCC/WDDM | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA GeForce ... WDDM  | 00000000:01:00.0  On |                  N/A |
|  0%   44C    P8    22W / 170W |   1486MiB / 12288MiB |     31%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

create environment

conda create -name torch python=3.9

Activate the environment

activate torch

Install the corresponding torch version

The torch official website
provides several sample codes:

# CUDA 10.2
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=10.2 -c pytorch
# CUDA 11.3
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -c pytorch
# CUDA 11.6
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.6 -c pytorch -c conda-forge
# CPU Only
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cpuonly -c pytorch

Delete the last -c pytorch
and then modify the cudatoolkit version to 11.2 (this sentence means to download the 11.2 version of cuda, and this cuda can be inconsistent with the system's cuda version, but it must be lower than the system itself, that is, The version (12.0) obtained by the nidia-smi command query)
that is, use the following command in the torch environment: (note that this command is wrong and will be modified later)

conda install pytorch torchvision torchaudio cudatoolkit=11.2

examine

use pip list

Package           Version
----------------- -------
numpy             1.21.6
Pillow            9.2.0
pip               22.3.1
setuptools        65.5.1
six               1.16.0
torch             1.13.0
torchaudio        0.13.0
torchvision       0.2.2
typing_extensions 4.4.0
wheel             0.38.2

import view

import torch 
torch.cuda.is_available()

The cashback returns false.
Use the conda list to check and find that the downloaded version is the cpu version.

pytorch                   1.13.0              py3.7_cpu_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
pytorch-mutex             1.0                         cpu    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch
setuptools                65.5.1             pyhd8ed1ab_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
six                       1.16.0             pyh6c4a22f_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
sqlite                    3.39.4               hcfcfb64_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge

uninstall

conda uninstall pytorch

Download the gpu version of

View the installation command in the form of pip on the official website:
insert image description here

pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116

verify

feasible
insert image description here

Add this kernel to jupyter

  1. Check if there is ipykernel
    python -m ipykernel --version
  2. If not, install
    python -m pip install ipykernel
  3. Add
    python -m ipykernel install --user --name=torch after installation
  4. View the kernel
    jupyter kernelspec list
    insert image description here
  5. Do not want to delete
    jupyter kernelspec remove kernelname

Finish



Category of website: technical article > Blog

Author:gfg

link:http://www.pythonblackhole.com/blog/article/25278/6b54391dbf12356a4293/

source:python black hole net

Please indicate the source for any form of reprinting. If any infringement is discovered, it will be held legally responsible.

7 0
collect article
collected

Comment content: (supports up to 255 characters)