Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import matplotlib.pyplot as plt
|
| 3 |
import numpy as np
|
| 4 |
import json
|
| 5 |
import warnings
|
|
|
|
| 6 |
|
| 7 |
# Silence irrelevant HF warnings
|
| 8 |
warnings.filterwarnings(
|
|
@@ -12,38 +12,50 @@ warnings.filterwarnings(
|
|
| 12 |
)
|
| 13 |
|
| 14 |
# ----------------------------
|
| 15 |
-
# Core callback (SAFE
|
| 16 |
# ----------------------------
|
| 17 |
def run_curvopt(model_name, hardware, acc_budget):
|
| 18 |
try:
|
| 19 |
# ----------------------------
|
| 20 |
-
# ENERGY PLOT
|
| 21 |
# ----------------------------
|
| 22 |
-
fig_energy = plt.figure()
|
| 23 |
x = np.arange(1, 6)
|
| 24 |
y = np.random.uniform(10, 50, size=5)
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
# ----------------------------
|
| 33 |
-
# PARETO PLOT
|
| 34 |
# ----------------------------
|
| 35 |
-
fig_pareto = plt.figure()
|
| 36 |
acc = np.array([0.82, 0.85, 0.88, 0.90])
|
| 37 |
energy = np.array([55, 48, 40, 34])
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
# ----------------------------
|
| 46 |
-
# POLICY JSON
|
| 47 |
# ----------------------------
|
| 48 |
policy = {
|
| 49 |
"model": model_name,
|
|
@@ -64,7 +76,7 @@ def run_curvopt(model_name, hardware, acc_budget):
|
|
| 64 |
import traceback
|
| 65 |
print(traceback.format_exc())
|
| 66 |
|
| 67 |
-
#
|
| 68 |
return None, None, f"ERROR:\n{str(e)}"
|
| 69 |
|
| 70 |
|
|
@@ -76,6 +88,8 @@ with gr.Blocks() as demo:
|
|
| 76 |
"""
|
| 77 |
# ⚡ CurvOpt
|
| 78 |
**Energy-Efficient Inference via Curvature & Information**
|
|
|
|
|
|
|
| 79 |
"""
|
| 80 |
)
|
| 81 |
|
|
@@ -89,7 +103,7 @@ with gr.Blocks() as demo:
|
|
| 89 |
hardware_radio = gr.Radio(
|
| 90 |
choices=["CPU", "GPU", "EDGE"],
|
| 91 |
value="CPU",
|
| 92 |
-
label="Hardware"
|
| 93 |
)
|
| 94 |
|
| 95 |
acc_slider = gr.Slider(
|
|
@@ -118,7 +132,7 @@ with gr.Blocks() as demo:
|
|
| 118 |
)
|
| 119 |
|
| 120 |
# ----------------------------
|
| 121 |
-
# Launch (HF-
|
| 122 |
# ----------------------------
|
| 123 |
demo.launch(
|
| 124 |
theme=gr.themes.Soft(),
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import numpy as np
|
| 3 |
import json
|
| 4 |
import warnings
|
| 5 |
+
import plotly.graph_objects as go
|
| 6 |
|
| 7 |
# Silence irrelevant HF warnings
|
| 8 |
warnings.filterwarnings(
|
|
|
|
| 12 |
)
|
| 13 |
|
| 14 |
# ----------------------------
|
| 15 |
+
# Core callback (SAFE + HF READY)
|
| 16 |
# ----------------------------
|
| 17 |
def run_curvopt(model_name, hardware, acc_budget):
|
| 18 |
try:
|
| 19 |
# ----------------------------
|
| 20 |
+
# ENERGY PLOT
|
| 21 |
# ----------------------------
|
|
|
|
| 22 |
x = np.arange(1, 6)
|
| 23 |
y = np.random.uniform(10, 50, size=5)
|
| 24 |
+
|
| 25 |
+
fig_energy = go.Figure(
|
| 26 |
+
data=go.Scatter(
|
| 27 |
+
x=x,
|
| 28 |
+
y=y,
|
| 29 |
+
mode="lines+markers"
|
| 30 |
+
)
|
| 31 |
+
)
|
| 32 |
+
fig_energy.update_layout(
|
| 33 |
+
title="Layerwise Energy Consumption",
|
| 34 |
+
xaxis_title="Layer Index",
|
| 35 |
+
yaxis_title="Energy (mJ)"
|
| 36 |
+
)
|
| 37 |
|
| 38 |
# ----------------------------
|
| 39 |
+
# PARETO PLOT
|
| 40 |
# ----------------------------
|
|
|
|
| 41 |
acc = np.array([0.82, 0.85, 0.88, 0.90])
|
| 42 |
energy = np.array([55, 48, 40, 34])
|
| 43 |
+
|
| 44 |
+
fig_pareto = go.Figure(
|
| 45 |
+
data=go.Scatter(
|
| 46 |
+
x=acc,
|
| 47 |
+
y=energy,
|
| 48 |
+
mode="lines+markers"
|
| 49 |
+
)
|
| 50 |
+
)
|
| 51 |
+
fig_pareto.update_layout(
|
| 52 |
+
title="Energy–Accuracy Pareto Frontier",
|
| 53 |
+
xaxis_title="Accuracy",
|
| 54 |
+
yaxis_title="Energy (mJ)"
|
| 55 |
+
)
|
| 56 |
|
| 57 |
# ----------------------------
|
| 58 |
+
# POLICY JSON
|
| 59 |
# ----------------------------
|
| 60 |
policy = {
|
| 61 |
"model": model_name,
|
|
|
|
| 76 |
import traceback
|
| 77 |
print(traceback.format_exc())
|
| 78 |
|
| 79 |
+
# Must return SAME NUMBER of outputs
|
| 80 |
return None, None, f"ERROR:\n{str(e)}"
|
| 81 |
|
| 82 |
|
|
|
|
| 88 |
"""
|
| 89 |
# ⚡ CurvOpt
|
| 90 |
**Energy-Efficient Inference via Curvature & Information**
|
| 91 |
+
|
| 92 |
+
A systems-oriented ML demo focusing on **lower energy and compute footprint**.
|
| 93 |
"""
|
| 94 |
)
|
| 95 |
|
|
|
|
| 103 |
hardware_radio = gr.Radio(
|
| 104 |
choices=["CPU", "GPU", "EDGE"],
|
| 105 |
value="CPU",
|
| 106 |
+
label="Target Hardware"
|
| 107 |
)
|
| 108 |
|
| 109 |
acc_slider = gr.Slider(
|
|
|
|
| 132 |
)
|
| 133 |
|
| 134 |
# ----------------------------
|
| 135 |
+
# Launch (HF-SAFE)
|
| 136 |
# ----------------------------
|
| 137 |
demo.launch(
|
| 138 |
theme=gr.themes.Soft(),
|