Commit
·
e42f9e7
1
Parent(s):
0080e32
feature: estimates metrics for unavailable states
Browse files- during inference phase, the metrics are read from the offline
dataset by querying the current state. When there is no record
corresponding to the state, then the metrics are estimated by using
the twin model.
- agent/backend/policy.py +2 -2
- agent/backend/utils.py +5 -4
- agent/dashboard/inference.py +11 -4
agent/backend/policy.py
CHANGED
|
@@ -19,7 +19,7 @@ $$ \max_{state} reward(model(state)) $$
|
|
| 19 |
self.label = """PolicyArgMax: pursue max reward """
|
| 20 |
|
| 21 |
def choose(self, model, ds, input_ranges, cur_state, cur_metrics, reward_fn):
|
| 22 |
-
print(input_ranges)
|
| 23 |
|
| 24 |
input_df, output_df = predict_dict(model, ds, input_ranges)
|
| 25 |
|
|
@@ -28,7 +28,7 @@ $$ \max_{state} reward(model(state)) $$
|
|
| 28 |
io_df['reward'] = io_df.apply(lambda row: reward_fn.calculate(row), axis=1)
|
| 29 |
max_reward_index = io_df['reward'].argmax()
|
| 30 |
next_state = io_df.loc[max_reward_index].to_dict()
|
| 31 |
-
print('next state', next_state)
|
| 32 |
return next_state
|
| 33 |
|
| 34 |
|
|
|
|
| 19 |
self.label = """PolicyArgMax: pursue max reward """
|
| 20 |
|
| 21 |
def choose(self, model, ds, input_ranges, cur_state, cur_metrics, reward_fn):
|
| 22 |
+
#print(input_ranges)
|
| 23 |
|
| 24 |
input_df, output_df = predict_dict(model, ds, input_ranges)
|
| 25 |
|
|
|
|
| 28 |
io_df['reward'] = io_df.apply(lambda row: reward_fn.calculate(row), axis=1)
|
| 29 |
max_reward_index = io_df['reward'].argmax()
|
| 30 |
next_state = io_df.loc[max_reward_index].to_dict()
|
| 31 |
+
#print('next state', next_state)
|
| 32 |
return next_state
|
| 33 |
|
| 34 |
|
agent/backend/utils.py
CHANGED
|
@@ -46,10 +46,11 @@ def read_metrics(df, cur_state):
|
|
| 46 |
cols = list(df.columns)
|
| 47 |
|
| 48 |
dff = df[cols]
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
| 53 |
output_df = dff.sample(1)
|
| 54 |
for feature in ['replica','cpu','expected_tps']:
|
| 55 |
if feature in cols:
|
|
|
|
| 46 |
cols = list(df.columns)
|
| 47 |
|
| 48 |
dff = df[cols]
|
| 49 |
+
for col, value in cur_state.items():
|
| 50 |
+
#print(f'{col} = {value}', dff.columns)
|
| 51 |
+
dff = dff.query(f'{col} == {value}')
|
| 52 |
+
if len(dff) == 0:
|
| 53 |
+
return None
|
| 54 |
output_df = dff.sample(1)
|
| 55 |
for feature in ['replica','cpu','expected_tps']:
|
| 56 |
if feature in cols:
|
agent/dashboard/inference.py
CHANGED
|
@@ -44,7 +44,7 @@ def force_render():
|
|
| 44 |
@solara.component
|
| 45 |
def InferencePlots(render_count):
|
| 46 |
|
| 47 |
-
|
| 48 |
|
| 49 |
def execute():
|
| 50 |
#print(selected_policy_label, selected_reward_label, selected_load_label)
|
|
@@ -62,7 +62,7 @@ def InferencePlots(render_count):
|
|
| 62 |
|
| 63 |
|
| 64 |
df = ds.df
|
| 65 |
-
print(df.columns)
|
| 66 |
# get all possible values for inputs
|
| 67 |
input_ranges = {col: list(pd.unique(df[col])) for col in input_cols}
|
| 68 |
|
|
@@ -72,6 +72,7 @@ def InferencePlots(render_count):
|
|
| 72 |
cur_hist = {}
|
| 73 |
replica = initial_replica.value
|
| 74 |
cpu = initial_cpu.value
|
|
|
|
| 75 |
for load, eod in load_profile:
|
| 76 |
if step > nsteps.value:
|
| 77 |
break
|
|
@@ -83,9 +84,13 @@ def InferencePlots(render_count):
|
|
| 83 |
|
| 84 |
if use_model_to_estimate_metrics.value:
|
| 85 |
cur_metrics = estimate_metrics(model, ds, cur_state)
|
| 86 |
-
print(cur_metrics)
|
| 87 |
else:
|
| 88 |
cur_metrics = read_metrics(df, cur_state)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
combined_data = cur_state | cur_metrics
|
| 91 |
for state, value in combined_data.items():
|
|
@@ -112,6 +117,7 @@ def InferencePlots(render_count):
|
|
| 112 |
cpu = next_state['cpu']
|
| 113 |
|
| 114 |
step += 1
|
|
|
|
| 115 |
|
| 116 |
|
| 117 |
with solara.Row():
|
|
@@ -130,7 +136,8 @@ def InferencePlots(render_count):
|
|
| 130 |
solara.Warning("There is no trained model ye, please train one!")
|
| 131 |
|
| 132 |
solara.Button(label="Execute", on_click=execute, disabled=model is None)
|
| 133 |
-
|
|
|
|
| 134 |
|
| 135 |
#print('Interence plots')
|
| 136 |
with solara.ColumnsResponsive():
|
|
|
|
| 44 |
@solara.component
|
| 45 |
def InferencePlots(render_count):
|
| 46 |
|
| 47 |
+
unavailable_states_in_data, set_unavailable_states_in_data = solara.use_state_or_update(0)
|
| 48 |
|
| 49 |
def execute():
|
| 50 |
#print(selected_policy_label, selected_reward_label, selected_load_label)
|
|
|
|
| 62 |
|
| 63 |
|
| 64 |
df = ds.df
|
| 65 |
+
#print(df.columns)
|
| 66 |
# get all possible values for inputs
|
| 67 |
input_ranges = {col: list(pd.unique(df[col])) for col in input_cols}
|
| 68 |
|
|
|
|
| 72 |
cur_hist = {}
|
| 73 |
replica = initial_replica.value
|
| 74 |
cpu = initial_cpu.value
|
| 75 |
+
state_not_found_in_data = 0
|
| 76 |
for load, eod in load_profile:
|
| 77 |
if step > nsteps.value:
|
| 78 |
break
|
|
|
|
| 84 |
|
| 85 |
if use_model_to_estimate_metrics.value:
|
| 86 |
cur_metrics = estimate_metrics(model, ds, cur_state)
|
| 87 |
+
#print(cur_metrics)
|
| 88 |
else:
|
| 89 |
cur_metrics = read_metrics(df, cur_state)
|
| 90 |
+
if cur_metrics is None:
|
| 91 |
+
print('there is no data for this state',cur_state)
|
| 92 |
+
state_not_found_in_data += 1
|
| 93 |
+
cur_metrics = estimate_metrics(model, ds, cur_state)
|
| 94 |
|
| 95 |
combined_data = cur_state | cur_metrics
|
| 96 |
for state, value in combined_data.items():
|
|
|
|
| 117 |
cpu = next_state['cpu']
|
| 118 |
|
| 119 |
step += 1
|
| 120 |
+
set_unavailable_states_in_data(state_not_found_in_data)
|
| 121 |
|
| 122 |
|
| 123 |
with solara.Row():
|
|
|
|
| 136 |
solara.Warning("There is no trained model ye, please train one!")
|
| 137 |
|
| 138 |
solara.Button(label="Execute", on_click=execute, disabled=model is None)
|
| 139 |
+
if unavailable_states_in_data > 0:
|
| 140 |
+
solara.Warning(f'There are {unavailable_states_in_data} unavailable states in data. Estimatated versions are used!')
|
| 141 |
|
| 142 |
#print('Interence plots')
|
| 143 |
with solara.ColumnsResponsive():
|