Linux / keyless-cuda-gate (pull_request) Skipped
Linux / verify (pull_request) Successful in 4m32s
Linux / keyless-cuda (pull_request) Skipped
Linux / static-cuda-package (pull_request) Skipped
Linux / hosted-cuda-package (pull_request) Skipped
Linux / linux-cli-container (pull_request) Successful in 1m38s
Linux / linux-static-cli (pull_request) Successful in 11m8s
Linux / release-cli (pull_request) Skipped
182 lines
8.8 KiB
Python
182 lines
8.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Render a private descriptive paired JSON report as private Markdown."""
|
|
|
|
import argparse
|
|
import html
|
|
import json
|
|
import math
|
|
import os
|
|
from pathlib import Path
|
|
|
|
MAX_BYTES = 16 * 1024 * 1024
|
|
MAX_GROUPS = 1000
|
|
|
|
|
|
def count(value, ceiling=None):
|
|
if type(value) is not int or value < 0 or (ceiling is not None and value > ceiling):
|
|
raise ValueError("invalid count")
|
|
return value
|
|
|
|
|
|
def number(value):
|
|
if type(value) not in (int, float) or not math.isfinite(value) or value <= 0:
|
|
raise ValueError("invalid measurement")
|
|
return f"{value:.6g}"
|
|
|
|
|
|
def label(value):
|
|
if not isinstance(value, str) or not value or len(value) > 256:
|
|
raise ValueError("invalid group label")
|
|
return html.escape(value).replace("|", "|").replace("`", "`").replace("\n", " ").replace("\r", " ").replace("[", "[").replace("]", "]")
|
|
|
|
|
|
def distribution_row(name, distribution, expected):
|
|
n = count(distribution["sample_count"], expected)
|
|
if n != expected or not n:
|
|
raise ValueError("distribution count does not match")
|
|
values = [number(distribution[key]) for key in ("mean", "median", "p10", "p90")]
|
|
if not distribution["p10"] <= distribution["median"] <= distribution["p90"]:
|
|
raise ValueError("invalid percentiles")
|
|
small = distribution["small_sample"]
|
|
if type(small) is not bool or small != (n < 30):
|
|
raise ValueError("invalid sample warning")
|
|
interval = distribution.get("median_confidence_interval")
|
|
bounds = "not reported"
|
|
if interval is not None:
|
|
available = interval["finite_interval_available"]
|
|
if type(available) is not bool:
|
|
raise ValueError("invalid interval availability")
|
|
level = interval["confidence_level"]
|
|
number(level)
|
|
if level > 1:
|
|
raise ValueError("invalid confidence level")
|
|
if available:
|
|
lower, upper = interval["lower"], interval["upper"]
|
|
low_text, high_text = number(lower), number(upper)
|
|
if not lower <= distribution["median"] <= upper:
|
|
raise ValueError("invalid confidence interval")
|
|
bounds = f"{level * 100:.6g}%: [{low_text}, {high_text}]"
|
|
else:
|
|
if interval["lower"] is not None or interval["upper"] is not None:
|
|
raise ValueError("unavailable interval has bounds")
|
|
bounds = "insufficient pairs for finite interval"
|
|
warning = "small sample (<30 pairs)" if small else "30+ pairs; still descriptive"
|
|
return f"| {name} | {n} | {' | '.join(values)} | {bounds} | {warning} |"
|
|
|
|
|
|
def render(report):
|
|
if not isinstance(report, dict) or type(report.get("schema")) is not int or report["schema"] != 1:
|
|
raise ValueError("unsupported report")
|
|
summary = report["summary"]
|
|
pairs = count(summary["pairs"])
|
|
if not pairs:
|
|
raise ValueError("empty report")
|
|
baseline = count(summary["baseline_quality_passed"], pairs)
|
|
candidate = count(summary["candidate_quality_passed"], pairs)
|
|
same = count(summary["same_normalized_output"], pairs)
|
|
ratio = number(summary["candidate_over_baseline_wall_median_ratio"])
|
|
lines = ["# Descriptive paired comparison", "",
|
|
"Sequential loads and synthetic fixtures may confound this comparison. "
|
|
"These numbers do not qualify GPU inference, model quality, or a performance improvement.", "",
|
|
"## Aggregate", "", "| Metric | Value |", "| --- | ---: |",
|
|
f"| Measured pairs | {pairs} |",
|
|
f"| Baseline quality checks passed | {baseline}/{pairs} |",
|
|
f"| Candidate quality checks passed | {candidate}/{pairs} |",
|
|
f"| Same normalized output | {same}/{pairs} |",
|
|
f"| Candidate/baseline median wall ratio (lower is faster) | {ratio} |"]
|
|
if "initial_request_quality_failed" in summary:
|
|
initial_failed = count(summary["initial_request_quality_failed"], pairs)
|
|
lines.append(f"| Initial requests failing quality checks | {initial_failed} |")
|
|
lines += ["",
|
|
"## Categories", "", "Any failing category remains a failed gate; aggregate results cannot hide it.", "",
|
|
"| Category | Pairs | Both quality checks passed | Same output | Wall ratio | Observed checks |",
|
|
"| --- | ---: | ---: | ---: | ---: | --- |"]
|
|
groups = summary["categories"]
|
|
if not isinstance(groups, dict) or not groups or len(groups) > MAX_GROUPS:
|
|
raise ValueError("invalid categories")
|
|
total = total_same = total_both_quality = 0
|
|
for name, group in sorted(groups.items()):
|
|
n = count(group["pairs"], pairs)
|
|
if not n:
|
|
raise ValueError("empty category")
|
|
total += n
|
|
quality = count(group["both_quality_passed"], n)
|
|
same_group = count(group["same_normalized_output"], n)
|
|
total_same += same_group
|
|
total_both_quality += quality
|
|
wall = number(group["candidate_over_baseline_wall_median_ratio"])
|
|
verdict = "PASS (observed only)" if quality == same_group == n else "FAIL"
|
|
lines.append(f"| {label(name)} | {n} | {quality}/{n} | {same_group}/{n} | {wall} | {verdict} |")
|
|
if total != pairs or total_same != same or total_both_quality > min(baseline, candidate):
|
|
raise ValueError("category counts do not match")
|
|
lines += ["", "## Throughput", "",
|
|
"Optional timings cover only pairs with measurements in both arms.", "",
|
|
"| Timing | Pairs | Baseline median tok/s | Candidate median tok/s | Candidate/baseline ratio |",
|
|
"| --- | ---: | ---: | ---: | ---: |"]
|
|
for name in ("prefill", "decode"):
|
|
timing = summary.get(name)
|
|
if timing is None:
|
|
lines.append(f"| {name} | 0 | unavailable | unavailable | unavailable |")
|
|
continue
|
|
n = count(timing["pairs"], pairs)
|
|
if not n:
|
|
raise ValueError("empty timing")
|
|
b = number(timing["baseline_median_tokens_per_second"])
|
|
c = number(timing["candidate_median_tokens_per_second"])
|
|
r = number(timing["candidate_over_baseline_median_ratio"])
|
|
lines.append(f"| {name} | {n} | {b} | {c} | {r} |")
|
|
distributions = []
|
|
for name, group in [("Aggregate", summary), *[(label(k), v) for k, v in sorted(groups.items())]]:
|
|
for arm in ("baseline", "candidate"):
|
|
value = group.get("wall_seconds", {}).get(arm)
|
|
if value is not None:
|
|
distributions.append(distribution_row(f"{name}: {arm} wall seconds", value, group["pairs"]))
|
|
value = group.get("candidate_over_baseline_wall_ratio_distribution")
|
|
if value is not None:
|
|
distributions.append(distribution_row(f"{name}: wall ratio", value, group["pairs"]))
|
|
for name in ("prefill", "decode"):
|
|
timing = summary.get(name)
|
|
if timing is not None:
|
|
for key in ("baseline_distribution", "candidate_distribution", "candidate_over_baseline_ratio_distribution"):
|
|
if key in timing:
|
|
distributions.append(distribution_row(f"{name}: {key.replace('_', ' ')}", timing[key], timing["pairs"]))
|
|
if distributions:
|
|
lines += ["", "## Distributions and uncertainty", "",
|
|
"Intervals describe paired medians under independent-pair assumptions. "
|
|
"Repeated cases, sequential loads and cache drift limit their interpretation.", "",
|
|
"| Measurement | Pairs | Mean | Median | P10 | P90 | Median interval | Sample limit |",
|
|
"| --- | ---: | ---: | ---: | ---: | ---: | --- | --- |", *distributions]
|
|
lines += ["", "Raw responses, tool arguments, and private metadata values are omitted.", ""]
|
|
return "\n".join(lines)
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("report", type=Path)
|
|
parser.add_argument("--output", type=Path, required=True)
|
|
args = parser.parse_args()
|
|
try:
|
|
output = args.output.resolve()
|
|
if any((parent / ".git").exists() for parent in (output, *output.parents)):
|
|
raise ValueError("output must be outside Git")
|
|
with args.report.open("rb") as source:
|
|
data = source.read(MAX_BYTES + 1)
|
|
if len(data) > MAX_BYTES:
|
|
raise ValueError("report too large")
|
|
document = render(json.loads(data))
|
|
output.parent.mkdir(parents=True, exist_ok=True)
|
|
fd = os.open(output, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
|
|
try:
|
|
with os.fdopen(fd, "w", encoding="utf-8") as target:
|
|
target.write(document)
|
|
except BaseException:
|
|
output.unlink()
|
|
raise
|
|
except (ValueError, KeyError, TypeError, OSError, RecursionError):
|
|
parser.exit(1, "paired Markdown report refused: invalid input or unavailable private output\n")
|
|
print("Private descriptive Markdown report written.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|