如何成功地安装pytorch库

如何成功安装torch库

首先进入https://pytorch.org/get-started/locally/,一般会自动识别当前设备适应版本,你可以选择CONDA,或者pip两种安装方式。前提是你装好了anaconda和Python环境,以及pip。
在这里插入图片描述
比如我选择
**
stable(稳定版)
Windows系统
pip安装方式
Python语言**
CUDA11.3
run this command(执行此命令) 如下

pip3 install torch1.10.0+cu113 torchvision0.11.1+cu113 torchaudio===0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html

CUDA是什么,如何识别你的cuda版本

1)按win+Q,输入控制面板,然后查看方式小图标,点击NVIDIA控制面板:
Win11系统,点击底部搜索图标,输入NVIDIA控制面板,点击弹出。
2)点击NVIDIA控制面板的帮助,点击左下角系统信息:
3)点击组件:这里就显示了你的CUDA的信息啦!!!
cuda版本查看在这里插入图片描述
如果你在安装过程中执行报
pytorch Key already registered with the same priority: GroupSpatialSoftmax
那么可能是你安装了不同版本的torch

执行两遍
pip uninstall torch
pip uninstall torch
再执行你的安装命令:
pip3 install torch1.10.0+cu113 torchvision0.11.1+cu113 torchaudio===0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html

如何检测torch是否安装成功
import torch # 如正常则静默
a = torch.Tensor([1.]) # 如正常则静默
a.cuda() # 如正常则返回"tensor([ 1.], device=‘cuda:0’)"
from torch.backends import cudnn # 如正常则静默
cudnn.is_acceptable(a.cuda()) # 如正常则返回 “True”
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/auagm168/article/details/121885249