Another fool-like way to deploy cuda environment from zero under windows

foreword

Recently, because of the continuous deployment of two deep learning environments, it is really annoying, so I found a simple way to make everyone deploy quickly like a fool. First, ensure that your hard disk has more than 20G of space. Here, deploy torch The gpu version and let onnxruntime use cuda acceleration as an example, let us start the following steps.

Install

install miniconda

If you already have a conda environment, you can skip this step. If you don’t have it, you can install miniconda directly from 0. It is not recommended to install anaconda directly, because the volume is too large and there are too many packages.
Miniconda download
insert image description here
is now generally 64-bit, here is a 64-bit installation package as an example to download directly:

insert image description here
Choose just me here:

insert image description here
Modify the directory , if you are confident enough in your C drive, you can just default it, but generally speaking, the C drive does not have so much space, and in addition, the later deep learning may require hard disk paging as virtual memory, so I put it in the D drive Ensure enough space:

insert image description here

insert image description here
Check all of them. The second item is to add conda to the environment variable, so that you don’t need to do it manually. Later, you can directly call up conda and python from the command line. After the fourth item is installed, clean up the package residue. Then open the command line and enter conda and python to see if there is any output. If there is, the installation is completed correctly:
insert image description here

conda change source

Copy and paste the following from the command line, replace it with a domestic mirror source, and download faster:

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes

Install pytorch and cuda

In order to ensure that the article is time-sensitive in the future, I will post a picture of how to obtain the installation command on the pytorch official website here :
insert image description here
if the version changes in the future, copy the new command.

Now copy paste the following command:

conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia

Wait for about 15 minutes after the installation is complete, open the system advanced settings, click path to add environment variables:
insert image description here
add the two paths of bin and include under miniconda3, here the ellipsis means that you fill in the path yourself:

.../miniconda3/bin
.../miniconda3/include

Then enter python on the command line to activate the python environment, and enter the following code:

import torch
print(torch.cuda.is_available())
print(torch.backends.cudnn.is_available())
print(torch.cuda_version)
print(torch.backends.cudnn.version())

The first two prints are printed as True, and the latter two version numbers can be printed correctly.

onnxruntime uses cuda to accelerate

First install onnxruntime-gpu from the command line.

pip install onnxruntime-gpu -i https://mirror.baidu.com/pypi/simple

Next, if you want to use cuda to accelerate, you must import pytorch before importing onnxruntime, otherwise error 126 will be displayed, and the cuda environment cannot be found:

import pytorch
import onnxruntime

This is because this method actually downloads the cuda and cudnn components related to pytorch, which are not in the default search path of onnxruntime, but if you import pytorch first, there will be a cuda library in the environment that can be called.

Guess you like

Origin blog.csdn.net/weixin_43945848/article/details/130316110