-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinference.py
55 lines (44 loc) · 1.6 KB
/
inference.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
import os
import time
import csv
from model.utils.test_policy import load_policy_and_env, run_policy
from model.synthetic import set_slo
NCONFS = [5, 10, 25, 50, 100]
NCOMPS = [3, 5, 10, 20]
EPISODE_COUNT = 20
for name, knob in [('op',0.03), ('std',0.05), ('up',0.07)]:
slo = 150
freq = int(1e6 / slo)
print(f"SLO: {slo}, Freq: {freq}, Knob: {knob}")
set_slo(slo, freq, knob)
time_tracker = []
dir = './data/'
out_dir = './infer_logs/'
out_path = os.path.join(out_dir, 'inference.csv')
fix = lambda x: x + '/' + x + '_s0/'
os.makedirs(out_dir+name, exist_ok=True)
for nconf in NCONFS:
for ncomp in NCOMPS:
model_path = os.path.join(dir, fix(f'std-f{nconf}-c{ncomp}'))
params = {
'log_dir':out_dir+name,
'steps_per_epoch': 1000,
'budget': [2500, 3600],
'slo_latency': slo,
'overrun_lim': 0.2,
'mode': 'synthetic',
'nconf': nconf,
'ncomp': ncomp,
}
try:
env, get_action = load_policy_and_env(model_path, 'last', params)
except:
continue
start = time.time()
run_policy(env, get_action, out_path, num_episodes=EPISODE_COUNT)
end = time.time()
time_tracker.append([name, nconf, ncomp, end - start])
with open(f'./infer_logs/time_tracker_{name}.csv', 'a') as f:
writer = csv.writer(f)
writer.writerow(['Name', 'Configs', 'Components', 'Time'])
writer.writerows(time_tracker)