Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit 41f57f8

Browse files
Jules PondardJules Pondard
authored andcommitted
Add random search baseline
Generate a graph of the performance of a random search for a given kernel and inputs sizes.
1 parent 56610d2 commit 41f57f8

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import numpy as np
2+
#import ipdb
3+
import torch
4+
import torch.optim as optim
5+
import torch.nn as nn
6+
import torch.utils.data
7+
import torch.nn.functional as F
8+
import tensor_comprehensions as tc
9+
from visdom import Visdom
10+
11+
import utils
12+
13+
NB_EPOCHS = 1000
14+
BATCH_SZ = 1
15+
16+
viz = Visdom()
17+
win0 = viz.line(X=np.arange(NB_EPOCHS), Y=np.random.rand(NB_EPOCHS))
18+
19+
exptuner_config = utils.ExpTunerConfig()
20+
exptuner_config.set_convolution_tc()
21+
22+
NB_HYPERPARAMS = utils.NB_HYPERPARAMS
23+
24+
def getRandom():
25+
opt_v = np.zeros(NB_HYPERPARAMS).astype(int)
26+
for i in range(opt_v.shape[0]):
27+
opt_v[i] = np.random.randint(exptuner_config.cat_sz[i])
28+
return opt_v
29+
30+
INTER_DISP = 20
31+
32+
running_reward = -0.5
33+
tab_rewards=[]
34+
tab_best=[]
35+
best=-12
36+
best_options = -1
37+
for i in range(NB_EPOCHS):
38+
rewards = []
39+
opts=[]
40+
for j in range(BATCH_SZ):
41+
out = getRandom()
42+
reward = utils.evalTime(out.astype(int), exptuner_config, prune=2, curr_best=np.exp(-best))
43+
reward = -np.log(reward)
44+
rewards.append(reward)
45+
opts.append(out.astype(int))
46+
if(best < np.max(rewards) or i==0):
47+
best = np.max(rewards)
48+
ind=np.argmax(rewards)
49+
best_options = opts[ind]
50+
utils.print_opt(best_options)
51+
if(i==0):
52+
running_reward = reward
53+
running_reward = running_reward * 0.99 + np.mean(rewards) * 0.01
54+
tab_rewards.append(-running_reward)
55+
tab_best.append(-best)
56+
if i % INTER_DISP == 0:
57+
viz.line(X=np.column_stack((np.arange(i+1), np.arange(i+1))), Y=np.column_stack((np.array(tab_rewards), np.array(tab_best))), win=win0, opts=dict(legend=["Geometric run", "Best time"]))
58+
print(-running_reward)
59+
print(-best)
60+
tab_best = np.array(tab_best)
61+
np.save("randomsearch.npy", tab_best)
62+
print("Finally, best options are:")
63+
utils.print_opt(best_options)

0 commit comments

Comments
 (0)