1.查看CUDA支持最高版本

在显卡驱动正常安装的情况下,输入下面命令可以查看CUDA支持的最高版本

nvidia-smi

从这里可以看到当前显卡最高CUDA支持版本为12.1

2.安装CUDA

  • NVIDIA官方网站:https://developer.nvidia.com/cuda-toolkit-archive

  • 选择离线安装包

  • 后续下载完成之后点击安装,下一步 下一步...即可

  • 输入:nvcc -V 查看是否安装成功

2.5 安装cudnn

https://developer.nvidia.com/cudnn

3.安装torch、torchvision、torchaudio

  • PyTorch 安装页面:https://pytorch.org/get-started/locally/

  • 选择系统、安装器、版本、编程语言

pip install torch==2.1.0+cu121 torchvision==0.16.0+cu121 torchaudio==2.1.0+cu121 --index-url https://download.pytorch.org/whl/cu121 --no-cache-dir

4.安装完成后验证GPU是否可用

import torch

print(torch.__version__)
print(torch.cuda.is_available())
if torch.cuda.is_available():
    print(torch.cuda.get_device_name(0))