Today, ubuntu16.04 version of pytorch configuration a bit. Stepped pit point, record it (at the end of a successful approach).
1, because the computer can not access science, so do not be in accordance with official website. https://pytorch.org/
2, online tutorial and reference cloudy teacher Tutorial: conda command to install.
(1) Domestic Mirror added:
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
(2) Installation pytorch
conda install pytorch torchvision cuda80 #cuda80对应cuda版本号(cuda8.0)
And there are a problem, other packages can be installed pytorch dependent achieved by this method, but the torch, torchvision, cudatoolkit still can not successfully install. Ever since, I enabled third method pip install.
3, the same reference to some online tutorials: Using pip command to install (you may be prompted to update pip, follow the prompts to update that).
(1) Ubuntu source arranged pip
1. 创建pip.conf文件
运行以下命令:
cd ~/.pip
如果提示目录不存在的话,我们要自行创建一个,再进入目录
mkdir ~/.pip
cd ~/.pip
在.pip目录下创建一个pip.conf文件
touch pip.conf
文件就创建好了(当然如果你已经有这个文件了这步可以跳过).
2. 编辑pip.conf文件
gedit pip.conf
打开pip.conf文件窗口,将以下内容复制到文件中:
[global]
index-url = http://pypi.douban.com/simple #这个镜像可以根据实际情况更改
[install]
trusted-host=pypi.douban.com
China is known to add a mirror:
Watercress (douban) http://pypi.douban.com/simple/
Tsinghua https://pypi.tuna.tsinghua.edu.cn/simple/
Ali cloud http://mirrors.aliyun.com/pypi/simple/
China University of Science and technology https://pypi.mirrors.ustc.edu.cn/simple/
University of Science and technology of China http://pypi.mirrors.ustc.edu.cn/simple/
(2) Installation pytorch
pip install torch torchvision
(3) test is successfully installed
import torch
import torchvision
如果没有报错那基本就是完成了
(See GPU whether to call up and thrown small example)
import torch
import time
print(torch.__version__)
print(torch.cuda.is_available())
# print('hello, world.')
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)
t2 = time.time()
print(a.device, t2 - t0, c.norm(2))
t0 = time.time()
c = torch.matmul(a, b)
t2 = time.time()
print(a.device, t2 - t0, c.norm(2))