CUDA版本PyTorch安装

发布时间 2023-09-14 00:42:11作者: yanghui01

安装驱动

显卡为 Nvidia的GTX950M,驱动版本517.48,这个版本的驱动为CUDA_11.7

移动版:GeForce Game Ready 驱动程序 | 517.48 | Windows 11 | NVIDIA

桌面版:GeForce Game Ready 驱动程序 | 517.48 | Windows 10 64-bit, Windows 11 | NVIDIA

 

要使用cuda,必须安装CUDA版本的PyTorch,且版本要和驱动的cuda版本匹配。可以执行以下语句检查当前是否支持CUDA:

import torch

print(torch.cuda.is_available())

如果安装的是CPU版本的PyTorch或者CUDA版本不匹配,将打印False

 

下载cuda版PyTorch

Previous PyTorch Versions | PyTorch

# CUDA 11.7
pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu117

 

在命令行下输入上面的语句

注意:之前已经安装了CPU版本的PyTorch也没事,这边会帮你自动卸载,然后替换为CUDA版本的PyTorch

再运行上面的语句,就打印True了