栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

使用pip+代理下载PyTorch GPU版本(win10系统)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用pip+代理下载PyTorch GPU版本(win10系统)

使用pip+代理下载PyTorch GPU版本(win10系统)
  • 前言
  • 查看PyTorch官网
  • 查看代理服务器地址、端口
  • 使用pip下载
  • 可能出现的错误
    • 1. `ReadTimeoutError`
    • 2. `zipfile.BadZipFile: File is not a zip file`
  • 成功图片和测试代码

前言

本人是新手,如有错误还请指正。
本文章建立在已知需要下载的PyTorch版本、如何使用代理的基础上。
电脑是Win10系统,conda环境也可以使用pip下载。因为直接下载速度非常缓慢,考虑使用代理来提高下载速度。

查看PyTorch官网

首先,需要查看官网确认自己需要下载的PyTorch版本的命令:

pip install torch==1.8.2+cu111 torchvision==0.9.2+cu111 torchaudio===0.8.2 -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html
查看代理服务器地址、端口


可以在代理软件的设置中找到,之后的代码请根据你自己的地址和端口进行修改!

使用pip下载

需要使用pip/pip3的--proxy选项:
127.0.0.1:41091是我的代理服务器地址和端口,请根据你自己的地址和端口进行修改!

pip3 --proxy 127.0.0.1:41091 install torch==1.8.2+cu111 torchvision==0.9.2+cu111 torchaudio===0.8.2 -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html
可能出现的错误 1. ReadTimeoutError

超时出错,考虑加大超时时间(在以上代码中加入--default-timeout=1000):

pip3 --default-timeout=1000 --proxy 127.0.0.1:41091 install torch==1.8.2+cu111 torchvision==0.9.2+cu111 torchaudio===0.8.2 -f https://download.pytorch.org/whl/lts/1.8/torch_lts.html
2. zipfile.BadZipFile: File is not a zip file

这个问题比较奇怪,目前我没有发现较好的解决方法。可能是下载文件出错导致的,和网络稳定性有关,只能重试一次。

成功图片和测试代码

图片如下:

测试代码:
转自:https://blog.csdn.net/luoshiyong123/article/details/107221694/

import torch
# 以下代码只有在PyTorch GPU版本上才会执行
import time

print(torch.__version__)
print(torch.cuda.is_available())
a = torch.randn(10000, 1000)
b = torch.randn(1000, 2000)
t0 = time.time()
c = torch.matmul(a, b)
t1 = time.time()
print(a.device, t1 - t0, c.norm(2))

device = torch.device('cuda')
a = a.to(device)
b = b.to(device)
t0 = time.time()
c = torch.matmul(a, b)
t1 = time.time()
print(a.device, t1 - t0, c.norm(2))

t0 = time.time()
c = torch.matmul(a, b)
t1 = time.time()
print(a.device, t1 - t0, c.norm(2))

结果为:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/357146.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号