Udayshankar Ravikumar commited on
UI
Browse files
app.py
CHANGED
|
@@ -70,15 +70,15 @@ def load_model(workload: str, target: str):
|
|
| 70 |
raise RuntimeError(f"Model not preloaded: {workload}, {target}")
|
| 71 |
|
| 72 |
def physical_sanity_check(ipc, miss_rate):
|
| 73 |
-
|
| 74 |
if ipc < 0 or ipc > 3.5:
|
| 75 |
-
|
| 76 |
if miss_rate < 0 or miss_rate > 1:
|
| 77 |
-
|
| 78 |
-
return
|
| 79 |
|
| 80 |
# -------------------------------------------------
|
| 81 |
-
# Preload
|
| 82 |
# -------------------------------------------------
|
| 83 |
def preload_models():
|
| 84 |
ensure_models()
|
|
@@ -87,16 +87,16 @@ def preload_models():
|
|
| 87 |
|
| 88 |
for workload in workloads:
|
| 89 |
for target in TARGETS:
|
| 90 |
-
|
| 91 |
MODEL_DIR, f"model_{workload}_{target}.pkl"
|
| 92 |
)
|
| 93 |
-
payload = joblib.load(
|
| 94 |
MODEL_CACHE[(workload, target)] = (
|
| 95 |
payload["model"],
|
| 96 |
payload["log_target"],
|
| 97 |
)
|
| 98 |
|
| 99 |
-
return "
|
| 100 |
|
| 101 |
# -------------------------------------------------
|
| 102 |
# Inference Core
|
|
@@ -106,7 +106,6 @@ def run_inference(df: pd.DataFrame) -> pd.DataFrame:
|
|
| 106 |
if missing:
|
| 107 |
raise ValueError(f"Missing required columns: {missing}")
|
| 108 |
|
| 109 |
-
# Feature engineering
|
| 110 |
for col in [
|
| 111 |
"l1d_size",
|
| 112 |
"l1i_size",
|
|
@@ -173,44 +172,49 @@ def infer_from_csv(file):
|
|
| 173 |
# UI
|
| 174 |
# -------------------------------------------------
|
| 175 |
with gr.Blocks(title="AIDE Chip Surrogate Inference") as demo:
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
"""
|
| 181 |
-
# AIDE Chip Surrogate Inference
|
| 182 |
-
|
| 183 |
-
Upload a CSV describing cache configurations and workloads.
|
| 184 |
-
The app will run surrogate models to predict:
|
| 185 |
-
- IPC
|
| 186 |
-
- L2 Miss Rate
|
| 187 |
-
"""
|
| 188 |
)
|
| 189 |
|
| 190 |
-
|
| 191 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
|
|
|
|
|
|
| 196 |
|
|
|
|
| 197 |
demo.load(
|
| 198 |
preload_models,
|
| 199 |
inputs=None,
|
| 200 |
-
outputs=
|
| 201 |
).then(
|
| 202 |
lambda: (
|
| 203 |
gr.update(visible=False),
|
| 204 |
gr.update(visible=True),
|
| 205 |
-
gr.update(interactive=True),
|
| 206 |
),
|
| 207 |
-
outputs=[loading_md,
|
| 208 |
-
)
|
| 209 |
-
|
| 210 |
-
run_btn.click(
|
| 211 |
-
infer_from_csv,
|
| 212 |
-
inputs=csv_input,
|
| 213 |
-
outputs=[preview, output_csv, warnings_box],
|
| 214 |
)
|
| 215 |
|
| 216 |
if __name__ == "__main__":
|
|
|
|
| 70 |
raise RuntimeError(f"Model not preloaded: {workload}, {target}")
|
| 71 |
|
| 72 |
def physical_sanity_check(ipc, miss_rate):
|
| 73 |
+
out = []
|
| 74 |
if ipc < 0 or ipc > 3.5:
|
| 75 |
+
out.append(f"IPC={ipc:.3f} out of physical range")
|
| 76 |
if miss_rate < 0 or miss_rate > 1:
|
| 77 |
+
out.append(f"L2 miss rate={miss_rate:.3f} out of [0,1]")
|
| 78 |
+
return out
|
| 79 |
|
| 80 |
# -------------------------------------------------
|
| 81 |
+
# Preload models (runs once at app start)
|
| 82 |
# -------------------------------------------------
|
| 83 |
def preload_models():
|
| 84 |
ensure_models()
|
|
|
|
| 87 |
|
| 88 |
for workload in workloads:
|
| 89 |
for target in TARGETS:
|
| 90 |
+
path = os.path.join(
|
| 91 |
MODEL_DIR, f"model_{workload}_{target}.pkl"
|
| 92 |
)
|
| 93 |
+
payload = joblib.load(path)
|
| 94 |
MODEL_CACHE[(workload, target)] = (
|
| 95 |
payload["model"],
|
| 96 |
payload["log_target"],
|
| 97 |
)
|
| 98 |
|
| 99 |
+
return "ready"
|
| 100 |
|
| 101 |
# -------------------------------------------------
|
| 102 |
# Inference Core
|
|
|
|
| 106 |
if missing:
|
| 107 |
raise ValueError(f"Missing required columns: {missing}")
|
| 108 |
|
|
|
|
| 109 |
for col in [
|
| 110 |
"l1d_size",
|
| 111 |
"l1i_size",
|
|
|
|
| 172 |
# UI
|
| 173 |
# -------------------------------------------------
|
| 174 |
with gr.Blocks(title="AIDE Chip Surrogate Inference") as demo:
|
| 175 |
+
# Loading screen ONLY
|
| 176 |
+
loading_md = gr.Markdown(
|
| 177 |
+
"## Downloading surrogate models…\n\nThis may take a while.",
|
| 178 |
+
visible=True,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
)
|
| 180 |
|
| 181 |
+
# Main app (hidden initially)
|
| 182 |
+
with gr.Column(visible=False) as app_ui:
|
| 183 |
+
gr.Markdown(
|
| 184 |
+
"""
|
| 185 |
+
# AIDE Chip Surrogate Inference
|
| 186 |
+
|
| 187 |
+
Upload a CSV describing cache configurations and workloads.
|
| 188 |
+
The app will run surrogate models to predict:
|
| 189 |
+
- IPC
|
| 190 |
+
- L2 Miss Rate
|
| 191 |
+
"""
|
| 192 |
+
)
|
| 193 |
+
|
| 194 |
+
csv_input = gr.File(label="Input CSV", file_types=[".csv"])
|
| 195 |
+
run_btn = gr.Button("Run Inference")
|
| 196 |
+
|
| 197 |
+
preview = gr.Dataframe(label="Preview (first 20 rows)")
|
| 198 |
+
output_csv = gr.File(label="Download Full Output CSV")
|
| 199 |
+
warnings_box = gr.Textbox(label="Sanity Check Summary")
|
| 200 |
|
| 201 |
+
run_btn.click(
|
| 202 |
+
infer_from_csv,
|
| 203 |
+
inputs=csv_input,
|
| 204 |
+
outputs=[preview, output_csv, warnings_box],
|
| 205 |
+
)
|
| 206 |
|
| 207 |
+
# Startup load hook
|
| 208 |
demo.load(
|
| 209 |
preload_models,
|
| 210 |
inputs=None,
|
| 211 |
+
outputs=None,
|
| 212 |
).then(
|
| 213 |
lambda: (
|
| 214 |
gr.update(visible=False),
|
| 215 |
gr.update(visible=True),
|
|
|
|
| 216 |
),
|
| 217 |
+
outputs=[loading_md, app_ui],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
)
|
| 219 |
|
| 220 |
if __name__ == "__main__":
|