Spaces:
Running on Zero
Running on Zero
Fix: clear benchmark cache, add binary verification and debug logging
Browse files
app.py
CHANGED
|
@@ -438,23 +438,34 @@ def _ensure_llama_cpp():
|
|
| 438 |
# Use a known stable release
|
| 439 |
release = "b5440"
|
| 440 |
url = f"https://github.com/ggml-org/llama.cpp/releases/download/{release}/llama-{release}-bin-ubuntu-x64.zip"
|
|
|
|
| 441 |
zip_path = os.path.join(bin_dir, "llama.zip")
|
| 442 |
urllib.request.urlretrieve(url, zip_path)
|
|
|
|
| 443 |
|
| 444 |
_log("Benchmark: extracting llama.cpp...")
|
| 445 |
with zipfile.ZipFile(zip_path) as zf:
|
|
|
|
| 446 |
for name in zf.namelist():
|
| 447 |
-
if name.endswith("llama-cli"):
|
| 448 |
-
# Extract to bin_dir
|
| 449 |
data = zf.read(name)
|
| 450 |
with open(llama_cli, "wb") as f:
|
| 451 |
f.write(data)
|
|
|
|
| 452 |
break
|
| 453 |
os.chmod(llama_cli, 0o755)
|
| 454 |
os.unlink(zip_path)
|
| 455 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 456 |
_LLAMA_CPP_BIN = llama_cli
|
| 457 |
-
_log(f"Benchmark: llama.cpp ready at {llama_cli}")
|
| 458 |
return llama_cli
|
| 459 |
|
| 460 |
|
|
@@ -589,10 +600,12 @@ def _patched_create_app(blocks, **kwargs):
|
|
| 589 |
return JSONResponse({"error": str(e)}, status_code=502)
|
| 590 |
|
| 591 |
@fa_app.get("/respite/benchmark")
|
| 592 |
-
def _benchmark():
|
| 593 |
"""Run CPU LLM benchmark. Takes 5-15 minutes. Returns cached results on repeat calls."""
|
| 594 |
try:
|
| 595 |
-
|
|
|
|
|
|
|
| 596 |
results = _run_benchmark()
|
| 597 |
return JSONResponse({
|
| 598 |
"status": "complete",
|
|
|
|
| 438 |
# Use a known stable release
|
| 439 |
release = "b5440"
|
| 440 |
url = f"https://github.com/ggml-org/llama.cpp/releases/download/{release}/llama-{release}-bin-ubuntu-x64.zip"
|
| 441 |
+
_log(f"Benchmark: URL: {url}")
|
| 442 |
zip_path = os.path.join(bin_dir, "llama.zip")
|
| 443 |
urllib.request.urlretrieve(url, zip_path)
|
| 444 |
+
_log(f"Benchmark: downloaded {os.path.getsize(zip_path)} bytes")
|
| 445 |
|
| 446 |
_log("Benchmark: extracting llama.cpp...")
|
| 447 |
with zipfile.ZipFile(zip_path) as zf:
|
| 448 |
+
_log(f"Benchmark: zip contents: {zf.namelist()}")
|
| 449 |
for name in zf.namelist():
|
| 450 |
+
if name.endswith("llama-cli") or name.endswith("llama-cli.exe"):
|
|
|
|
| 451 |
data = zf.read(name)
|
| 452 |
with open(llama_cli, "wb") as f:
|
| 453 |
f.write(data)
|
| 454 |
+
_log(f"Benchmark: extracted {name} ({len(data)} bytes)")
|
| 455 |
break
|
| 456 |
os.chmod(llama_cli, 0o755)
|
| 457 |
os.unlink(zip_path)
|
| 458 |
|
| 459 |
+
# Verify binary works
|
| 460 |
+
_log("Benchmark: verifying llama-cli binary...")
|
| 461 |
+
try:
|
| 462 |
+
check = subprocess.run([llama_cli, "--help"], capture_output=True, text=True, timeout=10)
|
| 463 |
+
_log(f"Benchmark: llama-cli --help exit code: {check.returncode}")
|
| 464 |
+
_log(f"Benchmark: llama-cli --help output: {check.stdout[:200]}")
|
| 465 |
+
except Exception as e:
|
| 466 |
+
_log(f"Benchmark: llama-cli verification failed: {e}")
|
| 467 |
+
|
| 468 |
_LLAMA_CPP_BIN = llama_cli
|
|
|
|
| 469 |
return llama_cli
|
| 470 |
|
| 471 |
|
|
|
|
| 600 |
return JSONResponse({"error": str(e)}, status_code=502)
|
| 601 |
|
| 602 |
@fa_app.get("/respite/benchmark")
|
| 603 |
+
def _benchmark(force: bool = False):
|
| 604 |
"""Run CPU LLM benchmark. Takes 5-15 minutes. Returns cached results on repeat calls."""
|
| 605 |
try:
|
| 606 |
+
global _BENCHMARK_RESULTS
|
| 607 |
+
if force:
|
| 608 |
+
_BENCHMARK_RESULTS = []
|
| 609 |
results = _run_benchmark()
|
| 610 |
return JSONResponse({
|
| 611 |
"status": "complete",
|