0
点赞
收藏
分享

微信扫一扫

PyTorch安装

sullay 2022-03-27 阅读 105

亲测可行!RTX3060显卡驱动版本11.3,CUDA版本11.2,cudnn版本是与CUDA对应的版本11.2。

  • 安装好CUDA和cudnn。

  • 在Annaconda中新建环境“PyTorch”;
    在这里插入图片描述

  • 然后从Anaconda Prompt进入,切换环境到“PyTorch”
    在这里插入图片描述

  • 然后从PyTorch官网选择符合自己计算机CUDA的版本,如下
    在这里插入图片描述

  • 复制Run this Command中的代码(例如,我的CUDA版本是11.2,cudnn版本是与CUDA对应的版本11.2,RTX显卡驱动版本是11.3)

pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
  • 回车运行上述代码,等待安装(约2个多G),大约耗时十几分钟;
  • 验证是否安装成功,在Anaconda的环境“PyTorch”中启动spyder、vscode等程序(确保切换到了对应的环境“PyTorch”),运行以下代码
import torch
x = torch.rand(5, 3)
print(x)

运行结果类似于:
在这里插入图片描述

这个只是验证PyTorch是否安装上,还要验证是否能调用GPU(这个很关键,否则只是用CPU运行PyTorch,没有利用GPU,计算速度很低)

torch.cuda.is_available()

运行结果输出True
在这里插入图片描述
完整测试代码参考:

import torch
a = torch.cuda.is_available()
print(a)

x = torch.rand(5, 3)
print(x)
举报

相关推荐

0 条评论