Spaces:
Running on Zero
Running on Zero
Add debug logging to benchmark parsing
Browse files
app.py
CHANGED
|
@@ -503,31 +503,38 @@ def _run_benchmark():
|
|
| 503 |
wall_time = time.time() - t0
|
| 504 |
output_text = proc.stdout.strip()
|
| 505 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 506 |
# Parse llama.cpp stderr for timing info
|
| 507 |
-
#
|
| 508 |
-
#
|
|
|
|
| 509 |
prompt_tps = 0.0
|
| 510 |
gen_tps = 0.0
|
| 511 |
prompt_tok = 0
|
| 512 |
gen_tok = 0
|
|
|
|
| 513 |
for line in proc.stderr.splitlines():
|
| 514 |
-
|
| 515 |
-
|
| 516 |
-
|
| 517 |
-
|
| 518 |
-
if
|
| 519 |
-
prompt_tps = float(
|
| 520 |
-
|
| 521 |
-
|
| 522 |
-
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
|
|
|
| 531 |
|
| 532 |
result.update({
|
| 533 |
"status": "success",
|
|
|
|
| 503 |
wall_time = time.time() - t0
|
| 504 |
output_text = proc.stdout.strip()
|
| 505 |
|
| 506 |
+
# Log raw output for debugging
|
| 507 |
+
_log(f"Benchmark: {model_info['name']} stdout ({len(output_text)} chars): {output_text[:200]}")
|
| 508 |
+
_log(f"Benchmark: {model_info['name']} stderr ({len(proc.stderr)} chars): {proc.stderr[-500:]}")
|
| 509 |
+
|
| 510 |
# Parse llama.cpp stderr for timing info
|
| 511 |
+
# Various formats depending on version:
|
| 512 |
+
# "prompt eval time = 1234.56 ms / 12 tokens (102.88 ms per token, 9.72 tokens per second)"
|
| 513 |
+
# "eval time = 5678.90 ms / 64 tokens (88.73 ms per token, 11.27 tokens per second)"
|
| 514 |
prompt_tps = 0.0
|
| 515 |
gen_tps = 0.0
|
| 516 |
prompt_tok = 0
|
| 517 |
gen_tok = 0
|
| 518 |
+
import re
|
| 519 |
for line in proc.stderr.splitlines():
|
| 520 |
+
# Match: "N.NN tokens per second"
|
| 521 |
+
tps_match = re.search(r"(\d+\.?\d*) tokens per second", line)
|
| 522 |
+
tok_match = re.search(r"/ (\d+) tokens", line)
|
| 523 |
+
if "prompt eval" in line.lower() or "prompt_eval" in line.lower():
|
| 524 |
+
if tps_match:
|
| 525 |
+
prompt_tps = float(tps_match.group(1))
|
| 526 |
+
if tok_match:
|
| 527 |
+
prompt_tok = int(tok_match.group(1))
|
| 528 |
+
elif ("eval time" in line.lower() or "eval_time" in line.lower()) and "prompt" not in line.lower():
|
| 529 |
+
if tps_match:
|
| 530 |
+
gen_tps = float(tps_match.group(1))
|
| 531 |
+
if tok_match:
|
| 532 |
+
gen_tok = int(tok_match.group(1))
|
| 533 |
+
|
| 534 |
+
# If parsing failed, try counting newlines as rough token estimate
|
| 535 |
+
if gen_tok == 0 and output_text:
|
| 536 |
+
gen_tok = len(output_text.split())
|
| 537 |
+
_log(f"Benchmark: parsing failed, estimated {gen_tok} tokens from word count")
|
| 538 |
|
| 539 |
result.update({
|
| 540 |
"status": "success",
|