Spaces:
Running on Zero
Running on Zero
Fix: extract all llama.cpp libs, set LD_LIBRARY_PATH
Browse files
app.py
CHANGED
|
@@ -445,23 +445,41 @@ def _ensure_llama_cpp():
|
|
| 445 |
|
| 446 |
_log("Benchmark: extracting llama.cpp...")
|
| 447 |
with zipfile.ZipFile(zip_path) as zf:
|
| 448 |
-
_log(f"Benchmark: zip
|
| 449 |
-
|
| 450 |
-
|
| 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 |
-
|
| 463 |
-
|
| 464 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 465 |
except Exception as e:
|
| 466 |
_log(f"Benchmark: llama-cli verification failed: {e}")
|
| 467 |
|
|
@@ -495,6 +513,9 @@ def _run_benchmark():
|
|
| 495 |
)
|
| 496 |
|
| 497 |
_log(f"Benchmark: running {model_info['name']} with {n_threads} threads...")
|
|
|
|
|
|
|
|
|
|
| 498 |
cmd = [
|
| 499 |
llama_cli,
|
| 500 |
"-m", model_path,
|
|
@@ -509,10 +530,11 @@ def _run_benchmark():
|
|
| 509 |
]
|
| 510 |
_log(f"Benchmark: cmd: {' '.join(cmd[:6])}...")
|
| 511 |
_log(f"Benchmark: model exists: {os.path.isfile(model_path)}, size: {os.path.getsize(model_path) if os.path.isfile(model_path) else 0}")
|
|
|
|
| 512 |
t0 = time.time()
|
| 513 |
try:
|
| 514 |
proc = subprocess.run(
|
| 515 |
-
cmd, capture_output=True, text=True, timeout=300,
|
| 516 |
)
|
| 517 |
except subprocess.TimeoutExpired:
|
| 518 |
result["error"] = "Timeout after 300s"
|
|
|
|
| 445 |
|
| 446 |
_log("Benchmark: extracting llama.cpp...")
|
| 447 |
with zipfile.ZipFile(zip_path) as zf:
|
| 448 |
+
_log(f"Benchmark: zip has {len(zf.namelist())} files")
|
| 449 |
+
# Extract ALL files (libs + binaries) to bin_dir
|
| 450 |
+
zf.extractall(bin_dir)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 451 |
os.unlink(zip_path)
|
| 452 |
|
| 453 |
+
# The files are under build/bin/ - move them up and fix permissions
|
| 454 |
+
build_bin = os.path.join(bin_dir, "build", "bin")
|
| 455 |
+
if os.path.isdir(build_bin):
|
| 456 |
+
for fname in os.listdir(build_bin):
|
| 457 |
+
src = os.path.join(build_bin, fname)
|
| 458 |
+
dst = os.path.join(bin_dir, fname)
|
| 459 |
+
os.rename(src, dst)
|
| 460 |
+
os.rmdir(os.path.join(bin_dir, "build", "bin"))
|
| 461 |
+
os.rmdir(os.path.join(bin_dir, "build"))
|
| 462 |
+
|
| 463 |
+
# Make all files executable
|
| 464 |
+
for fname in os.listdir(bin_dir):
|
| 465 |
+
fpath = os.path.join(bin_dir, fname)
|
| 466 |
+
if os.path.isfile(fpath):
|
| 467 |
+
os.chmod(fpath, 0o755)
|
| 468 |
+
|
| 469 |
+
_log(f"Benchmark: extracted to {bin_dir}: {os.listdir(bin_dir)}")
|
| 470 |
+
|
| 471 |
# Verify binary works
|
| 472 |
_log("Benchmark: verifying llama-cli binary...")
|
| 473 |
try:
|
| 474 |
+
# Set LD_LIBRARY_PATH so the binary can find shared libs
|
| 475 |
+
env = os.environ.copy()
|
| 476 |
+
env["LD_LIBRARY_PATH"] = bin_dir + ":" + env.get("LD_LIBRARY_PATH", "")
|
| 477 |
+
check = subprocess.run(
|
| 478 |
+
[llama_cli, "--version"], capture_output=True, text=True, timeout=10, env=env,
|
| 479 |
+
)
|
| 480 |
+
_log(f"Benchmark: llama-cli --version exit code: {check.returncode}")
|
| 481 |
+
_log(f"Benchmark: llama-cli --version stdout: {check.stdout[:200]}")
|
| 482 |
+
_log(f"Benchmark: llama-cli --version stderr: {check.stderr[:200]}")
|
| 483 |
except Exception as e:
|
| 484 |
_log(f"Benchmark: llama-cli verification failed: {e}")
|
| 485 |
|
|
|
|
| 513 |
)
|
| 514 |
|
| 515 |
_log(f"Benchmark: running {model_info['name']} with {n_threads} threads...")
|
| 516 |
+
env = os.environ.copy()
|
| 517 |
+
bin_dir = os.path.dirname(llama_cli)
|
| 518 |
+
env["LD_LIBRARY_PATH"] = bin_dir + ":" + env.get("LD_LIBRARY_PATH", "")
|
| 519 |
cmd = [
|
| 520 |
llama_cli,
|
| 521 |
"-m", model_path,
|
|
|
|
| 530 |
]
|
| 531 |
_log(f"Benchmark: cmd: {' '.join(cmd[:6])}...")
|
| 532 |
_log(f"Benchmark: model exists: {os.path.isfile(model_path)}, size: {os.path.getsize(model_path) if os.path.isfile(model_path) else 0}")
|
| 533 |
+
_log(f"Benchmark: LD_LIBRARY_PATH={bin_dir}")
|
| 534 |
t0 = time.time()
|
| 535 |
try:
|
| 536 |
proc = subprocess.run(
|
| 537 |
+
cmd, capture_output=True, text=True, timeout=300, env=env,
|
| 538 |
)
|
| 539 |
except subprocess.TimeoutExpired:
|
| 540 |
result["error"] = "Timeout after 300s"
|