Desktop foundation / core (ubuntu-latest) (push) Failing after 28s
Desktop foundation / core (macos-latest) (push) Canceled after 0s
Desktop foundation / core (windows-latest) (push) Canceled after 0s
Linux / verify (push) Canceled after 0s
Linux / keyless-cuda (push) Canceled after 0s
Linux / static-cuda-package (push) Canceled after 0s
Linux / hosted-cuda-package (push) Canceled after 0s
Linux / linux-static-cli (push) Canceled after 0s
Linux / linux-cli-container (push) Canceled after 0s
Linux / release-cli (push) Canceled after 0s
189 lines
8.0 KiB
Python
189 lines
8.0 KiB
Python
#!/usr/bin/env python3
|
|
"""Compare two private, sequential runs of bench-chat-paired.py.
|
|
|
|
Useful on one GPU when both model arms cannot fit in VRAM together. The output
|
|
is a descriptive paired report; load order and disk/cache drift still matter.
|
|
"""
|
|
|
|
import argparse
|
|
import datetime as dt
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import statistics
|
|
|
|
|
|
def normalized(row):
|
|
try:
|
|
message = row["response"]["choices"][0]["message"]
|
|
return {
|
|
"content": message.get("content"),
|
|
"tool_calls": [
|
|
{"name": call["function"]["name"],
|
|
"arguments": json.loads(call["function"]["arguments"])}
|
|
for call in message.get("tool_calls") or []
|
|
],
|
|
}
|
|
except (KeyError, IndexError, TypeError, ValueError):
|
|
return None
|
|
|
|
|
|
def selected(report):
|
|
rows = {}
|
|
for row in report["rows"]:
|
|
if row["warmup"]:
|
|
continue
|
|
key = (row["case_id"], row["repeat"])
|
|
if key in rows:
|
|
raise ValueError(f"duplicate run {key}")
|
|
rows[key] = row
|
|
return rows
|
|
|
|
|
|
def initial_requests(base, candidate):
|
|
def rows(report):
|
|
selected_rows = {}
|
|
for row in report["rows"]:
|
|
if row["warmup"]:
|
|
case = row["case_id"]
|
|
if case in selected_rows:
|
|
raise ValueError(f"duplicate initial request for {case}")
|
|
selected_rows[case] = row
|
|
return selected_rows
|
|
|
|
b_rows, c_rows = rows(base), rows(candidate)
|
|
if b_rows.keys() != c_rows.keys():
|
|
raise ValueError("initial requests differ between arms")
|
|
result = {}
|
|
for case in sorted(b_rows):
|
|
b, c = b_rows[case], c_rows[case]
|
|
b_timing = b["response"].get("timings") or {}
|
|
c_timing = c["response"].get("timings") or {}
|
|
result[case] = {
|
|
"baseline_wall_seconds": b["wall_seconds"],
|
|
"candidate_wall_seconds": c["wall_seconds"],
|
|
"baseline_quality_passed": b["quality"]["passed"],
|
|
"candidate_quality_passed": c["quality"]["passed"],
|
|
"baseline_prompt_tokens_processed": b_timing.get("prompt_n"),
|
|
"candidate_prompt_tokens_processed": c_timing.get("prompt_n"),
|
|
"baseline_cached_prompt_tokens": b_timing.get("cache_n"),
|
|
"candidate_cached_prompt_tokens": c_timing.get("cache_n"),
|
|
"baseline_prompt_tokens_per_second": b_timing.get("prompt_per_second"),
|
|
"candidate_prompt_tokens_per_second": c_timing.get("prompt_per_second"),
|
|
}
|
|
return result
|
|
|
|
|
|
def throughput(pairs, field):
|
|
measured = []
|
|
for pair in pairs:
|
|
baseline = pair["baseline_timings"].get(field)
|
|
candidate = pair["candidate_timings"].get(field)
|
|
if (isinstance(baseline, (int, float)) and isinstance(candidate, (int, float))
|
|
and baseline > 0 and candidate > 0):
|
|
measured.append((baseline, candidate))
|
|
if not measured:
|
|
return None
|
|
return {
|
|
"pairs": len(measured),
|
|
"baseline_median_tokens_per_second": statistics.median(a for a, _ in measured),
|
|
"candidate_median_tokens_per_second": statistics.median(b for _, b in measured),
|
|
"candidate_over_baseline_median_ratio": statistics.median(b / a for a, b in measured),
|
|
}
|
|
|
|
|
|
def group_summary(pairs):
|
|
return {
|
|
"pairs": len(pairs),
|
|
"same_normalized_output": sum(pair["same_normalized_output"] for pair in pairs),
|
|
"both_quality_passed": sum(pair["baseline_quality_passed"] and
|
|
pair["candidate_quality_passed"] for pair in pairs),
|
|
"candidate_over_baseline_wall_median_ratio": statistics.median(
|
|
pair["candidate_over_baseline_wall_ratio"] for pair in pairs),
|
|
"prefill": throughput(pairs, "prompt_per_second"),
|
|
"decode": throughput(pairs, "predicted_per_second"),
|
|
}
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("baseline", type=Path)
|
|
parser.add_argument("candidate", type=Path)
|
|
parser.add_argument("--output", type=Path, required=True)
|
|
args = parser.parse_args()
|
|
repository = Path(__file__).resolve().parent.parent
|
|
output = args.output.resolve()
|
|
if output == repository or repository in output.parents:
|
|
parser.error("output must be outside the repository")
|
|
base, candidate = (json.loads(path.read_text()) for path in
|
|
(args.baseline, args.candidate))
|
|
for field in ("schema", "suite_sha256", "model", "configuration"):
|
|
if base[field] != candidate[field]:
|
|
raise ValueError(f"reports differ in {field}")
|
|
b_rows, c_rows = selected(base), selected(candidate)
|
|
if not b_rows or b_rows.keys() != c_rows.keys():
|
|
raise ValueError("reports do not contain the same measured cases")
|
|
pairs = []
|
|
for key in sorted(b_rows):
|
|
b, c = b_rows[key], c_rows[key]
|
|
if b["category"] != c["category"]:
|
|
raise ValueError("case category differs")
|
|
pairs.append({
|
|
"case_id": key[0], "repeat": key[1], "category": b["category"],
|
|
"baseline_wall_seconds": b["wall_seconds"],
|
|
"candidate_wall_seconds": c["wall_seconds"],
|
|
"candidate_over_baseline_wall_ratio": c["wall_seconds"] / b["wall_seconds"],
|
|
"baseline_quality_passed": b["quality"]["passed"],
|
|
"candidate_quality_passed": c["quality"]["passed"],
|
|
"same_normalized_output": (b["http_status"] == c["http_status"] == 200
|
|
and normalized(b) is not None
|
|
and normalized(b) == normalized(c)),
|
|
"baseline_usage": b["response"].get("usage") if isinstance(b["response"], dict) else None,
|
|
"candidate_usage": c["response"].get("usage") if isinstance(c["response"], dict) else None,
|
|
"baseline_timings": (b["response"].get("timings") or {})
|
|
if isinstance(b["response"], dict) else {},
|
|
"candidate_timings": (c["response"].get("timings") or {})
|
|
if isinstance(c["response"], dict) else {},
|
|
})
|
|
categories = {}
|
|
for category in sorted({pair["category"] for pair in pairs}):
|
|
members = [pair for pair in pairs if pair["category"] == category]
|
|
categories[category] = group_summary(members)
|
|
cases = {case: group_summary([pair for pair in pairs if pair["case_id"] == case])
|
|
for case in sorted({pair["case_id"] for pair in pairs})}
|
|
report = {
|
|
"schema": 1, "created_utc": dt.datetime.now(dt.timezone.utc).isoformat(),
|
|
"baseline_report": str(args.baseline.resolve()),
|
|
"candidate_report": str(args.candidate.resolve()),
|
|
"baseline_metadata": base.get("metadata", {}),
|
|
"candidate_metadata": candidate.get("metadata", {}),
|
|
"comparison_limit": "Sequential model loads on one GPU; wall times include API and may drift with I/O and cache state.",
|
|
"summary": {
|
|
"pairs": len(pairs),
|
|
"baseline_quality_passed": sum(p["baseline_quality_passed"] for p in pairs),
|
|
"candidate_quality_passed": sum(p["candidate_quality_passed"] for p in pairs),
|
|
"same_normalized_output": sum(p["same_normalized_output"] for p in pairs),
|
|
"candidate_over_baseline_wall_median_ratio": statistics.median(
|
|
p["candidate_over_baseline_wall_ratio"] for p in pairs),
|
|
"prefill": throughput(pairs, "prompt_per_second"),
|
|
"decode": throughput(pairs, "predicted_per_second"),
|
|
"categories": categories,
|
|
"cases": cases,
|
|
},
|
|
"initial_requests": initial_requests(base, candidate),
|
|
"pairs": pairs,
|
|
}
|
|
output.parent.mkdir(parents=True, exist_ok=True)
|
|
old_mask = os.umask(0o077)
|
|
try:
|
|
with output.open("x", encoding="utf-8") as file:
|
|
json.dump(report, file, indent=2, ensure_ascii=False)
|
|
file.write("\n")
|
|
finally:
|
|
os.umask(old_mask)
|
|
print(json.dumps(report["summary"], indent=2))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|