Merge pull request #11 from app2scale/feature_display_cost
Browse files
agent/dashboard/inference.py
CHANGED
|
@@ -30,6 +30,7 @@ selected_load_label = solara.reactive(load_labels[0])
|
|
| 30 |
nsteps = solara.reactive(10)
|
| 31 |
initial_replica = solara.reactive(1)
|
| 32 |
initial_cpu = solara.reactive(4)
|
|
|
|
| 33 |
|
| 34 |
use_model_to_estimate_metrics = solara.reactive(False)
|
| 35 |
|
|
@@ -45,6 +46,7 @@ def force_render():
|
|
| 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)
|
|
@@ -73,6 +75,7 @@ def InferencePlots(render_count):
|
|
| 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
|
|
@@ -81,7 +84,8 @@ def InferencePlots(render_count):
|
|
| 81 |
input_ranges['expected_tps'] = [load]
|
| 82 |
|
| 83 |
cur_state = {"replica": replica, "cpu": cpu, "expected_tps": load}
|
| 84 |
-
|
|
|
|
| 85 |
if use_model_to_estimate_metrics.value:
|
| 86 |
cur_metrics = estimate_metrics(model, ds, cur_state)
|
| 87 |
#print(cur_metrics)
|
|
@@ -120,10 +124,11 @@ def InferencePlots(render_count):
|
|
| 120 |
set_unavailable_states_in_data(state_not_found_in_data)
|
| 121 |
|
| 122 |
|
| 123 |
-
with solara.
|
| 124 |
solara.InputInt(label='Number of steps', value=nsteps.value, on_value=nsteps.set)
|
| 125 |
solara.InputInt(label="Initial replica", value=initial_replica)
|
| 126 |
solara.InputInt(label="Initial CPU", value=initial_cpu)
|
|
|
|
| 127 |
if set(training_state.value['input_cols'].value) == set(['replica','cpu','expected_tps']):
|
| 128 |
solara.Checkbox(label='Use twin model to estimate metrics', value=use_model_to_estimate_metrics)
|
| 129 |
else:
|
|
@@ -140,6 +145,8 @@ def InferencePlots(render_count):
|
|
| 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():
|
| 144 |
for col, content in local_state.value['inference_plot_data'].value.items():
|
| 145 |
options = {
|
|
|
|
| 30 |
nsteps = solara.reactive(10)
|
| 31 |
initial_replica = solara.reactive(1)
|
| 32 |
initial_cpu = solara.reactive(4)
|
| 33 |
+
cpu_cost_per_hour = solara.reactive(0.031611)
|
| 34 |
|
| 35 |
use_model_to_estimate_metrics = solara.reactive(False)
|
| 36 |
|
|
|
|
| 46 |
def InferencePlots(render_count):
|
| 47 |
|
| 48 |
unavailable_states_in_data, set_unavailable_states_in_data = solara.use_state_or_update(0)
|
| 49 |
+
total_cost, set_total_cost = solara.use_state_or_update(0)
|
| 50 |
|
| 51 |
def execute():
|
| 52 |
#print(selected_policy_label, selected_reward_label, selected_load_label)
|
|
|
|
| 75 |
replica = initial_replica.value
|
| 76 |
cpu = initial_cpu.value
|
| 77 |
state_not_found_in_data = 0
|
| 78 |
+
cum_cost = 0.0
|
| 79 |
for load, eod in load_profile:
|
| 80 |
if step > nsteps.value:
|
| 81 |
break
|
|
|
|
| 84 |
input_ranges['expected_tps'] = [load]
|
| 85 |
|
| 86 |
cur_state = {"replica": replica, "cpu": cpu, "expected_tps": load}
|
| 87 |
+
cum_cost += cpu_cost_per_hour.value * 24 * replica * cpu / 10
|
| 88 |
+
set_total_cost(cum_cost)
|
| 89 |
if use_model_to_estimate_metrics.value:
|
| 90 |
cur_metrics = estimate_metrics(model, ds, cur_state)
|
| 91 |
#print(cur_metrics)
|
|
|
|
| 124 |
set_unavailable_states_in_data(state_not_found_in_data)
|
| 125 |
|
| 126 |
|
| 127 |
+
with solara.GridFixed(columns=3):
|
| 128 |
solara.InputInt(label='Number of steps', value=nsteps.value, on_value=nsteps.set)
|
| 129 |
solara.InputInt(label="Initial replica", value=initial_replica)
|
| 130 |
solara.InputInt(label="Initial CPU", value=initial_cpu)
|
| 131 |
+
solara.InputFloat(label="CPU cost per hour ($)", value=cpu_cost_per_hour)
|
| 132 |
if set(training_state.value['input_cols'].value) == set(['replica','cpu','expected_tps']):
|
| 133 |
solara.Checkbox(label='Use twin model to estimate metrics', value=use_model_to_estimate_metrics)
|
| 134 |
else:
|
|
|
|
| 145 |
solara.Warning(f'There are {unavailable_states_in_data} unavailable states in data. Estimatated versions are used!')
|
| 146 |
|
| 147 |
#print('Interence plots')
|
| 148 |
+
if len(local_state.value['inference_plot_data'].value.items()) > 0:
|
| 149 |
+
solara.Text(f'Total cost is ${total_cost:.4f}')
|
| 150 |
with solara.ColumnsResponsive():
|
| 151 |
for col, content in local_state.value['inference_plot_data'].value.items():
|
| 152 |
options = {
|