conda安装pytorch

说明

  1. 使用conda安装,不建议使用pip安装;
  2. cuda使用10.0或更高版本.

anaconda版本

Anaconda3-2019.10-Windows-x86_64.exe

windows10安装cuda10.2

windows10安装cuda10.2

配置国内清华镜像源

https://blog.csdn.net/bingo_liu/article/details/103224105

切换到pytorch环境

conda activate pytorch

安装到当前环境

conda install pytorch==1.2.0 torchvision==0.4.0 cudatoolkit=10.0 -c pytorch

**提示:**虽然使用了国内源,但是安装过程中提示错误:

CondaHTTPError: HTTP 000 CONNECTION FAILED for url <https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/win-64/pytorch-1.2.0-py3.7_cuda100_cudnn7_1.tar.bz2>
Elapsed: -

An HTTP error occurred when trying to retrieve this URL.
HTTP errors are often intermittent, and a simple retry will get you on your way.

重试几次或十来次或会成功

验证

(pytorch) C:\Users\Administrator>python
Python 3.7.5 (default, Oct 31 2019, 15:18:51) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print(torch.__version__)
1.2.0

测试对比cpu和gpu

# coding=utf-8
import torch
from time import perf_counter

x = torch.rand(10000, 100000)
y = torch.rand(100000, 10000)

# CPU
start = perf_counter()
x.mm(y)
finish = perf_counter()
time = finish - start
print("CPU计算时间:%s" % time)

# GPU
if torch.cuda.is_available():
    x = x.cuda()
    y = y.cuda()
    start = perf_counter()
    x.mm(y)
    finish = perf_counter()
    time_cuda = finish - start
    print("GPU加速计算的时间:%s" % time_cuda)
    print("CPU计算时间是GPU加速计算时间的%s倍" % str(time / time_cuda))

else:
    print("未支持CUDA")

输出

# CPU计算时间:108.6555498
# GPU加速计算的时间:0.21388500000000477
# CPU计算时间是GPU加速计算时间的508.0092096219818倍

如果机子内存不够,请将矩阵x的列数和y的行数改小点,哈哈

  • 1
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值