Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -93,21 +93,29 @@ def _apply_schedule(h_cycles: int, l_cycles: int) -> None:
|
|
| 93 |
LAST_SCHEDULE["h"], LAST_SCHEDULE["l"] = h_cycles, l_cycles
|
| 94 |
|
| 95 |
|
| 96 |
-
#
|
| 97 |
-
# 16 * H * (L
|
|
|
|
| 98 |
SCHEDULES = [
|
| 99 |
-
("
|
| 100 |
-
("
|
| 101 |
-
("
|
| 102 |
-
("
|
| 103 |
-
("
|
| 104 |
-
("
|
| 105 |
]
|
| 106 |
_SCHEDULE_LOOKUP = {name: (h, l) for name, h, l in SCHEDULES}
|
| 107 |
|
| 108 |
|
| 109 |
def _estimate_duration(*args, **kwargs) -> int:
|
| 110 |
-
"""Callable GPU duration
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
schedule = kwargs.get("schedule") or (args[2] if len(args) > 2 else None)
|
| 112 |
budget = kwargs.get("max_tokens") or (args[3] if len(args) > 3 else 32)
|
| 113 |
try:
|
|
@@ -115,14 +123,14 @@ def _estimate_duration(*args, **kwargs) -> int:
|
|
| 115 |
except Exception:
|
| 116 |
h, l = 2, 3
|
| 117 |
depth = 16 * h * (l + 1)
|
| 118 |
-
return min(
|
| 119 |
|
| 120 |
|
| 121 |
@spaces.GPU(duration=_estimate_duration)
|
| 122 |
def answer(
|
| 123 |
image: Image.Image,
|
| 124 |
prompt: str,
|
| 125 |
-
schedule: str = "H2L3
|
| 126 |
max_tokens: int = 32,
|
| 127 |
use_trigger: bool = False,
|
| 128 |
progress=gr.Progress(track_tqdm=True),
|
|
@@ -208,9 +216,11 @@ with gr.Blocks() as demo:
|
|
| 208 |
)
|
| 209 |
schedule_in = gr.Dropdown(
|
| 210 |
choices=[name for name, _, _ in SCHEDULES],
|
| 211 |
-
value="H2L3
|
| 212 |
label="Recurrent schedule (compute budget)",
|
| 213 |
-
info="Unrolled depth = 16 脳 H 脳 (L+1) effective layers per forward pass"
|
|
|
|
|
|
|
| 214 |
)
|
| 215 |
run_btn = gr.Button("Answer", variant="primary")
|
| 216 |
with gr.Accordion("Advanced", open=False):
|
|
|
|
| 93 |
LAST_SCHEDULE["h"], LAST_SCHEDULE["l"] = h_cycles, l_cycles
|
| 94 |
|
| 95 |
|
| 96 |
+
# Coherent schedules from the paper's Table 4 sweep: (label, H, L) -> unrolled
|
| 97 |
+
# depth 16 * H * (L+1). H2L3 is the trained schedule and clearly the best; the
|
| 98 |
+
# H1/H4 rows in the paper collapse (MMStar 0.5/24), so they are not offered.
|
| 99 |
SCHEDULES = [
|
| 100 |
+
("H2L3 路 128 layers (trained default, best)", 2, 3),
|
| 101 |
+
("H2L2 路 96 layers (lighter, still solid)", 2, 2),
|
| 102 |
+
("H3L3 路 192 layers (heavier, slightly lower)", 3, 3),
|
| 103 |
+
("H3L2 路 144 layers", 3, 2),
|
| 104 |
+
("H2L1 路 64 layers (noticeably degraded)", 2, 1),
|
| 105 |
+
("H3L1 路 96 layers (noticeably degraded)", 3, 1),
|
| 106 |
]
|
| 107 |
_SCHEDULE_LOOKUP = {name: (h, l) for name, h, l in SCHEDULES}
|
| 108 |
|
| 109 |
|
| 110 |
def _estimate_duration(*args, **kwargs) -> int:
|
| 111 |
+
"""Callable GPU duration, calibrated from measured calls on this Space.
|
| 112 |
+
|
| 113 |
+
Measured on ZeroGPU: ~0.081 s/token at 128 unrolled layers, roughly
|
| 114 |
+
proportional to depth; ~2.5 s fixed plus up to ~9 s one-time init on a
|
| 115 |
+
visitor's first call. The 20 s base covers init + prefill + margin.
|
| 116 |
+
|
| 117 |
+
Duration = 20 + budget x (0.12 s/token scaled by depth/128), capped.
|
| 118 |
+
"""
|
| 119 |
schedule = kwargs.get("schedule") or (args[2] if len(args) > 2 else None)
|
| 120 |
budget = kwargs.get("max_tokens") or (args[3] if len(args) > 3 else 32)
|
| 121 |
try:
|
|
|
|
| 123 |
except Exception:
|
| 124 |
h, l = 2, 3
|
| 125 |
depth = 16 * h * (l + 1)
|
| 126 |
+
return min(120, 20 + int(float(budget) * 0.12 * depth / 128))
|
| 127 |
|
| 128 |
|
| 129 |
@spaces.GPU(duration=_estimate_duration)
|
| 130 |
def answer(
|
| 131 |
image: Image.Image,
|
| 132 |
prompt: str,
|
| 133 |
+
schedule: str = "H2L3 路 128 layers (trained default, best)",
|
| 134 |
max_tokens: int = 32,
|
| 135 |
use_trigger: bool = False,
|
| 136 |
progress=gr.Progress(track_tqdm=True),
|
|
|
|
| 216 |
)
|
| 217 |
schedule_in = gr.Dropdown(
|
| 218 |
choices=[name for name, _, _ in SCHEDULES],
|
| 219 |
+
value="H2L3 路 128 layers (trained default, best)",
|
| 220 |
label="Recurrent schedule (compute budget)",
|
| 221 |
+
info="Unrolled depth = 16 脳 H 脳 (L+1) effective layers per forward pass. "
|
| 222 |
+
"H2L3 is the trained schedule; other coherent schedules from the "
|
| 223 |
+
"paper's Table 4 sweep are offered for comparison.",
|
| 224 |
)
|
| 225 |
run_btn = gr.Button("Answer", variant="primary")
|
| 226 |
with gr.Accordion("Advanced", open=False):
|