linux 下安装 torch0.4.0
必要条件:cuda9
conda create -n py36 python=3.6
conda activate py36
conda install pytorch=0.4.0 -c pytorch
测试:
import torch
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)
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))
输出:
0.4.0
True
cpu 0.4831969738006592 tensor(1.00000e+05 *
1.4141)
cuda:0 0.11518597602844238 tensor(1.00000e+05 *
1.4141, device='cuda:0')
cuda:0 0.001634836196899414 tensor(1.00000e+05 *
1.4141, device='cuda:0')