pytorch加速下载——清华镜像源(conda或者pip版本)

方法一:

1、查看自己电脑安装的cuda版本

打开终端(ctrl+alt+t)输入:

nvcc -V

2、打开终端,使用 conda 安装

安装前需要添加清华源,直接在终端或者创建的虚拟环境中输入相继运行下列五行命令:

# 添加清华源的pytorch
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

conda install pytorch torchvision cudatoolkit=10.0  # 删除安装命令最后的 -c pytorch,才会采用清华源安装。

3、安装完成后,测试torch和CUD

1)为了确保PyTorch安装正确,我们可以运行示例PyTorch代码来验证安装。这里我们将构造一个随机初始化的张量。

from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)

# The output should be something similar to:
# tensor([[0.2989, 0.2493, 0.2642],
#         [0.9508, 0.4811, 0.1085],
#         [0.5423, 0.3216, 0.3068],
#         [0.8863, 0.8385, 0.5150],
#         [0.8451, 0.4620, 0.6266]])

如下图所示:
在这里插入图片描述
2)此外,要检查GPU驱动程序和CUDA是否能够被PyTorch启用和访问,需要运行以下命令以返回CUDA驱动程序是否已启用:

import torch
torch.cuda.is_available()

# the output is: True

如下图所示:
在这里插入图片描述
最后,大功告成!

方法二:

pip使用清华镜像源

临时使用

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package

some-package替换为所需模块即可(还真有个模块叫some-package)
如果报错,可能是因为pip版本不够(需≥10.0.0),先升级pip:

pip install pip -U

当然,升级pip本身也可以使用清华镜像源。

安装pytorch

进入pytorch的官网,根据系统、python版本、cuda版本选择下载命令。
在这里插入图片描述添加上文所说的参数,然后记得去掉 -f https://download.pytorch.org/whl/torch_stable.html,否则依然会很慢。即可通过清华镜像源高速下载pytorch,这里我下载的是pytorch1.3版本:

pip install torch===1.3.0 torchvision===0.4.1 -i https://pypi.tuna.tsinghua.edu.cn/simple

国内其他pip源:

清华:https://pypi.tuna.tsinghua.edu.cn/simple
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/
豆瓣:http://pypi.douban.com/simple/
  • 53
    点赞
  • 204
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
使用清华镜像源下载pip的步骤如下: 1. 首先,你可以使用清华镜像站的搜索功能来查找你需要下载pip包。你可以访问清华镜像站的网站,并在搜索框中输入你要查找的包的名称。 2. 如果你已经确定要使用清华镜像源作为pip下载源,你可以通过命令行工具更换清华镜像源。在命令提示符或终端中输入以下命令来更换清华镜像源:`pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple`。这样设置后,pip将会使用清华镜像源下载包。 3. 如果你使用的是Anaconda,你可以通过conda下载包。你可以使用以下命令来设置清华镜像源:`conda config --add channels https://mirrors.tuna.tsinghua.edu.***如果你想使用清华镜像源下载pip包,你可以使用清华镜像站的搜索功能来查找包,并通过命令行工具或conda来设置清华镜像源下载包。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [清华镜像站下载python第三方库、pip通过清华镜像站下载第三方库](https://blog.csdn.net/m0_46114594/article/details/111771228)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [更换pypi镜像源与pip使用](https://download.csdn.net/download/weixin_38642636/14856194)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [通过清华镜像源加速下载pytorch——(pip版本)](https://blog.csdn.net/WannaSeaU/article/details/102830613)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值