One-file bench.sh, sources in dev/, BetterBench 0.6.1 or newer

- bench.sh at the root is generated by dev/build.sh and holds everything;
  people download just that file. It unpacks its helpers to a temp dir;
  results and bench.local.env stay next to it
- collect-env and the power sampler are subcommands (bench.sh collect-env,
  bench.sh power); --help is the manual, --version prints the versions
- BetterBench: minimum 0.6.1 instead of exactly 0.6.1; the version is
  recorded in the run note. Standard bumped to 0.4.0
- each run folder gets a copy of config.json
- AGENTS.md carries the install, the models with hashes and the agent
  procedure; README is a pointer; DETAILS.md moved to dev/

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
claudeandClaude Opus 5.5 committed 2026-10-29 12:58:02 +01:00
1 parent 9400c074bd
commit 1f4ea0b225
13 files changed
+1330 -209

No files matched your search

+534 -32
View File
@@ -1,46 +1,86 @@
#!/bin/sh
# bench.sh - the single entry point for a standardized BetterBench run (see README.md).
# bench.sh - bench-standard 0.4.0, everything in one file: run ./bench.sh --help
# Generated by dev/build.sh from dev/ - edit there and rebuild, not here.
set -eu
BENCH_HOME=${BENCH_HOME:-$(cd "$(dirname "$0")" && pwd)}; export BENCH_HOME
d=$(mktemp -d)
trap 'rm -rf "$d"' EXIT
trap 'rm -rf "$d"; exit 130' INT
trap 'rm -rf "$d"; exit 143' TERM
cat > "$d/bench.sh" <<'__BENCH_STANDARD_EOF__'
#!/bin/sh
# bench.sh - bench-standard: benchmark an LLM server the way everyone in the
# group does, with BetterBench 0.6.1+. Every result records its setup (GPU,
# PCIe, engine, launch flags, ...), so results stay comparable.
#
# usage: bench.sh --endpoint URL --model ID
# --tp N --pp N --quant Q --kv KV --spec none|METHOD:N
# --thinking MODE --submitter NAME
# [--power-limit W|stock] [--api-key KEY] [--server-cmd-file FILE]
# [--env-file FILE] [--pcie GenN xW] [--special-notes TEXT]
# [--mem-bw GBPS] [--results-dir DIR] [--full] [--no-concurrency]
# [--verbose] [--dry-run]
# A quick check (a few minutes), then the same with --full for the real run:
# ./bench.sh --endpoint http://localhost:8080/v1 --model MODEL_ID \
# --tp 1 --pp 1 --quant Q4_K_M --kv f16 --spec none --thinking default \
# --submitter YOUR_NAME --server-cmd-file server-cmd.txt
#
# Default is a quick smoke run (BetterBench --quick); --full is the run that
# counts for submission.
# Mandatory values may also come from the environment: BENCH_TP, BENCH_PP,
# BENCH_QUANT, BENCH_KV, BENCH_SPEC, BENCH_THINKING, BENCH_SUBMITTER.
# --power-limit (or BENCH_POWER_LIMIT): read from the GPU when omitted; required
# only where it can't be detected. API key: --api-key or $BETTERBENCH_API_KEY.
# --pcie (or BENCH_PCIE): declare the slot link where it can't be read (VMs).
# --special-notes (or BENCH_SPECIAL_NOTES): free text for anything unusual
# about this run, e.g. "custom k8v4 kernels" or "undervolted".
# --mem-bw (or BENCH_MEM_BW): the card's declared (spec sheet) memory
# bandwidth in GB/s, recorded next to the one collect-env.sh measures.
# --verbose: stream BetterBench's full output (default: progress lines and a
# summary; the full output is in betterbench.log either way).
# --env-file: output of collect-env.sh run on the server, when BetterBench
# runs on another machine (default: run collect-env.sh here).
# You declare (these can't be detected):
# --tp N / --pp N tensor / pipeline parallel size
# --quant Q weight quantization: Q4_K_M, UD-Q4_K_M, w4a16, bf16
# --kv KV KV cache type: f16, bf16, q8_0
# --spec S speculative decoding: none, or METHOD:N with METHOD
# mtp, eagle, eagle3, ngram or draft (e.g. mtp:5)
# --thinking T thinking mode set on the server: off, on, low, medium,
# high or default
# --submitter NAME you
# --server-cmd-file F the command that started the server (not needed
# behind llama-swap, which reports it)
#
# Options:
# --full the run that counts (default: a quick check)
# --verbose show all of BetterBench's output
# --dry-run detect everything, print what would run, stop
# --mem-bw GBPS the card's spec memory bandwidth (measured anyway)
# --power-limit W when it can't be read from the GPU, or 'stock'
# --pcie "Gen4 x16" inside a VM, where the link can't be read
# --special-notes TXT anything unusual: custom kernels, undervolt, ...
# --api-key KEY or $BETTERBENCH_API_KEY; never stored
# --no-concurrency skip the concurrency sweep
# --results-dir DIR default: results/ next to bench.sh
# --env-file FILE when BetterBench runs on another machine than the GPU:
# the output of 'bench.sh collect-env' run on the GPU box
#
# Other commands:
# bench.sh collect-env --endpoint URL --model ID print the detected setup
# bench.sh power [SECONDS] sample GPU power, energy and clock until killed
# bench.sh --version
#
# Values can also come from the environment: BENCH_TP, BENCH_PP, BENCH_QUANT,
# BENCH_KV, BENCH_SPEC, BENCH_THINKING, BENCH_SUBMITTER, BENCH_POWER_LIMIT,
# BENCH_PCIE, BENCH_MEM_BW, BENCH_SPECIAL_NOTES, BENCH_RESULTS_DIR. Machine-
# local defaults like these go in bench.local.env next to bench.sh.
# Send the whole results/<run>/ folder. Only --full runs count.
# The standard models, their hashes and step-by-step help: AGENTS.md.
set -eu
umask 002
# here: the helper files. home: where results and bench.local.env go - next to
# the bench.sh people run, which unpacks the helpers to a temp dir.
here=$(cd "$(dirname "$0")" && pwd)
home=${BENCH_HOME:-$here}
. "$here/standard.env"
# Machine-local defaults (e.g. BENCH_RESULTS_DIR), not part of the standard.
[ -f "$here/bench.local.env" ] && . "$here/bench.local.env"
[ -f "$home/bench.local.env" ] && . "$home/bench.local.env"
die() { echo "bench.sh: $*" >&2; exit 1; }
usage() { sed -n '2,27p' "$0"; exit "${1:-0}"; }
usage() { sed -n '2,/^$/p' "$0" | sed -e 's/^# \{0,1\}//' -e '$d'; exit "${1:-0}"; }
case "${1:-}" in
collect-env) shift; exec sh "$here/collect-env.sh" "$@" ;;
power) shift; exec sh "$here/gpu-power.sh" "$@" ;;
--version) echo "bench-standard $STANDARD_VERSION (BetterBench $BETTERBENCH_MIN_VERSION or newer)"; exit 0 ;;
esac
endpoint="" model="" server_cmd_file="" env_file="" quick=1 no_conc=0 dry=0 verbose=0
tp=${BENCH_TP:-} pp=${BENCH_PP:-} quant=${BENCH_QUANT:-} kv=${BENCH_KV:-}
spec=${BENCH_SPEC:-} thinking=${BENCH_THINKING:-} power_limit=${BENCH_POWER_LIMIT:-}
submitter=${BENCH_SUBMITTER:-} pcie=${BENCH_PCIE:-} special=${BENCH_SPECIAL_NOTES:-}
mem_bw=${BENCH_MEM_BW:-}
results_dir=${BENCH_RESULTS_DIR:-$here/results}
results_dir=${BENCH_RESULTS_DIR:-$home/results}
need() { [ "$1" -ge 2 ] || die "$2 needs a value"; }
while [ $# -gt 0 ]; do
@@ -75,11 +115,13 @@ done
# ---------------------------------------------------------------- checks
matches() { printf '%s\n' "$1" | grep -Eqx "$2"; }
have_ver=$(betterbench --version 2>/dev/null | awk '{print $NF}') || have_ver=""
[ "$have_ver" = "$BETTERBENCH_VERSION" ] ||
die "BetterBench $BETTERBENCH_VERSION required, found '${have_ver:-not installed}'" \
"(git checkout v$BETTERBENCH_VERSION && pip install -e .)"
command -v python3 >/dev/null || die "python3 not found"
have_ver=$(betterbench --version 2>/dev/null | awk '{print $NF}') || have_ver=""
python3 -c 'import re, sys
v = lambda s: tuple(int(x) for x in re.findall(r"\d+", s)[:3])
sys.exit(not sys.argv[1] or v(sys.argv[1]) < v(sys.argv[2]))' "$have_ver" "$BETTERBENCH_MIN_VERSION" ||
die "BetterBench $BETTERBENCH_MIN_VERSION or newer required, found '${have_ver:-not installed}'" \
"(see https://github.com/GGZ14/BetterBench)"
command -v curl >/dev/null || die "curl not found"
missing=""
@@ -185,6 +227,7 @@ fi
[ -n "$pcie" ] && printf 'pcie=%s\n' "$pcie"
[ -n "$special" ] && printf 'special_notes=%s\n' "$special"
[ -n "$mem_bw" ] && printf 'mem_bw=%s\n' "$mem_bw"
printf 'betterbench=%s\n' "$have_ver"
printf 'bench_standard=%s\nrun_mode=%s\nconcurrency=%s\n' "$STANDARD_VERSION" \
"$([ $quick = 1 ] && echo quick || echo full)" "$([ $no_conc = 1 ] && echo off || echo on)"
} > "$tmp/mandatory"
@@ -391,7 +434,7 @@ notes = [
("thinking", m["thinking"]),
("greedy_check", greedy),
("run", join(m["run_mode"], "concurrency " + m["concurrency"],
"bench-standard " + m["bench_standard"])),
"bench-standard " + m["bench_standard"], "betterbench " + m["betterbench"])),
]
if m.get("special_notes"):
notes.append(("special_notes", m["special_notes"]))
@@ -413,7 +456,7 @@ run_dir="$results_dir/$(date +%Y%m%d-%H%M%S)-$(printf '%s' "$submitter" | slug)-
# ---------------------------------------------------------------- run
set -- run --no-update-check --endpoint "$endpoint" --model "$model" \
--config "$here/config.json" --name "$name" --out "$run_dir/results.json"
--config "$run_dir/config.json" --name "$name" --out "$run_dir/results.json"
[ $quick = 1 ] && set -- "$@" --quick
[ $no_conc = 1 ] && set -- "$@" --no-concurrency
# Through a proxy /v1/models often lacks the context size; hand over what the
@@ -431,6 +474,7 @@ fi
mkdir -p "$results_dir"
mkdir "$run_dir" || die "cannot create $run_dir"
cp "$here/config.json" "$run_dir/config.json"
[ -n "$cmd_src" ] && cp "$tmp/cmd.red" "$run_dir/server-cmd.txt"
STANDARD_VERSION=$STANDARD_VERSION CMD_SRC=$cmd_src ENDPOINT=$endpoint MODEL=$model NAME=$name NOTES=$tmp/notes \
@@ -609,3 +653,461 @@ PY
echo
echo "done: $run_dir"
ls -1 "$run_dir"
__BENCH_STANDARD_EOF__
cat > "$d/collect-env.sh" <<'__BENCH_STANDARD_EOF__'
#!/bin/sh
# collect-env.sh - run ON THE INFERENCE SERVER. Prints a flat key=value list
# describing the hardware and the inference engine behind an endpoint.
# Never aborts on detection: anything it cannot find is reported as "unknown".
#
# usage: collect-env.sh [--endpoint URL] [--model ID] [--api-key KEY] [--server-cmd-out FILE]
# [--server-cmd-file FILE]
# --endpoint OpenAI-compatible base, e.g. http://localhost:8080/v1 (omit: hardware only)
# --model model id as sent to the endpoint (needed behind llama-swap)
# --server-cmd-out behind llama-swap: write the model's launch command (raw) to FILE
# --server-cmd-file the launch command when not behind llama-swap (finds the container)
# env: BETTERBENCH_API_KEY, PROBE_TIMEOUT (s, default 10), LOAD_TIMEOUT (s, default 600),
# MEASURE_BW=0 (skip the bandwidth test), BW_PYTHON (python with torch for it)
set -u
LC_ALL=C; export LC_ALL
endpoint="" model="" api_key="${BETTERBENCH_API_KEY:-}" cmd_out="" cmd_file=""
PROBE_TIMEOUT=${PROBE_TIMEOUT:-10}
LOAD_TIMEOUT=${LOAD_TIMEOUT:-600}
need() { [ "$1" -ge 2 ] || { echo "collect-env: $2 needs a value" >&2; exit 2; }; }
while [ $# -gt 0 ]; do
case "$1" in
--endpoint) need $# "$1"; endpoint=$2; shift 2 ;;
--model) need $# "$1"; model=$2; shift 2 ;;
--api-key) need $# "$1"; api_key=$2; shift 2 ;;
--server-cmd-out) need $# "$1"; cmd_out=$2; shift 2 ;;
--server-cmd-file) need $# "$1"; cmd_file=$2; shift 2 ;;
-h|--help) sed -n '2,13p' "$0"; exit 0 ;;
*) echo "collect-env: unknown argument: $1" >&2; exit 2 ;;
esac
done
tmp=$(mktemp -d) || exit 1
trap 'rm -rf "$tmp"' EXIT INT TERM
# Header via a file so the key never shows up in `ps`.
if [ -n "$api_key" ]; then printf 'Authorization: Bearer %s\n' "$api_key" > "$tmp/hdr"
else printf 'Accept: application/json\n' > "$tmp/hdr"; fi
have() { command -v "$1" >/dev/null 2>&1; }
# jget FILE EXPR - evaluate a python expression over the parsed JSON `j`
# (and `arg` = $JARG); prints nothing on any failure. Tolerates junk before
# the JSON (xpu-smi prints "[Error] ..." lines on stdout).
jget() {
have python3 || return 0
python3 - "$1" "$2" <<'PY' 2>/dev/null
import json, os, sys
try:
raw = open(sys.argv[1], encoding="utf-8", errors="replace").read()
try:
j = json.loads(raw)
except ValueError:
j = json.loads(raw[raw.index("{"):])
v = eval(sys.argv[2], {"j": j, "arg": os.environ.get("JARG", "")})
if v is not None and v != "":
print(" ".join(str(v).split()))
except Exception:
pass
PY
}
# fetch URL OUTFILE [TIMEOUT] - succeeds only on HTTP 2xx.
fetch() {
have curl || return 1
code=$(curl -s -m "${3:-$PROBE_TIMEOUT}" -o "$2" -w '%{http_code}' -H @"$tmp/hdr" "$1" 2>/dev/null) || code=000
case "$code" in 2*) return 0 ;; *) return 1 ;; esac
}
# Strip vendor boilerplate so the same card reads the same everywhere.
norm_gpu() {
sed -e 's/([RT]M*)//g' -e 's/^ *Intel *//' -e 's/^ *NVIDIA *//' -e 's/^ *AMD *//' \
-e 's/ Graphics *$//' -e 's/ */ /g' -e 's/^ //' -e 's/ $//'
}
kv() { printf '%s=%s\n' "$1" "$(printf '%s' "${2:-unknown}" | tr '\n\r' ' ')"; }
# "16.0 GT/s PCIe" -> 4
pcie_gen() {
case "$1" in
2.5*) echo 1 ;; 5.0*|5\ *) echo 2 ;; 8.0*|8\ *) echo 3 ;; 16.0*|16\ *) echo 4 ;;
32.0*|32\ *) echo 5 ;; 64.0*|64\ *) echo 6 ;; *) echo "" ;;
esac
}
# pcie_of BDF - sets pcie_link (negotiated now) and pcie_max (what card and slot
# both support) for the link into the slot. Cards with their own PCIe switch
# (Intel Arc, some AMD) expose an internal link on the GPU function itself, so
# walk up through bridges of the GPU's vendor to the switch's upstream port.
pcie_of() {
d=$(readlink -f "/sys/bus/pci/devices/$1" 2>/dev/null) && [ -f "$d/vendor" ] || return 0
vendor=$(cat "$d/vendor")
while p=${d%/*}; [ -f "$p/class" ] && [ "$(cat "$p/vendor")" = "$vendor" ]; do
case $(cat "$p/class") in 0x0604*) d=$p ;; *) break ;; esac
done
p=${d%/*}
g=$(pcie_gen "$(cat "$d/current_link_speed" 2>/dev/null)") w=$(cat "$d/current_link_width" 2>/dev/null)
[ -n "$g" ] && [ -n "$w" ] && pcie_link="Gen$g x$w"
g=$(pcie_gen "$(cat "$d/max_link_speed" 2>/dev/null)") w=$(cat "$d/max_link_width" 2>/dev/null)
if [ -f "$p/max_link_speed" ]; then
pg=$(pcie_gen "$(cat "$p/max_link_speed")") pw=$(cat "$p/max_link_width" 2>/dev/null)
[ -n "$pg" ] && [ "$pg" -lt "${g:-99}" ] && g=$pg
[ -n "$pw" ] && [ "$pw" -lt "${w:-99}" ] && w=$pw
fi
[ -n "$g" ] && [ -n "$w" ] && pcie_max="Gen$g x$w"
return 0
}
# ---------------------------------------------------------------- GPU
gpu_vendor=none gpu_model="" gpu_count=0 gpu_vram_gb="" gpu_driver="" gpu_power_limit_w="" gpu_bdf=""
if have nvidia-smi && q=$(nvidia-smi --query-gpu=name,memory.total,driver_version,power.limit,pci.bus_id \
--format=csv,noheader,nounits 2>/dev/null) && [ -n "$q" ]; then
gpu_vendor=nvidia
gpu_count=$(printf '%s\n' "$q" | grep -c .)
gpu_model=$(printf '%s\n' "$q" | cut -d, -f1 | norm_gpu | sort -u | paste -sd+ -)
first=$(printf '%s\n' "$q" | head -n1)
gpu_vram_gb=$(printf '%s' "$first" | cut -d, -f2 | awk '$1+0>0 {printf "%d", $1/1024+0.5}')
gpu_driver=$(printf '%s' "$first" | cut -d, -f3 | tr -d ' ')
gpu_power_limit_w=$(printf '%s' "$first" | cut -d, -f4 | awk '$1+0>0 {printf "%g", $1}')
# 00000000:01:00.0 -> 0000:01:00.0
gpu_bdf=$(printf '%s' "$first" | cut -d, -f5 | tr -d ' ' | tr 'A-F' 'a-f' | sed 's/^[0-9a-f]*\([0-9a-f]\{4\}:\)/\1/')
elif have rocm-smi && rocm-smi --showproductname --json > "$tmp/rp" 2>/dev/null; then
gpu_vendor=amd
rocm-smi --showmeminfo vram --json > "$tmp/rm" 2>/dev/null
rocm-smi --showdriverversion --json > "$tmp/rd" 2>/dev/null
rocm-smi --showmaxpower --json > "$tmp/rw" 2>/dev/null
rocm-smi --showbus --json > "$tmp/rb" 2>/dev/null
gpu_bdf=$(jget "$tmp/rb" 'next(v["PCI Bus"] for k, v in j.items() if k.startswith("card")).lower()')
gpu_count=$(jget "$tmp/rp" 'len([k for k in j if k.startswith("card")])')
gpu_model=$(jget "$tmp/rp" '"+".join(sorted({v.get("Card Series") or v.get("Card series") or v.get("Card model", "") for k, v in j.items() if k.startswith("card")}))' | norm_gpu)
gpu_vram_gb=$(jget "$tmp/rm" 'round(int(next(v["VRAM Total Memory (B)"] for k, v in j.items() if k.startswith("card"))) / 2**30)')
gpu_driver=$(jget "$tmp/rd" 'j["system"]["Driver version"]')
gpu_power_limit_w=$(jget "$tmp/rw" '"%g" % float(next(v for k, v in next(c for n, c in j.items() if n.startswith("card")).items() if "Power" in k))')
elif have xpu-smi && xpu-smi discovery -j > "$tmp/xl" 2>/dev/null; then
gpu_vendor=intel
gpu_count=$(jget "$tmp/xl" 'len(j["device_list"])')
gpu_model=$(jget "$tmp/xl" '"+".join(sorted({d["device_name"] for d in j["device_list"]}))' | norm_gpu)
dev0=$(jget "$tmp/xl" 'j["device_list"][0]["device_id"]')
gpu_bdf=$(jget "$tmp/xl" 'j["device_list"][0]["pci_bdf_address"].lower()')
if [ -n "$dev0" ]; then
xpu-smi discovery -d "$dev0" -j > "$tmp/xd" 2>/dev/null
gpu_vram_gb=$(jget "$tmp/xd" 'round(int(j["memory_physical_size_byte"]) / 2**30)')
gpu_driver=$(jget "$tmp/xd" 'j["driver_version"]')
# Newer xpu-smi takes named metrics; the old numeric -m syntax is gone.
gpu_power_limit_w=$(xpu-smi dump --device "$dev0" --metrics power.limit --number 1 2>/dev/null \
| awk -F', *' 'NR>1 && $3+0>0 {printf "%g", $3; exit}')
fi
fi
[ -n "$gpu_count" ] || gpu_count=unknown
# ---------------------------------------------------------------- host
# In a VM the GPU hangs off a virtual root port whose link figures are made
# up, so PCIe is only measured on bare metal.
virt=$(systemd-detect-virt --vm 2>/dev/null) || virt=none
pcie_link="" pcie_max=""
if [ "$virt" = none ] && [ -n "$gpu_bdf" ]; then pcie_of "$gpu_bdf"
elif [ "$virt" != none ]; then pcie_link="unknown (VM)" pcie_max="unknown (VM)"; fi
# Largest BAR of the GPU function: about VRAM-sized with Resizable BAR on,
# 256 MiB or less when off - the rule BetterBench's own fingerprint uses
# (GGZ14/BetterBench#4). Passthrough keeps BAR sizes, so this holds in a VM too.
gpu_bar_mib="" rebar=""
if [ -n "$gpu_bdf" ] && [ -r "/sys/bus/pci/devices/$gpu_bdf/resource" ] && have python3; then
gpu_bar_mib=$(python3 - "/sys/bus/pci/devices/$gpu_bdf/resource" <<'PY' 2>/dev/null
import sys
bars = []
for line in open(sys.argv[1]):
try:
start, end, _ = (int(x, 16) for x in line.split())
except ValueError:
continue
if end > start:
bars.append((end - start + 1) >> 20)
if bars:
print(max(bars))
PY
)
if [ -n "$gpu_bar_mib" ]; then
if [ "$gpu_bar_mib" -gt 256 ]; then rebar=on; else rebar=off; fi
fi
fi
cpu_model=$(lscpu 2>/dev/null | sed -n 's/^Model name: *//p' | head -n1)
[ -n "$cpu_model" ] || cpu_model=$(sed -n 's/^model name[[:space:]]*: *//p' /proc/cpuinfo 2>/dev/null | head -n1)
ram_gb=$(awk '/^MemTotal:/ {printf "%d", $2/1048576+0.5}' /proc/meminfo 2>/dev/null)
os=$( (. /etc/os-release 2>/dev/null && printf '%s' "${PRETTY_NAME:-}") )
[ -n "$os" ] || os=$(uname -s 2>/dev/null)
kernel=$(uname -r 2>/dev/null)
# ---------------------------------------------------------------- engine
proxy=none engine=unknown engine_version="" model_file="" ctx="" engine_slots=""
if [ -n "$endpoint" ]; then
base=${endpoint%/}; base=${base%/v1}
prefix=$base
t1=$PROBE_TIMEOUT
if fetch "$base/running" "$tmp/running" && [ -n "$(jget "$tmp/running" '"running" in j and "y"')" ]; then
proxy=llama-swap
if [ -n "$model" ]; then
prefix="$base/upstream/$model"
export JARG="$model"
state=$(jget "$tmp/running" 'next((r.get("state") for r in j["running"] if r.get("model") == arg), "")')
if [ "$state" != ready ]; then
echo "collect-env: $model is not loaded; llama-swap loads it on this probe (up to ${LOAD_TIMEOUT}s)" >&2
t1=$LOAD_TIMEOUT
fi
fi
fi
if fetch "$prefix/props" "$tmp/props" "$t1" \
&& [ -n "$(jget "$tmp/props" '("build_info" in j or "default_generation_settings" in j) and "y"')" ]; then
engine=llama.cpp
engine_version=$(jget "$tmp/props" 'j.get("build_info")')
model_file=$(jget "$tmp/props" 'j.get("model_path")')
ctx=$(jget "$tmp/props" '(j.get("default_generation_settings") or {}).get("n_ctx") or j.get("n_ctx")')
engine_slots=$(jget "$tmp/props" 'j.get("total_slots")')
elif fetch "$prefix/version" "$tmp/version" "$t1" \
&& v=$(jget "$tmp/version" 'j.get("version")') && [ -n "$v" ]; then
engine_version=$v
if fetch "$prefix/v1/models" "$tmp/models"; then
export JARG="$model"
# Behind a proxy the served name differs from the routed id, so a single
# entry is taken as is.
pick='next((m for m in j["data"] if m.get("id") == arg), j["data"][0] if len(j["data"]) == 1 else {})'
[ "$(jget "$tmp/models" "($pick).get('owned_by')")" = vllm ] && engine=vllm
ctx=$(jget "$tmp/models" "($pick).get('max_model_len')")
model_file=$(jget "$tmp/models" "($pick).get('root')")
fi
fi
# Behind llama-swap the launch command is known: keep it, and map a
# container path (-v HOST:/model) back to the host path.
if [ "$proxy" = llama-swap ] && [ -n "$model" ] && fetch "$base/running" "$tmp/running"; then
export JARG="$model"
jget "$tmp/running" 'next((r.get("cmd") for r in j["running"] if r.get("model") == arg), "")' > "$tmp/cmd"
if [ -s "$tmp/cmd" ]; then
[ -n "$cmd_out" ] && cp "$tmp/cmd" "$cmd_out"
if [ -n "$model_file" ] && have python3; then
host=$(python3 - "$tmp/cmd" "$model_file" <<'PY' 2>/dev/null
import re, sys
cmd, path = open(sys.argv[1]).read(), sys.argv[2]
for src, dst in re.findall(r'(?:-v|--volume)[ =](\S+?):(/[^\s:]*)', cmd):
if path == dst or path.startswith(dst.rstrip("/") + "/"):
print(src + path[len(dst):]); break
PY
)
[ -n "$host" ] && model_file=$host
fi
fi
fi
fi
# Weight bytes as stored: a single file, the parts of a split GGUF
# (-00001-of-0000N.gguf), or the *.safetensors of a model directory.
model_bytes=""
if [ -f "$model_file" ]; then
case $model_file in
*-00001-of-[0-9]*.gguf) set -- "${model_file%-00001-of-*}"-[0-9]*-of-[0-9]*.gguf ;;
*) set -- "$model_file" ;;
esac
model_bytes=$(stat -c %s "$@" 2>/dev/null | awk '{s += $1} END {if (s) printf "%d", s}')
elif [ -d "$model_file" ]; then
model_bytes=$(find "$model_file" -maxdepth 1 -name '*.safetensors' -exec stat -c %s {} + 2>/dev/null |
awk '{s += $1} END {if (s) printf "%d", s}')
fi
[ -s "$tmp/cmd" ] || { [ -n "$cmd_file" ] && cp "$cmd_file" "$tmp/cmd" 2>/dev/null; }
# A docker server: the exact image, since tags like llama.cpp's server-intel
# move daily (the llama.cpp build itself is in engine_version).
container="" engine_image=""
[ -s "$tmp/cmd" ] && container=$(tr '\n' ' ' < "$tmp/cmd" |
sed -n 's/.*docker *\(run\|create\) .*--name[= ]\([^ ]*\).*/\2/p')
if [ -n "$container" ] && have docker &&
i=$(docker inspect -f '{{.Config.Image}}@{{.Image}}' "$container" 2>/dev/null); then
engine_image=$(printf '%s' "$i" | sed 's/@sha256:\(.\{12\}\).*/@\1/')
fi
# Measured memory bandwidth, the base for "% of peak". mem-bw.py copies random
# data with torch, inside the server's container (same GPU, env and torch), or
# with $BW_PYTHON. Fallback: clpeak, whose test data may compress on Arc and
# read high. A few seconds and 2 GiB of free VRAM; MEASURE_BW=0 skips it.
gpu_mem_bw_gbs="" gpu_mem_bw_tool=""
here=$(cd "$(dirname "$0")" && pwd)
if [ "${MEASURE_BW:-1}" != 0 ]; then
if [ -n "${BW_PYTHON:-}" ]; then
r=$(timeout 300 "$BW_PYTHON" "$here/mem-bw.py" 2>/dev/null)
elif [ -n "$engine_image" ]; then
r=$(timeout 300 docker exec -i "$container" python3 - < "$here/mem-bw.py" 2>/dev/null)
else
r=""
fi
if [ -n "$r" ]; then
gpu_mem_bw_gbs=${r% *} gpu_mem_bw_tool="torch copy, random, ${r#* } MiB"
elif have clpeak && [ -n "$gpu_model" ]; then
echo "collect-env: measuring memory bandwidth with clpeak (MEASURE_BW=0 skips) ..." >&2
timeout 300 clpeak --global-bandwidth > "$tmp/clpeak" 2>/dev/null
# Pick the device whose name holds the detected model; take the best width.
gpu_mem_bw_gbs=$(awk -v want="$gpu_model" '
/^ *Device:/ { sub(/^ *Device: */, ""); gsub(/\([RT]M*\)/, ""); gsub(/ +/, " "); dev = $0; next }
/Global memory bandwidth/ { inbw = index(dev, want) > 0; next }
inbw && /^ *float[0-9]* *:/ { v = $NF + 0; if (v > best) best = v; next }
inbw && !/^ *float/ { inbw = 0 }
END { if (best > 0) printf "%.0f", best }' "$tmp/clpeak")
[ -n "$gpu_mem_bw_gbs" ] && gpu_mem_bw_tool=clpeak
fi
fi
kv gpu_vendor "$gpu_vendor"
kv gpu_model "$gpu_model"
kv gpu_count "$gpu_count"
kv gpu_vram_gb "$gpu_vram_gb"
kv gpu_driver "$gpu_driver"
kv gpu_power_limit_w "$gpu_power_limit_w"
kv gpu_bdf "$gpu_bdf"
kv pcie_link "$pcie_link"
kv pcie_max "$pcie_max"
kv gpu_bar_mib "$gpu_bar_mib"
kv rebar "$rebar"
kv gpu_mem_bw_gbs "$gpu_mem_bw_gbs"
kv gpu_mem_bw_tool "$gpu_mem_bw_tool"
kv cpu_model "$cpu_model"
kv ram_gb "$ram_gb"
kv os "$os"
kv kernel "$kernel"
kv virt "$virt"
kv proxy "$proxy"
kv engine "$engine"
kv engine_version "$engine_version"
kv engine_slots "$engine_slots"
kv engine_image "$engine_image"
kv model_file "$model_file"
kv model_bytes "$model_bytes"
kv ctx "$ctx"
exit 0
__BENCH_STANDARD_EOF__
cat > "$d/gpu-power.sh" <<'__BENCH_STANDARD_EOF__'
#!/bin/sh
# gpu-power.sh - run ON THE INFERENCE SERVER. Samples the power draw and the
# energy counter and the core clock of all GPUs until killed, one CSV line
# per sample:
# epoch_s,watts,joules,mhz
# watts is the sum over all GPUs; joules is the sum of the cards' cumulative
# energy counters (empty where the card has none, then integrate the watts);
# mhz is the mean graphics clock over the GPUs.
# Prints nothing at all when no supported tool is found (nvidia-smi, xpu-smi).
#
# usage: gpu-power.sh [INTERVAL_S] (default 2)
set -u
LC_ALL=C; export LC_ALL
interval=${1:-2}
if command -v nvidia-smi >/dev/null 2>&1 &&
nvidia-smi --query-gpu=power.draw --format=csv,noheader >/dev/null 2>&1; then
# total_energy_consumption is in mJ since the driver loaded
sample() {
nvidia-smi --query-gpu=power.draw,total_energy_consumption,clocks.gr \
--format=csv,noheader,nounits 2>/dev/null |
awk -F', *' '{w += $1; if ($2 + 0 > 0) j += $2 / 1000; else nj = 1; c += $3}
END {if (NR) printf "%.2f,%s,%.0f\n", w, nj ? "" : sprintf("%.3f", j), c / NR}'
}
elif command -v xpu-smi >/dev/null 2>&1; then
# one call takes about a second
sample() {
xpu-smi dump --device -1 --metrics power.draw,energy.consumed,clocks.current.graphics \
--number 1 2>/dev/null |
awk -F', *' 'NR > 1 && $3 + 0 > 0 {w += $3; n++; if ($4 + 0 > 0) j += $4; else nj = 1; c += $5}
END {if (n) printf "%.2f,%s,%.0f\n", w, nj ? "" : sprintf("%.3f", j), c / n}'
}
else
exit 0
fi
while :; do
t=$(date +%s.%N)
s=$(sample)
[ -n "$s" ] && printf '%s,%s\n' "$t" "$s"
sleep "$interval"
done
__BENCH_STANDARD_EOF__
cat > "$d/mem-bw.py" <<'__BENCH_STANDARD_EOF__'
"""mem-bw.py - measured GPU memory bandwidth with torch, printed as "GBPS MIB".
Copies a buffer of random floats 20 times and counts read + write. Random
data on purpose: Arc compresses uniform buffers, so a zero-filled test reads
far too high (1227 GB/s with zeros vs 533 GB/s real on a B70). Best of three
rounds. Tries 1 GiB, then smaller buffers when the inference server has taken
most of the VRAM. Prints nothing when there is no usable GPU.
Runs with any python that has torch for the GPU: collect-env.sh runs it inside
the server's own container (docker exec), or with $BW_PYTHON.
"""
import sys
import time
import torch
if hasattr(torch, "xpu") and torch.xpu.is_available():
dev, sync = "xpu", torch.xpu.synchronize
elif torch.cuda.is_available(): # NVIDIA, and AMD through ROCm
dev, sync = "cuda", torch.cuda.synchronize
else:
sys.exit(0)
for mib in (1024, 512, 256):
try:
x = torch.rand(mib * 2**20 // 4, device=dev)
y = torch.empty_like(x)
break
except RuntimeError: # out of memory
continue
else:
sys.exit(0)
y.copy_(x)
sync()
best = 0.0
for _ in range(3):
t = time.perf_counter()
for _ in range(20):
y.copy_(x)
sync()
best = max(best, 20 * 2 * x.numel() * 4 / (time.perf_counter() - t) / 1e9)
print(f"{best:.0f} {mib}")
__BENCH_STANDARD_EOF__
cat > "$d/config.json" <<'__BENCH_STANDARD_EOF__'
{
"temperature": 0.7,
"top_p": 0.95,
"top_k": 20,
"greedy": false,
"warmup": 3,
"runs_per_category": 20,
"unique_nonce": true,
"run_concurrency": true,
"concurrency_levels": [1, 2, 4, 8],
"concurrency_requests": 48,
"weights": {
"code": 0.30, "reasoning": 0.20, "prose": 0.15,
"json": 0.15, "file_edit": 0.10, "summarization": 0.10
},
"conf": 0.95,
"target_mde_pct": 1.0,
"ab_max_pairs": 200,
"ab_min_pairs": 12,
"timeout_s": 600.0
}
__BENCH_STANDARD_EOF__
cat > "$d/standard.env" <<'__BENCH_STANDARD_EOF__'
# Pins for this version of the group standard. Bump STANDARD_VERSION whenever
# config.json, the minimum BetterBench or the mandatory fields change.
STANDARD_VERSION=0.4.0
# Oldest BetterBench that has everything bench.sh uses; newer ones run too,
# and the version goes into the run note so compare shows a mismatch.
BETTERBENCH_MIN_VERSION=0.6.1
__BENCH_STANDARD_EOF__
sh "$d/bench.sh" "$@"