Skip to content

Commit cb20b62

Browse files
minor function signature changes
1 parent 6c25c72 commit cb20b62

1 file changed

Lines changed: 53 additions & 37 deletions

File tree

analysis/timefit.py

Lines changed: 53 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ def inference(d, n_iter, lr, workload, sys, print_freq=10):
3030
criterion = nn.MSELoss()
3131
optimizer = optim.Adam([log_max_time, alpha, itr_suppress], lr=lr)
3232

33-
print(f'---------------{workload} {sys} lr = {lr}---------------')
34-
3533
for _ in range(n_iter):
3634
max_time = torch.exp(log_max_time)
3735
pred = itr_suppress*itr + max_time/dvfs**(1+alpha)
@@ -47,44 +45,62 @@ def inference(d, n_iter, lr, workload, sys, print_freq=10):
4745

4846
print(f'{max_time.item():^10.3f} {alpha.item():^10.3f} {itr_suppress.item():^10.3f} {loss.item():^10.3f}')
4947

50-
return pred
48+
return pred, {'max_time': max_time.item(), 'alpha': alpha.item(), 'itr_suppress': itr_suppress.item()}
5149

52-
def run(n_iter=2000, lr=1e-1, target_col='read_99th_mean'):
50+
def run_all(n_iter=1000, lr=1e-2):
51+
for qps in [200000,400000, 60000]:
52+
for sys in ['linux_tuned', 'ebbrt_tuned']:
53+
for target_col in [f'read_{i}th_mean' for i in [5, 10, 50, 90, 99]]:
54+
run(n_iter=n_iter, lr=lr, sys=sys, qps=qps, target_col=target_col)
55+
56+
57+
def run(n_iter=2000,
58+
lr=1e-1,
59+
target_col='read_99th_mean',
60+
sys='ebbrt_tuned',
61+
qps=400000):
62+
5363
#read linux_mcd.csv
5464
for workload in ['mcd']:
55-
df_comb, _, _ = read_agg_data.start_analysis(workload) #DATA
65+
#read raw data: TODO check all preprocessing is correct
66+
df_comb, _, _ = read_agg_data.start_analysis(workload)
5667
df_comb['dvfs'] = df_comb['dvfs'].apply(lambda x: int(x, base=16))
5768
df_comb = df_comb[(df_comb['itr']!=1) | (df_comb['dvfs']!=65535)] #filter out linux dynamic
5869
df_comb['dvfs'] = df_comb['dvfs'].astype(float) / df_comb['dvfs'].min()
59-
df_comb = df_comb[df_comb['QPS'] == 400000]
60-
61-
for sys in ['ebbrt_tuned']:
62-
df = df_comb[(df_comb['sys']==sys)].copy()
63-
df = df[[target_col,'itr', 'dvfs']]
64-
d = df.values
65-
d = torch.tensor(d)
66-
67-
pred = inference(d, n_iter, lr, workload, sys, print_freq=500)
68-
df[f'prediction lr={lr}'] = pred.detach().numpy()
69-
70-
fig, ax = plt.subplots()
71-
plt.title(f'workload={workload} system={sys} lr={lr} QPS=400000')
72-
plt.xlabel(u"predictions")
73-
plt.ylabel(u"actual values")
74-
75-
scatter = ax.scatter(pred.detach().numpy(), d[:,0], marker = 'o', s = d[:,1], c = d[:,2], alpha=0.3)
76-
77-
legend1 = ax.legend(*scatter.legend_elements(),loc="upper left", title="dvfs")
78-
ax.add_artist(legend1)
79-
handles, labels = scatter.legend_elements(prop="sizes", alpha=0.6)
80-
legend2 = plt.legend(handles, labels, loc="lower right", title="itr")
81-
ax.add_artist(legend2)
82-
83-
ax.set_xlim(0, ax.get_xlim()[1])
84-
ax.set_ylim(0, ax.get_ylim()[1])
85-
ax.grid()
86-
87-
ax.plot(np.arange(0, int(ax.get_xlim()[1])), np.arange(0, int(ax.get_xlim()[1])))
88-
89-
plt.savefig(f'plots/timefit/{workload}_{sys}_{lr}.png')
90-
plt.close()
70+
df_comb = df_comb[df_comb['QPS'] == qps]
71+
72+
#filter to system
73+
df = df_comb[(df_comb['sys']==sys)].copy()
74+
df = df[[target_col,'itr', 'dvfs']]
75+
d = df.values
76+
d = torch.tensor(d)
77+
78+
#fitting
79+
print(f'----------{workload} {sys} QPS={qps} {target_col}-------------')
80+
if df.shape==0:
81+
raise ValueError('Empty Dataframe')
82+
pred, params = inference(d, n_iter, lr, workload, sys, print_freq=500)
83+
df[f'prediction lr={lr}'] = pred.detach().numpy()
84+
85+
#plotting
86+
fig, ax = plt.subplots()
87+
plt.title(f"{workload} {sys} {qps} {target_col}\n maxtime={params['max_time']:.2f} alpha={params['alpha']:.2f} itr_suppress={params['itr_suppress']:.2f}")
88+
plt.xlabel(u"predictions")
89+
plt.ylabel(u"actual values")
90+
91+
scatter = ax.scatter(pred.detach().numpy(), d[:,0], marker = 'o', s = d[:,1], c = d[:,2], alpha=0.3)
92+
93+
legend1 = ax.legend(*scatter.legend_elements(),loc="upper left", title="dvfs")
94+
ax.add_artist(legend1)
95+
handles, labels = scatter.legend_elements(prop="sizes", alpha=0.6)
96+
legend2 = plt.legend(handles, labels, loc="lower right", title="itr")
97+
ax.add_artist(legend2)
98+
99+
ax.set_xlim(0, ax.get_xlim()[1])
100+
ax.set_ylim(0, ax.get_ylim()[1])
101+
ax.grid()
102+
103+
ax.plot(np.arange(0, int(ax.get_xlim()[1])), np.arange(0, int(ax.get_xlim()[1])))
104+
105+
plt.savefig(f'plots/timefit/{workload}_{sys}_{target_col}_{qps}_{lr}.png')
106+
plt.close()

0 commit comments

Comments
 (0)