This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/scripts/sycl/bench_report.sh
T

133 lines
6.9 KiB
Bash
Executable File

#!/bin/sh
# bench_report.sh -- a BetterBench quick run against a live radiance server, its summary and a
# screenshot of its HTML report posted to the Discord webhook (docs/SYCL_PROGRESS.md, Benchmarks).
#
# Usage:
# scripts/sycl/bench_report.sh TAG [ENDPOINT] [SERVED_MODEL]
# runs `betterbench run --quick --decode --prefill` (the brief's command) into
# $RUNS/<date>-<TAG>-<commit>/, then reports it
# scripts/sycl/bench_report.sh --report RUN_DIR TAG
# reports an existing run (results.json and results.html in RUN_DIR) without running
#
# TAG the model and configuration, e.g. minicpm5-2b-bf16; runs with the same TAG are
# compared (the delta is against the newest earlier run of that TAG)
# ENDPOINT default http://127.0.0.1:8100/v1; SERVED_MODEL default: the server's first model
# Everything this script keeps is under the repo's local/ (git-excluded):
# BB BetterBench's venv (default local/tools/betterbench-venv)
# RUNS where runs are kept (default local/radiance-bench/runs)
# PLAYWRIGHT_BROWSERS_PATH the headless Chromium (default local/ms-playwright)
# CHROMIUM_LIBS libraries headless Chromium lacks on this host, unpacked without root
# (default local/tools/chromium-libs/root/usr/lib/x86_64-linux-gnu)
# CHROMIUM_FONTS a fontconfig file naming fonts for it (default local/tools/chromium-libs/fonts.conf):
# this host has no fonts, and without them the report renders with no text
#
# Quick runs are 1 warmup and 5 passes: for tracking progress, not for publishing, and labelled so.
# The numbers are BetterBench's own (report.combined_score for decode, report.prefill_rows for
# prefill), so they are the ones its HTML report shows. The Discord message is built with jq and
# stays under 2000 characters; the webhook URL comes from ~/.config/radiance-bench.env and is never
# printed. A failed post is reported and the script exits 2; no webhook configured exits 0 after
# saying so (the run itself is kept either way).
set -eu
here=$(cd "$(dirname "$0")" && pwd)
root=$(cd "$here/../.." && pwd)
BB=${BB:-$root/local/tools/betterbench-venv}
RUNS=${RUNS:-$root/local/radiance-bench/runs}
CHROMIUM_LIBS=${CHROMIUM_LIBS:-$root/local/tools/chromium-libs/root/usr/lib/x86_64-linux-gnu}
CHROMIUM_FONTS=${CHROMIUM_FONTS:-$root/local/tools/chromium-libs/fonts.conf}
export PLAYWRIGHT_BROWSERS_PATH=${PLAYWRIGHT_BROWSERS_PATH:-$root/local/ms-playwright}
commit=$(git -C "$root" rev-parse --short HEAD)
if [ "${1:-}" = "--report" ]; then
run=${2:?--report RUN_DIR TAG}
tag=${3:?--report RUN_DIR TAG}
else
tag=${1:?usage: bench_report.sh TAG [ENDPOINT] [SERVED_MODEL]}
endpoint=${2:-http://127.0.0.1:8100/v1}
model=${3:-$(curl -sf "$endpoint/models" | jq -r '.data[0].id')}
run=$RUNS/$(date +%Y%m%d-%H%M%S)-$tag-$commit
mkdir -p "$run"
"$BB/bin/betterbench" run --endpoint "$endpoint" --model "$model" \
--quick --decode --prefill --no-update-check \
--name "sycl-$tag-$commit" --out "$run/results.json" \
--note backend=sycl --note gpu=arc-pro-b65 --note commit="$commit" > "$run/betterbench.log" 2>&1
fi
[ -f "$run/results.json" ] || { echo "bench_report.sh: no $run/results.json" >&2; exit 1; }
# The previous run of the same tag, for the delta.
# Directories start with their date, so string order is time order: the newest one before this.
prev=$(ls -d "$RUNS"/*-"$tag"-* 2>/dev/null | sort | awk -v r="$run" '$0 < r' | tail -n 1 || true)
[ -n "$prev" ] && [ -f "$prev/results.json" ] || prev=
# The summary, from BetterBench's own report functions.
"$BB/bin/python" -I - "$run/results.json" ${prev:+"$prev/results.json"} > "$run/summary.json" <<'EOF'
import json, sys
from betterbench import report
def summ(path):
r = json.load(open(path))
comb = report.combined_score(r) or {}
pre = [d for d in report.prefill_rows(r) if not d.get("skipped")]
deep = pre[-1] if pre else {}
return {"decode_med": comb.get("decode"), "decode_low1": comb.get("itl_low1"),
"prefill_med": deep.get("pp_med"), "prefill_low1": deep.get("pp_low1"),
"prefill_depth": deep.get("target_depth"),
"prefill": [{"depth": d["target_depth"], "med": d["pp_med"], "low1": d["pp_low1"]} for d in pre]}
out = {"now": summ(sys.argv[1])}
if len(sys.argv) > 2:
out["prev"] = summ(sys.argv[2])
print(json.dumps(out))
EOF
# The report's screenshot, the whole page, as JPEG (the user's choice of format).
html=$run/results.html
img=$run/report.jpg
if [ -f "$html" ]; then
LD_LIBRARY_PATH=$CHROMIUM_LIBS${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} FONTCONFIG_FILE=$CHROMIUM_FONTS \
"$BB/bin/python" -I - "$html" "$img" <<'EOF'
import sys
from playwright.sync_api import sync_playwright
with sync_playwright() as p:
b = p.chromium.launch()
pg = b.new_page(viewport={"width": 1400, "height": 900}, device_scale_factor=1)
pg.goto("file://" + sys.argv[1])
pg.wait_for_timeout(1500)
pg.screenshot(path=sys.argv[2], full_page=True, type="jpeg", quality=88)
b.close()
EOF
fi
# The message.
jq -n --arg tag "$tag" --arg commit "$commit" --slurpfile s "$run/summary.json" '
def f(x): if x == null then "-" else (x * 10 | round / 10 | tostring) end;
def d(a; b): if a == null or b == null or b == 0 then "" else
" (" + (if a >= b then "+" else "" end) + (((a - b) / b * 1000 | round) / 10 | tostring) + "%)" end;
$s[0] as $x | $x.now as $n | ($x.prev // {}) as $p |
{content: ("**radiance-sycl** quick BetterBench run (1 warmup + 5 passes; for tracking, not publishing)\n" +
"model `" + $tag + "` | commit `" + $commit + "` | GPU Arc Pro B65 (SYCL)\n" +
"decode tok/s: median " + f($n.decode_med) + d($n.decode_med; $p.decode_med) +
", 1% low " + f($n.decode_low1) + d($n.decode_low1; $p.decode_low1) + "\n" +
"prefill tok/s @" + ($n.prefill_depth | tostring) + ": median " + f($n.prefill_med) +
d($n.prefill_med; $p.prefill_med) + ", 1% low " + f($n.prefill_low1) +
d($n.prefill_low1; $p.prefill_low1) + "\n" +
(if $x.prev then "delta vs the previous " + $tag + " run" else "first run of this model" end))[0:1990]}' \
> "$run/payload.json"
cat "$run/payload.json" | jq -r .content
echo "run: $run"
[ -r "$HOME/.config/radiance-bench.env" ] && . "$HOME/.config/radiance-bench.env"
if [ -z "${DISCORD_WEBHOOK_URL:-}" ]; then
echo "bench_report.sh: no DISCORD_WEBHOOK_URL; not posted" >&2
exit 0
fi
if [ -f "$img" ]; then
code=$(curl -sS -o "$run/post.out" -w '%{http_code}' -F "payload_json=<$run/payload.json" \
-F "files[0]=@$img;type=image/jpeg" "$DISCORD_WEBHOOK_URL") || code=000
else
code=$(curl -sS -o "$run/post.out" -w '%{http_code}' -H 'Content-Type: application/json' \
-d @"$run/payload.json" "$DISCORD_WEBHOOK_URL") || code=000
fi
case "$code" in
2??) echo "posted to Discord (HTTP $code)" ;;
*) echo "bench_report.sh: the webhook answered HTTP $code: $(head -c 300 "$run/post.out")" >&2; exit 2 ;;
esac