ubuntu配置cuda环境三:安装PyTorch 您所在的位置:网站首页 支持CUDA ubuntu配置cuda环境三:安装PyTorch

ubuntu配置cuda环境三:安装PyTorch

2023-03-09 06:04| 来源: 网络整理| 查看: 265

安装GPU版本的PyTorch

可以直接访问PyTorch官网生成安装命令,但是下载速度较慢

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-FBo7iNB0-1670935047591)(https://pictures-1258408207.cos.ap-nanjing.myqcloud.com/cuda%E5%92%8Ccudnn%E5%AE%89%E8%A3%85/pytorchDownloadMl.png)]

此处,可以到此链接下载对应的离线包:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-jPHwjM0h-1670935047593)(https://pictures-1258408207.cos.ap-nanjing.myqcloud.com/cuda%E5%92%8Ccudnn%E5%AE%89%E8%A3%85/pytorchLx.png)]

下载好离线包后,使用以下命令进行安装:

pip install torch-1.7.0+cu101-cp38-cp38-linux_x86_64.whl -i https://pypi.tuna.tsinghua.edu.cn/simple/

再安装其他的库(按需安装)

pip install torch==1.7.0+cu101 torchvision==0.8.1+cu101 torchaudio==0.7.0 -f https://download.pytorch.org/whl/torch_stable.html

最后可通过以下代码测试环境是否安装成功

import torch import torchvision if __name__ == "__main__": print(torch.__version__) # 查看torch当前版本号 print(torchvision.__version__) # 查看CUDA版本号: print(torch.version.cuda) # 编译当前版本的torch使用的cuda版本号 # 测试Cudnn是否安装成功 from torch.backends import cudnn print(cudnn.is_available()) # 是否GPU可用 print(torch.cuda.is_available()) # 查看当前cuda是否可用于当前版本的Torch,如果输出True,则表示可用


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有