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

Commit 4638b9d

Browse files
author
Jules Pondard
committed
Add random search baseline
Generate a graph of the performance of a random search for a given kernel and inputs sizes.
1 parent 8ee3d96 commit 4638b9d

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 my_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+
(tc_code, tc_name, inp, init_input_sz) = my_utils.get_convolution_example()
20+
21+
my_utils.computeCat(inp)
22+
my_utils.set_tc(tc_code, tc_name)
23+
24+
NB_HYPERPARAMS, INIT_INPUT_SZ = my_utils.NB_HYPERPARAMS, my_utils.INIT_INPUT_SZ
25+
26+
def getRandom():
27+
opt_v = np.zeros(NB_HYPERPARAMS).astype(int)
28+
for i in range(opt_v.shape[0]):
29+
opt_v[i] = np.random.randint(my_utils.cat_sz[i])
30+
return opt_v
31+
32+
33+
INTER_DISP = 20
34+
35+
running_reward = -0.5
36+
tab_rewards=[]
37+
tab_best=[]
38+
best=-12
39+
best_options = -1
40+
for i in range(NB_EPOCHS):
41+
rewards = []
42+
opts=[]
43+
for j in range(BATCH_SZ):
44+
out = getRandom()
45+
reward = my_utils.evalTime(out.astype(int), prune=2, curr_best=np.exp(-best))
46+
reward = -np.log(reward)
47+
rewards.append(reward)
48+
opts.append(out.astype(int))
49+
if(best < np.max(rewards) or i==0):
50+
best = np.max(rewards)
51+
ind=np.argmax(rewards)
52+
best_options = opts[ind]
53+
my_utils.print_opt(best_options)
54+
if(i==0):
55+
running_reward = reward
56+
running_reward = running_reward * 0.99 + np.mean(rewards) * 0.01
57+
tab_rewards.append(-running_reward)
58+
tab_best.append(-best)
59+
if i % INTER_DISP == 0:
60+
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"]))
61+
print(-running_reward)
62+
print(-best)
63+
tab_best = np.array(tab_best)
64+
np.save("randomsearch.npy", tab_best)
65+
print("Finally, best options are:")
66+
my_utils.print_opt(best_options)

0 commit comments

Comments
 (0)