Spaces:
Running on Zero
Running on Zero
Fix CPU benchmark diagnostics
Browse files
app.py
CHANGED
|
@@ -218,7 +218,7 @@ def _ensure_llama():
|
|
| 218 |
bd = os.path.join(_BENCH_CACHE, "build")
|
| 219 |
os.makedirs(bd, exist_ok=True)
|
| 220 |
nt = _parse_cpu_count() or 8
|
| 221 |
-
subprocess.check_call(["cmake","-S",src,"-B",bd,"-DLLAMA_NATIVE=ON","-DBUILD_SHARED_LIBS=OFF"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 222 |
subprocess.check_call(["cmake","--build",bd,"-j",str(nt),"--target","llama-cli"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 223 |
import glob as _g
|
| 224 |
cands = _g.glob(os.path.join(bd,"**","llama-cli"), recursive=True)
|
|
@@ -244,21 +244,39 @@ def _run_bench(model_filter=None):
|
|
| 244 |
mp = hf_hub_download(repo_id=mi["repo"], filename=mi["file"], cache_dir=_BENCH_CACHE)
|
| 245 |
env = os.environ.copy()
|
| 246 |
env["LD_LIBRARY_PATH"] = os.path.dirname(cli)
|
| 247 |
-
np =
|
| 248 |
-
to =
|
| 249 |
t0 = time.time()
|
| 250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
wt = time.time()-t0
|
| 252 |
-
|
| 253 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
tm = re.search(r"(\d+\.?\d*) tokens per second", line)
|
| 255 |
km = re.search(r"/ (\d+) tokens", line)
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
if
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
if
|
|
|
|
| 262 |
r.update({"status":"success","total_time_sec":round(wt,2),"prompt_tokens":ptk,"completion_tokens":gtk,"prompt_tokens_per_sec":round(pt,1),"generation_tokens_per_sec":round(gt,1),"output":p.stdout.strip()[:500]})
|
| 263 |
except Exception as e:
|
| 264 |
r["error"] = str(e)
|
|
|
|
| 218 |
bd = os.path.join(_BENCH_CACHE, "build")
|
| 219 |
os.makedirs(bd, exist_ok=True)
|
| 220 |
nt = _parse_cpu_count() or 8
|
| 221 |
+
subprocess.check_call(["cmake","-S",src,"-B",bd,"-DLLAMA_NATIVE=ON","-DLLAMA_CUDA=OFF","-DGGML_CUDA=OFF","-DBUILD_SHARED_LIBS=OFF"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 222 |
subprocess.check_call(["cmake","--build",bd,"-j",str(nt),"--target","llama-cli"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 223 |
import glob as _g
|
| 224 |
cands = _g.glob(os.path.join(bd,"**","llama-cli"), recursive=True)
|
|
|
|
| 244 |
mp = hf_hub_download(repo_id=mi["repo"], filename=mi["file"], cache_dir=_BENCH_CACHE)
|
| 245 |
env = os.environ.copy()
|
| 246 |
env["LD_LIBRARY_PATH"] = os.path.dirname(cli)
|
| 247 |
+
np = 48 if mi["size_gb"] <= 6 else 24
|
| 248 |
+
to = 240 if mi["size_gb"] <= 6 else 600
|
| 249 |
t0 = time.time()
|
| 250 |
+
command = [
|
| 251 |
+
cli, "-m", mp, "-t", str(nt), "-ngl", "0",
|
| 252 |
+
"-c", "1024", "-n", str(np), "-b", "128",
|
| 253 |
+
"--temp", "0.7", "--top-p", "0.9", "-p", prompt,
|
| 254 |
+
"--no-display-prompt",
|
| 255 |
+
]
|
| 256 |
+
try:
|
| 257 |
+
p = subprocess.run(command, capture_output=True, text=True, timeout=to, env=env)
|
| 258 |
+
except subprocess.TimeoutExpired as e:
|
| 259 |
+
partial = e.stdout or e.stderr or ""
|
| 260 |
+
if isinstance(partial, bytes):
|
| 261 |
+
partial = partial.decode("utf-8", "replace")
|
| 262 |
+
raise RuntimeError(f"llama.cpp timed out after {to}s; partial output: {partial[-1000:]}")
|
| 263 |
wt = time.time()-t0
|
| 264 |
+
if p.returncode != 0:
|
| 265 |
+
diagnostics = (p.stderr or p.stdout or "").strip()
|
| 266 |
+
raise RuntimeError(f"llama.cpp exited with code {p.returncode}: {diagnostics[-1500:]}")
|
| 267 |
+
combined_output = (p.stderr or "") + "\n" + (p.stdout or "")
|
| 268 |
+
pt = gt = 0.0
|
| 269 |
+
ptk = gtk = 0
|
| 270 |
+
for line in combined_output.splitlines():
|
| 271 |
tm = re.search(r"(\d+\.?\d*) tokens per second", line)
|
| 272 |
km = re.search(r"/ (\d+) tokens", line)
|
| 273 |
+
lower = line.lower()
|
| 274 |
+
if "prompt eval" in lower:
|
| 275 |
+
if tm: pt = float(tm.group(1))
|
| 276 |
+
if km: ptk = int(km.group(1))
|
| 277 |
+
elif "eval time" in lower and "prompt" not in lower:
|
| 278 |
+
if tm: gt = float(tm.group(1))
|
| 279 |
+
if km: gtk = int(km.group(1))
|
| 280 |
r.update({"status":"success","total_time_sec":round(wt,2),"prompt_tokens":ptk,"completion_tokens":gtk,"prompt_tokens_per_sec":round(pt,1),"generation_tokens_per_sec":round(gt,1),"output":p.stdout.strip()[:500]})
|
| 281 |
except Exception as e:
|
| 282 |
r["error"] = str(e)
|