-
Notifications
You must be signed in to change notification settings - Fork 2
/
inference_old.py
80 lines (64 loc) · 2 KB
/
inference_old.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
70
71
72
73
74
75
76
77
78
79
80
import os
import time
import csv
import numpy as np
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
slo = 150
freq = int(1e6 / np.random.randint(int(slo*0.8), int(slo*1.2)))
knob = 0.05
print(f"SLO: {slo}, Freq: {freq}, Knob: {knob}")
set_slo(slo, freq, knob)
time_tracker = []
dir = './data/'
out_dir = './inf_logs/'
out_path = os.path.join(out_dir, 'inference.log')
fix = lambda x: x + '/' + x + '_s0/'
for ncomp in NCOMPS:
name = f'std-f5-c{ncomp}'
model_path = os.path.join(dir, fix(name))
os.makedirs(out_dir+name, exist_ok=True)
params = {
'log_dir':out_dir+name,
'steps_per_epoch': 1000,
'budget': [1200, 1800],
'slo_latency': slo,
'overrun_lim': 0.2,
'mode': 'synthetic',
'nconf': 5,
'ncomp': ncomp,
}
env, get_action = load_policy_and_env(model_path, 'last', params)
start = time.time()
run_policy(env, get_action, out_path, num_episodes=EPISODE_COUNT)
end = time.time()
time_tracker.append([name, end - start])
for nconf in NCONFS:
name = f'std-f{nconf}-c3'
model_path = os.path.join(dir, fix(name))
params = {
'log_dir':out_dir+name,
'steps_per_epoch': 1000,
'budget': [600, 900],
'slo_latency': slo,
'overrun_lim': 0.2,
'mode': 'synthetic',
'nconf': nconf,
'ncomp': 3,
}
env, get_action = load_policy_and_env(model_path, 'last', params)
with open(out_path, 'w') as f:
writer = csv.writer(f)
writer.writerow(['---------------------'])
writer.writerow([name])
start = time.time()
run_policy(env, get_action, out_path, num_episodes=EPISODE_COUNT)
end = time.time()
time_tracker.append([name, end - start])
with open('./inf_logs/time_tracker.csv', 'w') as f:
writer = csv.writer(f)
writer.writerow(['Name', 'Time'])
writer.writerows(time_tracker)