文章目錄
- 1. 配置cuda環境
- 2. 配置conda環境
- 3. 配置pytorch gpu環境
1. 配置cuda環境
- 在命令行輸入以下命令可以查看當前顯卡驅動版本和最高支持的cuda版本
nvidia-smi
- 根據cuda版本去官網下載并安裝cuda
下載鏈接:https://developer.nvidia.com/cuda-toolkit-archive - 根據cuda、cudnn版本對照表下載安裝合適的cudnn
版本對照:https://docs.nvidia.com/deeplearning/cudnn/backend/v9.12.0/reference/support-matrix.html
下載鏈接:https://developer.nvidia.com/cudnn-archive
2. 配置conda環境
- 去官網下載anaconda
下載鏈接:https://repo.anaconda.com/archive - conda換源
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/ conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/ conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/ conda config --set show_channel_urls yes
- pip換源
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
- 安裝uv
pip install uv
- 安裝conda環境(python維護周期查詢)
conda create -n [環境名] python=3.x -y
3. 配置pytorch gpu環境
- 先去官網查詢安裝torch等庫的命令
官網鏈接:https://pytorch.org/get-started/previous-versions/ - 使用在命令前加上uv再執行命令提高下載速度,比如
uv pip install torch==2.7.1 torchvision==0.22.1 torchaudio==2.7.1 --index-url https://download.pytorch.org/whl/cu128
- 安裝后,運行python,執行以下代碼驗證是否配置成功
import torch torch.cuda.is_available() torch.cuda.get_device_name(0)