-
Notifications
You must be signed in to change notification settings - Fork 2
/
measure_stem.py
69 lines (58 loc) · 1.82 KB
/
measure_stem.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import torch
import torch.nn as nn
from operations import *
from genotypes import PRIMITIVES
from genotypes import Genotype
x = torch.cuda.FloatTensor(10000, 500).normal_()
w = torch.cuda.FloatTensor(200, 500).normal_()
torch.cuda.synchronize()
torch.cuda.synchronize()
y = x.mm(w.t())
torch.cuda.synchronize() # wait for mm to finish
class measure_stem(nn.Module):
def __init__(self):
super(measure, self).__init__()
self.x1 = torch.cuda.FloatTensor(10000, 500).normal_()
self.w1 = torch.cuda.FloatTensor(200, 500).normal_()
torch.cuda.synchronize()
torch.cuda.synchronize()
self.stem0 = nn.Sequential(
nn.Conv2d(3, 64, 3, stride=2, padding=1),
nn.BatchNorm2d(64),
nn.ReLU ()
)
self.stem1 = nn.Sequential(
nn.Conv2d(64, 64, 3, padding=1),
nn.BatchNorm2d(64),
nn.ReLU ()
)
self.stem2 = nn.Sequential(
nn.Conv2d(64, 128, 3, stride=2, padding=1),
nn.BatchNorm2d(128),
nn.ReLU ()
)
def forward(self, x):
torch.cuda.synchronize() # wait for mm to finish
time=0
for i in range(10000):
y = self.x1.mm(self.w1.t())
start = torch.cuda.Event(enable_timing=True)
end = torch.cuda.Event(enable_timing=True)
start.record()
z = self.stem0(x)
z1 = self.stem1(z1)
z2 = self.stem2(z2)
end.record()
torch.cuda.synchronize()
if i>4999:
time+=start.elapsed_time(end)
print(time/5000)
torch.cuda.synchronize()
x = torch.cuda.FloatTensor(10, 3, 512, 512).normal_()
x=x.cuda()
model=measure_stem()
model=model.cuda()
model.eval()
with torch.no_grad():
model(x)
print('************************')