Spaces:
Running on Zero
Running on Zero
Add CPU model smoke diagnostics
Browse files
app.py
CHANGED
|
@@ -286,9 +286,68 @@ def _run_bench_locked(model_filter=None):
|
|
| 286 |
return results
|
| 287 |
|
| 288 |
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 292 |
|
| 293 |
MODEL_CACHE = {}
|
| 294 |
|
|
@@ -351,6 +410,14 @@ def _patched_create_app(blocks, **kwargs):
|
|
| 351 |
try: return JSONResponse(_search_web(q, backend=backend, max_results=max_results, extract_top=extract_top, region=region))
|
| 352 |
except Exception as e: return JSONResponse({"error": str(e)}, status_code=502)
|
| 353 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
@fa_app.get("/respite/benchmark")
|
| 355 |
def _b(force: bool=False, model: str=""):
|
| 356 |
try:
|
|
|
|
| 286 |
return results
|
| 287 |
|
| 288 |
|
| 289 |
+
def _run_cpu_smoke(model_filter):
|
| 290 |
+
"""Run a short CPU-only loader/inference diagnostic for one model."""
|
| 291 |
+
import subprocess
|
| 292 |
+
from huggingface_hub import hf_hub_download
|
| 293 |
+
|
| 294 |
+
model = next((m for m in _BENCH_MODELS if m["name"] == model_filter), None)
|
| 295 |
+
if model is None:
|
| 296 |
+
raise ValueError(f"Unknown model: {model_filter}")
|
| 297 |
+
cli = _ensure_llama()
|
| 298 |
+
env = os.environ.copy()
|
| 299 |
+
env["LD_LIBRARY_PATH"] = os.path.dirname(cli)
|
| 300 |
+
env["CUDA_VISIBLE_DEVICES"] = ""
|
| 301 |
+
env["GGML_CUDA"] = "0"
|
| 302 |
+
result = {
|
| 303 |
+
"name": model["name"],
|
| 304 |
+
"engine": "llama-cli",
|
| 305 |
+
"gpu_layers": 0,
|
| 306 |
+
"threads": _parse_cpu_count() or 8,
|
| 307 |
+
"phases": {},
|
| 308 |
+
}
|
| 309 |
+
|
| 310 |
+
t0 = time.time()
|
| 311 |
+
version = subprocess.run([cli, "--version"], capture_output=True, text=True, timeout=15, env=env)
|
| 312 |
+
result["phases"]["binary"] = {
|
| 313 |
+
"ok": version.returncode == 0,
|
| 314 |
+
"elapsed_sec": round(time.time() - t0, 2),
|
| 315 |
+
"returncode": version.returncode,
|
| 316 |
+
"output": (version.stdout + version.stderr)[-1000:],
|
| 317 |
+
}
|
| 318 |
+
if version.returncode != 0:
|
| 319 |
+
return result
|
| 320 |
+
|
| 321 |
+
t0 = time.time()
|
| 322 |
+
try:
|
| 323 |
+
path = hf_hub_download(repo_id=model["repo"], filename=model["file"], cache_dir=_BENCH_CACHE)
|
| 324 |
+
result["model_path"] = path
|
| 325 |
+
result["phases"]["download"] = {"ok": True, "elapsed_sec": round(time.time() - t0, 2)}
|
| 326 |
+
except Exception as exc:
|
| 327 |
+
result["phases"]["download"] = {"ok": False, "elapsed_sec": round(time.time() - t0, 2), "error": str(exc)}
|
| 328 |
+
return result
|
| 329 |
+
|
| 330 |
+
command = [cli, "-m", path, "-t", str(result["threads"]), "-ngl", "0", "-c", "256", "-n", "1", "-p", "Say hi.", "--no-display-prompt"]
|
| 331 |
+
t0 = time.time()
|
| 332 |
+
try:
|
| 333 |
+
run = subprocess.run(command, capture_output=True, text=True, timeout=45, env=env)
|
| 334 |
+
result["phases"]["load_and_one_token"] = {
|
| 335 |
+
"ok": run.returncode == 0,
|
| 336 |
+
"elapsed_sec": round(time.time() - t0, 2),
|
| 337 |
+
"returncode": run.returncode,
|
| 338 |
+
"stdout": (run.stdout or "")[-1000:],
|
| 339 |
+
"stderr": (run.stderr or "")[-3000:],
|
| 340 |
+
}
|
| 341 |
+
except subprocess.TimeoutExpired as exc:
|
| 342 |
+
result["phases"]["load_and_one_token"] = {
|
| 343 |
+
"ok": False,
|
| 344 |
+
"elapsed_sec": round(time.time() - t0, 2),
|
| 345 |
+
"timeout": True,
|
| 346 |
+
"stdout": str(exc.stdout or "")[-1000:],
|
| 347 |
+
"stderr": str(exc.stderr or "")[-3000:],
|
| 348 |
+
}
|
| 349 |
+
return result
|
| 350 |
+
|
| 351 |
|
| 352 |
MODEL_CACHE = {}
|
| 353 |
|
|
|
|
| 410 |
try: return JSONResponse(_search_web(q, backend=backend, max_results=max_results, extract_top=extract_top, region=region))
|
| 411 |
except Exception as e: return JSONResponse({"error": str(e)}, status_code=502)
|
| 412 |
|
| 413 |
+
@fa_app.get("/respite/benchmark/smoke")
|
| 414 |
+
def _smoke(model: str="Gemma 4 E4B"):
|
| 415 |
+
try:
|
| 416 |
+
with _BENCH_LOCK:
|
| 417 |
+
return JSONResponse(_run_cpu_smoke(model.strip()))
|
| 418 |
+
except Exception as e:
|
| 419 |
+
return JSONResponse({"error": str(e)}, status_code=500)
|
| 420 |
+
|
| 421 |
@fa_app.get("/respite/benchmark")
|
| 422 |
def _b(force: bool=False, model: str=""):
|
| 423 |
try:
|