Fix double-click (trigger_mode + button-disable); show all 3 baselines (eager/compile/max-autotune)
Browse files
app.py
CHANGED
|
@@ -226,7 +226,6 @@ def _preload_cuda_libs():
|
|
| 226 |
_CUDA_PRELOADED = True
|
| 227 |
import ctypes
|
| 228 |
import glob
|
| 229 |
-
diag = bool(os.environ.get("LOCAL_CUDA_DIAG"))
|
| 230 |
roots = []
|
| 231 |
try:
|
| 232 |
import torch
|
|
@@ -254,43 +253,14 @@ def _preload_cuda_libs():
|
|
| 254 |
for hit in hits:
|
| 255 |
try:
|
| 256 |
ctypes.CDLL(hit, mode=ctypes.RTLD_GLOBAL)
|
| 257 |
-
if diag:
|
| 258 |
-
print(f"[diag] preloaded {hit}", flush=True)
|
| 259 |
loaded = True
|
| 260 |
break
|
| 261 |
except Exception:
|
| 262 |
continue
|
| 263 |
-
if not loaded and diag:
|
| 264 |
-
print(f"[diag] could NOT preload {pat} from {roots}", flush=True)
|
| 265 |
|
| 266 |
|
| 267 |
-
#
|
| 268 |
-
#
|
| 269 |
-
# ZeroGPU quota. It also warms the import so the in-@spaces.GPU call is instant.
|
| 270 |
-
if os.environ.get("LOCAL_LLAMA_GPU_LAYERS", "-1") != "0" and os.environ.get("LOCAL_CUDA_DIAG"):
|
| 271 |
-
try:
|
| 272 |
-
import glob as _g, site as _site
|
| 273 |
-
try:
|
| 274 |
-
import torch as _t
|
| 275 |
-
print(f"[diag] torch {_t.__version__} cuda={_t.version.cuda}", flush=True)
|
| 276 |
-
except Exception as _e:
|
| 277 |
-
print(f"[diag] torch import failed: {_e}", flush=True)
|
| 278 |
-
print(f"[diag] LD_LIBRARY_PATH={os.environ.get('LD_LIBRARY_PATH','')}", flush=True)
|
| 279 |
-
roots = ["/usr/local/lib/python3.10/site-packages", "/usr/lib", "/usr/local/cuda"]
|
| 280 |
-
try:
|
| 281 |
-
roots += list(_site.getsitepackages())
|
| 282 |
-
except Exception:
|
| 283 |
-
pass
|
| 284 |
-
found = set()
|
| 285 |
-
for r in roots:
|
| 286 |
-
for hit in _g.glob(os.path.join(r, "**", "libcudart.so*"), recursive=True)[:8]:
|
| 287 |
-
found.add(hit)
|
| 288 |
-
print(f"[diag] libcudart hits: {sorted(found) or 'NONE FOUND'}", flush=True)
|
| 289 |
-
except Exception as _e:
|
| 290 |
-
print(f"[diag] failed: {type(_e).__name__}: {_e}", flush=True)
|
| 291 |
-
|
| 292 |
-
# Confirm the CUDA llama.cpp lib loads (no GPU device needed, so no ZeroGPU quota spent). Also
|
| 293 |
-
# warms the import so the in-@spaces.GPU call is instant.
|
| 294 |
if os.environ.get("LOCAL_LLAMA_GPU_LAYERS", "-1") != "0":
|
| 295 |
try:
|
| 296 |
_preload_cuda_libs()
|
|
@@ -353,7 +323,10 @@ def _local_gpu_mint(op: str, k: int, temp: float, spark: str) -> dict:
|
|
| 353 |
# compiles + runs Triton, all here. Off ZeroGPU the decorator is a no-op and the GPU is always
|
| 354 |
# present, so the same code path works on a dedicated GPU and locally too.
|
| 355 |
_ensure_referee_path()
|
| 356 |
-
|
|
|
|
|
|
|
|
|
|
| 357 |
|
| 358 |
messages = _local_prompt_messages(op, spark)
|
| 359 |
srcs = []
|
|
@@ -370,12 +343,13 @@ def _local_gpu_mint(op: str, k: int, temp: float, spark: str) -> dict:
|
|
| 370 |
n_iters = int(os.environ.get("LOCAL_REFEREE_ITERS", "30"))
|
| 371 |
for i, src in enumerate(srcs):
|
| 372 |
try:
|
| 373 |
-
res =
|
| 374 |
except Exception:
|
| 375 |
statuses.append("runtime_fail")
|
| 376 |
continue
|
| 377 |
statuses.append(res.status)
|
| 378 |
-
|
|
|
|
| 379 |
best = {"source": src, "result": res.to_dict()}
|
| 380 |
return {"n_srcs": len(srcs), "statuses": statuses, "best": best}
|
| 381 |
|
|
@@ -385,9 +359,16 @@ def _local_explain(label: str, res) -> str:
|
|
| 385 |
status = "no verified attempt" if res is None else res.get("status", "failed")
|
| 386 |
return (f"The local referee rejected these kernels ({status}). It still compiled and "
|
| 387 |
"checked them inside this Space; try minting again or simplify the operation.")
|
| 388 |
-
|
| 389 |
-
|
| 390 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 391 |
|
| 392 |
|
| 393 |
def local_mint(recipe: dict) -> dict:
|
|
@@ -425,10 +406,15 @@ def local_mint(recipe: dict) -> dict:
|
|
| 425 |
"statuses": statuses, "gen_seconds": total_s, "verify_seconds": 0.0,
|
| 426 |
"speedup_compile": None, "explanation": _local_explain(label, None), "k": k}
|
| 427 |
res = best["result"]
|
| 428 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 429 |
"speedup_eager": round(float(res.get("speedup_eager", 0)), 2),
|
| 430 |
-
"speedup_compile":
|
| 431 |
"latency_ms": res.get("latency_ms"), "eager_ms": res.get("eager_ms"),
|
|
|
|
| 432 |
"source": best["source"], "statuses": statuses, "gen_seconds": total_s,
|
| 433 |
"verify_seconds": 0.0, "explanation": _local_explain(label, res),
|
| 434 |
"n_verified": sum(1 for s in statuses if s == "ok"), "k": k}
|
|
@@ -567,7 +553,7 @@ APP_HTML = r"""
|
|
| 567 |
</div>
|
| 568 |
<label class="km-toggle"><input type="checkbox" id="km-pro"><span class="km-switch"></span>Use the 27B model (slower, knows more)</label>
|
| 569 |
<label class="km-toggle km-local-toggle"><input type="checkbox" id="km-local"><span class="km-switch"></span>Local (offline)</label>
|
| 570 |
-
<p class="km-mode-help">Runs entirely in this Space
|
| 571 |
</div>
|
| 572 |
|
| 573 |
<div class="km-actions">
|
|
@@ -1052,6 +1038,14 @@ APP_JS = r"""
|
|
| 1052 |
const btn=document.querySelector('#km_lb_btn button')||document.querySelector('#km_lb_btn');
|
| 1053 |
if(btn)btn.click();
|
| 1054 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1055 |
|
| 1056 |
function replayName(key){return (REPLAY_META[key]&&REPLAY_META[key].label)||(REPLAYS[key]&&cleanText(REPLAYS[key].op))||key;}
|
| 1057 |
function matchingReplayKey(){
|
|
@@ -1121,6 +1115,7 @@ APP_JS = r"""
|
|
| 1121 |
const mode=opts.mode||lastMintedMode||'build';
|
| 1122 |
stopBuild();
|
| 1123 |
stopReplay();
|
|
|
|
| 1124 |
const t=target(mode), v=t.verdict;
|
| 1125 |
if(!v)return;
|
| 1126 |
clearSource(mode);
|
|
@@ -1144,8 +1139,12 @@ APP_JS = r"""
|
|
| 1144 |
return;
|
| 1145 |
}
|
| 1146 |
const recorded=!!opts.recorded, local=!!d.local;
|
| 1147 |
-
|
| 1148 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1149 |
const runLabel=local?'local offline mint':(recorded?'recorded mint':'live mint');
|
| 1150 |
const noteText=recorded?'recorded backend run':(local?'local offline run':'live backend run');
|
| 1151 |
const note="<span class='km-pill-note "+(recorded?'recorded':(local?'local':'hit'))+"'>"+noteText+"</span>";
|
|
@@ -1155,8 +1154,10 @@ APP_JS = r"""
|
|
| 1155 |
"<div class='km-speed-hero'><big>"+sp3(heroSpeed)+"x</big><span>"+heroLabel+"</span></div>"+
|
| 1156 |
"<div class='km-ref-summary'><b>"+a.passed+" of "+(a.total||'?')+"</b> attempts passed the referee</div>"+
|
| 1157 |
attemptChips(d)+
|
| 1158 |
-
"<div class='km-stats'><div><big>"+sp(
|
| 1159 |
-
"<div><big>"+
|
|
|
|
|
|
|
| 1160 |
"<p class='km-dim'>"+esc(d.explanation||'')+"</p></div>";
|
| 1161 |
animate(v.firstElementChild,[{transform:'scale(0.96)',opacity:0},{transform:'scale(1)',opacity:1}],{duration:300,easing:'cubic-bezier(0.16,1,0.3,1)'});
|
| 1162 |
setSource(d,recorded?'recorded':'live',mode);
|
|
@@ -1217,13 +1218,13 @@ APP_JS = r"""
|
|
| 1217 |
clearSource(mode);
|
| 1218 |
const k=recipe.k||4, started=Date.now(), replayKey=mode==='build'?(matchingReplayKey()||REPLAY_ORDER[0]||''):(REPLAY_ORDER[0]||'');
|
| 1219 |
const local=!!recipe.local;
|
| 1220 |
-
const stages=local?['loading local GGUF...','llama.cpp drafting '+Math.min(k,2)+' kernels...','compiling Triton on this Space GPU...','checking correctness vs PyTorch...','timing vs
|
| 1221 |
['model waking...','drafting '+k+' kernels...','compiling Triton...','checking correctness vs PyTorch...','timing vs torch.compile...'];
|
| 1222 |
const stepHtml=stages.map((s,i)=>"<span class='"+(i===0?'on':'')+"'>"+esc(s)+"</span>").join('');
|
| 1223 |
v.innerHTML="<div class='km-card building'><b class='km-bstage' id='km-bstage'>"+esc(stages[0])+"</b>"+
|
| 1224 |
"<div class='km-build-steps' id='km-build-steps'>"+stepHtml+"</div>"+
|
| 1225 |
"<div class='km-bar'><i id='km-barfill'></i></div>"+
|
| 1226 |
-
"<span class='km-dim'>"+(local?"Local mode drafts
|
| 1227 |
(replayKey?"<button class='km-inline-replay' data-replay-key='"+esc(replayKey)+"'>Watch a recorded mint while this runs</button>":"")+"</div>";
|
| 1228 |
// Honest progress: do_mint is one blocking call with no progress signal, so we cannot show a
|
| 1229 |
// live readout. Instead we walk the referee's real phases ONCE on a rough estimate, monotonically
|
|
@@ -1235,7 +1236,7 @@ APP_JS = r"""
|
|
| 1235 |
const elapsed=(Date.now()-started)/1000;
|
| 1236 |
let ix=0; for(let j=0;j<stageStart.length;j++){if(elapsed>=stageStart[j])ix=j;}
|
| 1237 |
ix=Math.min(ix,stages.length-1);
|
| 1238 |
-
const label=(ix===stages.length-1&&elapsed>45)?
|
| 1239 |
const el=$('#km-bstage');
|
| 1240 |
if(el&&el.textContent!==label){el.textContent=label;animate(el,[{opacity:.35,transform:'translateY(3px)'},{opacity:1,transform:'none'}],{duration:220,easing:'cubic-bezier(0.16,1,0.3,1)'});}
|
| 1241 |
$$('#km-build-steps span').forEach((s,j)=>{s.classList.toggle('on',j===ix);s.classList.toggle('done',j<ix);});
|
|
@@ -1408,6 +1409,7 @@ APP_JS = r"""
|
|
| 1408 |
const r=buildRecipe();
|
| 1409 |
animate(buildBtn,[{transform:'scale(0.97)'},{transform:'scale(1)'}],{duration:140,easing:'cubic-bezier(0.16,1,0.3,1)'});
|
| 1410 |
play();
|
|
|
|
| 1411 |
startBuild('build',r);
|
| 1412 |
bridge(r);
|
| 1413 |
});
|
|
@@ -1418,6 +1420,7 @@ APP_JS = r"""
|
|
| 1418 |
if(!r)return;
|
| 1419 |
lastMintedMode='expert';
|
| 1420 |
animate(xBuild,[{transform:'scale(0.97)'},{transform:'scale(1)'}],{duration:140,easing:'cubic-bezier(0.16,1,0.3,1)'});
|
|
|
|
| 1421 |
startBuild('expert',r);
|
| 1422 |
bridge(r);
|
| 1423 |
});
|
|
@@ -1452,7 +1455,11 @@ with gr.Blocks(title="Kernel Mint", head=f"<style>{CSS}</style>") as demo:
|
|
| 1452 |
lb_out = gr.HTML(elem_id="km_lb")
|
| 1453 |
go = gr.Button("go", elem_id="km_go")
|
| 1454 |
lb_btn = gr.Button("lb", elem_id="km_lb_btn")
|
| 1455 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1456 |
# Leaderboard refresh is its OWN trigger, decoupled from minting. Previously fetch_lb was wired
|
| 1457 |
# to recipe_in.change, so every mint (which sets recipe_in) also fired a leaderboard fetch; on a
|
| 1458 |
# slow backend that fetch sat ahead of do_mint in Gradio's queue and the mint appeared to do
|
|
|
|
| 226 |
_CUDA_PRELOADED = True
|
| 227 |
import ctypes
|
| 228 |
import glob
|
|
|
|
| 229 |
roots = []
|
| 230 |
try:
|
| 231 |
import torch
|
|
|
|
| 253 |
for hit in hits:
|
| 254 |
try:
|
| 255 |
ctypes.CDLL(hit, mode=ctypes.RTLD_GLOBAL)
|
|
|
|
|
|
|
| 256 |
loaded = True
|
| 257 |
break
|
| 258 |
except Exception:
|
| 259 |
continue
|
|
|
|
|
|
|
| 260 |
|
| 261 |
|
| 262 |
+
# Confirm the CUDA llama.cpp lib loads at startup (loading the .so needs no GPU device, so it spends
|
| 263 |
+
# no ZeroGPU quota). It also warms the import so the in-@spaces.GPU call is instant.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
if os.environ.get("LOCAL_LLAMA_GPU_LAYERS", "-1") != "0":
|
| 265 |
try:
|
| 266 |
_preload_cuda_libs()
|
|
|
|
| 323 |
# compiles + runs Triton, all here. Off ZeroGPU the decorator is a no-op and the GPU is always
|
| 324 |
# present, so the same code path works on a dedicated GPU and locally too.
|
| 325 |
_ensure_referee_path()
|
| 326 |
+
# Time every verified kernel against eager AND torch.compile (default + max-autotune), so local
|
| 327 |
+
# mode shows the honest baselines, not just the inflated vs-eager fusion win. The max-autotune
|
| 328 |
+
# compile is a few seconds for these ops (inductor-cached across the k attempts), so it fits.
|
| 329 |
+
from harness import evaluate_inprocess_full
|
| 330 |
|
| 331 |
messages = _local_prompt_messages(op, spark)
|
| 332 |
srcs = []
|
|
|
|
| 343 |
n_iters = int(os.environ.get("LOCAL_REFEREE_ITERS", "30"))
|
| 344 |
for i, src in enumerate(srcs):
|
| 345 |
try:
|
| 346 |
+
res = evaluate_inprocess_full(src, op, n_shapes=n_shapes, n_iters=n_iters, seed=i)
|
| 347 |
except Exception:
|
| 348 |
statuses.append("runtime_fail")
|
| 349 |
continue
|
| 350 |
statuses.append(res.status)
|
| 351 |
+
# Keep the FASTEST verified kernel (lowest latency = best vs every baseline at once).
|
| 352 |
+
if res.status == "ok" and (best is None or res.latency_ms < best["result"]["latency_ms"]):
|
| 353 |
best = {"source": src, "result": res.to_dict()}
|
| 354 |
return {"n_srcs": len(srcs), "statuses": statuses, "best": best}
|
| 355 |
|
|
|
|
| 359 |
status = "no verified attempt" if res is None else res.get("status", "failed")
|
| 360 |
return (f"The local referee rejected these kernels ({status}). It still compiled and "
|
| 361 |
"checked them inside this Space; try minting again or simplify the operation.")
|
| 362 |
+
se = float(res.get("speedup_eager", 0) or 0)
|
| 363 |
+
honest = res.get("speedup_maxauto") or res.get("speedup_compile")
|
| 364 |
+
bl = "torch.compile max-autotune" if res.get("speedup_maxauto") else "torch.compile"
|
| 365 |
+
if honest:
|
| 366 |
+
return (f"Verified correct. {float(honest):.2f}x faster than {bl} (the honest baseline that "
|
| 367 |
+
f"also fuses and autotunes), and {se:.0f}x vs unfused PyTorch eager. The whole loop "
|
| 368 |
+
"ran in this Space: the 1B wrote it via llama.cpp, the referee compiled, checked it "
|
| 369 |
+
"against PyTorch, and timed it.")
|
| 370 |
+
return (f"Verified correct, {se:.0f}x faster than unfused PyTorch eager. The 1B wrote it via "
|
| 371 |
+
"llama.cpp and the referee checked and timed it, all inside this Space.")
|
| 372 |
|
| 373 |
|
| 374 |
def local_mint(recipe: dict) -> dict:
|
|
|
|
| 406 |
"statuses": statuses, "gen_seconds": total_s, "verify_seconds": 0.0,
|
| 407 |
"speedup_compile": None, "explanation": _local_explain(label, None), "k": k}
|
| 408 |
res = best["result"]
|
| 409 |
+
|
| 410 |
+
def _su(key):
|
| 411 |
+
v = res.get(key)
|
| 412 |
+
return round(float(v), 2) if v else None
|
| 413 |
+
return {"op": label, "verified": True, "local": True, "baseline": "compile",
|
| 414 |
"speedup_eager": round(float(res.get("speedup_eager", 0)), 2),
|
| 415 |
+
"speedup_compile": _su("speedup_compile"), "speedup_maxauto": _su("speedup_maxauto"),
|
| 416 |
"latency_ms": res.get("latency_ms"), "eager_ms": res.get("eager_ms"),
|
| 417 |
+
"compile_ms": res.get("compile_ms"), "maxauto_ms": res.get("maxauto_ms"),
|
| 418 |
"source": best["source"], "statuses": statuses, "gen_seconds": total_s,
|
| 419 |
"verify_seconds": 0.0, "explanation": _local_explain(label, res),
|
| 420 |
"n_verified": sum(1 for s in statuses if s == "ok"), "k": k}
|
|
|
|
| 553 |
</div>
|
| 554 |
<label class="km-toggle"><input type="checkbox" id="km-pro"><span class="km-switch"></span>Use the 27B model (slower, knows more)</label>
|
| 555 |
<label class="km-toggle km-local-toggle"><input type="checkbox" id="km-local"><span class="km-switch"></span>Local (offline)</label>
|
| 556 |
+
<p class="km-mode-help">Runs entirely in this Space: a 1B GGUF model (llama.cpp) writes the kernel on this Space's GPU, then the in-process referee compiles it, checks correctness against PyTorch, and times it against PyTorch eager, torch.compile, and max-autotune. No Modal or cloud model calls. Pro uses the 27B.</p>
|
| 557 |
</div>
|
| 558 |
|
| 559 |
<div class="km-actions">
|
|
|
|
| 1038 |
const btn=document.querySelector('#km_lb_btn button')||document.querySelector('#km_lb_btn');
|
| 1039 |
if(btn)btn.click();
|
| 1040 |
}
|
| 1041 |
+
let mintSafetyTimer=null;
|
| 1042 |
+
function setMinting(on){
|
| 1043 |
+
['#km-build','#km-xbuild'].forEach(id=>{const b=$(id); if(b){b.disabled=on; b.classList.toggle('minting',on);}});
|
| 1044 |
+
if(mintSafetyTimer){clearTimeout(mintSafetyTimer); mintSafetyTimer=null;}
|
| 1045 |
+
// Bulletproof re-enable: showResult() clears this, but if a result never arrives (hung backend)
|
| 1046 |
+
// the button must not stay dead. 4 min is longer than any real mint.
|
| 1047 |
+
if(on) mintSafetyTimer=setTimeout(()=>setMinting(false), 240000);
|
| 1048 |
+
}
|
| 1049 |
|
| 1050 |
function replayName(key){return (REPLAY_META[key]&&REPLAY_META[key].label)||(REPLAYS[key]&&cleanText(REPLAYS[key].op))||key;}
|
| 1051 |
function matchingReplayKey(){
|
|
|
|
| 1115 |
const mode=opts.mode||lastMintedMode||'build';
|
| 1116 |
stopBuild();
|
| 1117 |
stopReplay();
|
| 1118 |
+
if(!opts.recorded) setMinting(false); // result arrived -> re-enable Mint (replays don't disable it)
|
| 1119 |
const t=target(mode), v=t.verdict;
|
| 1120 |
if(!v)return;
|
| 1121 |
clearSource(mode);
|
|
|
|
| 1139 |
return;
|
| 1140 |
}
|
| 1141 |
const recorded=!!opts.recorded, local=!!d.local;
|
| 1142 |
+
// Headline the HONEST baseline (the compiler), not the inflated vs-eager fusion number.
|
| 1143 |
+
// Strongest available wins: max-autotune > torch.compile default > eager.
|
| 1144 |
+
const se=+d.speedup_eager, sc=+d.speedup_compile, sm=+d.speedup_maxauto;
|
| 1145 |
+
const hasC=Number.isFinite(sc)&&sc>0, hasM=Number.isFinite(sm)&&sm>0;
|
| 1146 |
+
const heroSpeed=hasM?sm:(hasC?sc:se);
|
| 1147 |
+
const heroLabel=hasM?'vs torch.compile max-autotune':(hasC?'vs torch.compile':'vs PyTorch eager');
|
| 1148 |
const runLabel=local?'local offline mint':(recorded?'recorded mint':'live mint');
|
| 1149 |
const noteText=recorded?'recorded backend run':(local?'local offline run':'live backend run');
|
| 1150 |
const note="<span class='km-pill-note "+(recorded?'recorded':(local?'local':'hit'))+"'>"+noteText+"</span>";
|
|
|
|
| 1154 |
"<div class='km-speed-hero'><big>"+sp3(heroSpeed)+"x</big><span>"+heroLabel+"</span></div>"+
|
| 1155 |
"<div class='km-ref-summary'><b>"+a.passed+" of "+(a.total||'?')+"</b> attempts passed the referee</div>"+
|
| 1156 |
attemptChips(d)+
|
| 1157 |
+
"<div class='km-stats'><div><big>"+sp(se)+"x</big><span>vs PyTorch eager</span></div>"+
|
| 1158 |
+
(hasC?"<div><big>"+sp(sc)+"x</big><span>vs torch.compile</span></div>":"")+
|
| 1159 |
+
(hasM?"<div><big>"+sp(sm)+"x</big><span>vs max-autotune</span></div>":"")+
|
| 1160 |
+
"<div><big>"+(Number.isFinite(+d.gen_seconds)?sp(d.gen_seconds)+'s':'?')+"</big><span>generation</span></div></div>"+
|
| 1161 |
"<p class='km-dim'>"+esc(d.explanation||'')+"</p></div>";
|
| 1162 |
animate(v.firstElementChild,[{transform:'scale(0.96)',opacity:0},{transform:'scale(1)',opacity:1}],{duration:300,easing:'cubic-bezier(0.16,1,0.3,1)'});
|
| 1163 |
setSource(d,recorded?'recorded':'live',mode);
|
|
|
|
| 1218 |
clearSource(mode);
|
| 1219 |
const k=recipe.k||4, started=Date.now(), replayKey=mode==='build'?(matchingReplayKey()||REPLAY_ORDER[0]||''):(REPLAY_ORDER[0]||'');
|
| 1220 |
const local=!!recipe.local;
|
| 1221 |
+
const stages=local?['loading local GGUF...','llama.cpp drafting '+Math.min(k,2)+' kernels...','compiling Triton on this Space GPU...','checking correctness vs PyTorch...','timing vs torch.compile...']:
|
| 1222 |
['model waking...','drafting '+k+' kernels...','compiling Triton...','checking correctness vs PyTorch...','timing vs torch.compile...'];
|
| 1223 |
const stepHtml=stages.map((s,i)=>"<span class='"+(i===0?'on':'')+"'>"+esc(s)+"</span>").join('');
|
| 1224 |
v.innerHTML="<div class='km-card building'><b class='km-bstage' id='km-bstage'>"+esc(stages[0])+"</b>"+
|
| 1225 |
"<div class='km-build-steps' id='km-build-steps'>"+stepHtml+"</div>"+
|
| 1226 |
"<div class='km-bar'><i id='km-barfill'></i></div>"+
|
| 1227 |
+
"<span class='km-dim'>"+(local?"Local mode drafts up to two kernels with llama.cpp on this Space's GPU, then verifies them with the in-process referee and times them against PyTorch eager, torch.compile, and max-autotune. First run may also download/cache the GGUF.":"The model drafts up to "+k+" kernels. The referee compiles, correctness-checks, and times every candidate. First build of a session can take about 90 seconds while the model wakes.")+"</span>"+
|
| 1228 |
(replayKey?"<button class='km-inline-replay' data-replay-key='"+esc(replayKey)+"'>Watch a recorded mint while this runs</button>":"")+"</div>";
|
| 1229 |
// Honest progress: do_mint is one blocking call with no progress signal, so we cannot show a
|
| 1230 |
// live readout. Instead we walk the referee's real phases ONCE on a rough estimate, monotonically
|
|
|
|
| 1236 |
const elapsed=(Date.now()-started)/1000;
|
| 1237 |
let ix=0; for(let j=0;j<stageStart.length;j++){if(elapsed>=stageStart[j])ix=j;}
|
| 1238 |
ix=Math.min(ix,stages.length-1);
|
| 1239 |
+
const label=(ix===stages.length-1&&elapsed>45)?'still timing vs torch.compile...':stages[ix];
|
| 1240 |
const el=$('#km-bstage');
|
| 1241 |
if(el&&el.textContent!==label){el.textContent=label;animate(el,[{opacity:.35,transform:'translateY(3px)'},{opacity:1,transform:'none'}],{duration:220,easing:'cubic-bezier(0.16,1,0.3,1)'});}
|
| 1242 |
$$('#km-build-steps span').forEach((s,j)=>{s.classList.toggle('on',j===ix);s.classList.toggle('done',j<ix);});
|
|
|
|
| 1409 |
const r=buildRecipe();
|
| 1410 |
animate(buildBtn,[{transform:'scale(0.97)'},{transform:'scale(1)'}],{duration:140,easing:'cubic-bezier(0.16,1,0.3,1)'});
|
| 1411 |
play();
|
| 1412 |
+
setMinting(true);
|
| 1413 |
startBuild('build',r);
|
| 1414 |
bridge(r);
|
| 1415 |
});
|
|
|
|
| 1420 |
if(!r)return;
|
| 1421 |
lastMintedMode='expert';
|
| 1422 |
animate(xBuild,[{transform:'scale(0.97)'},{transform:'scale(1)'}],{duration:140,easing:'cubic-bezier(0.16,1,0.3,1)'});
|
| 1423 |
+
setMinting(true);
|
| 1424 |
startBuild('expert',r);
|
| 1425 |
bridge(r);
|
| 1426 |
});
|
|
|
|
| 1455 |
lb_out = gr.HTML(elem_id="km_lb")
|
| 1456 |
go = gr.Button("go", elem_id="km_go")
|
| 1457 |
lb_btn = gr.Button("lb", elem_id="km_lb_btn")
|
| 1458 |
+
# trigger_mode="multiple": the default ("once") silently DROPS a click that lands while a
|
| 1459 |
+
# previous mint is still running, so minting one kernel after another needed two clicks and the
|
| 1460 |
+
# old result lingered. The frontend also disables the Mint button during a mint (one at a time,
|
| 1461 |
+
# no wasted ZeroGPU calls); this is the belt-and-suspenders so no click is ever swallowed.
|
| 1462 |
+
go.click(do_mint, recipe_in, result_out, trigger_mode="multiple")
|
| 1463 |
# Leaderboard refresh is its OWN trigger, decoupled from minting. Previously fetch_lb was wired
|
| 1464 |
# to recipe_in.change, so every mint (which sets recipe_in) also fired a leaderboard fetch; on a
|
| 1465 |
# slow backend that fetch sat ahead of do_mint in Gradio's queue and the mint appeared to do
|