Save values in bench.local.env: bench.sh init writes a template
./bench.sh init writes a commented bench.local.env next to bench.sh; fill it in once and the run is just ./bench.sh (--dry-run, --full). New saved keys: BENCH_ENDPOINT, BENCH_MODEL, BENCH_SERVER_CMD_FILE, BENCH_ENV_FILE. --settings FILE picks another file (a second server or model). The file is now read as KEY=value data instead of being sourced: no code in it runs, the environment wins over it (flags > environment > file), relative paths are relative to the file, and BETTERBENCH_API_KEY in it is refused. Each run says which values came from the file. A missing value's error points to the file and to init. AGENTS.md: read the file for round 1 defaults, offer to save the confirmed values after round 2. 11 new tests (47 in all). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EooZ9aTJE7srSQEYUqdQio
This commit is contained in:
5 files changed
+274
-19
No files matched your search
+100
-8
@@ -33,16 +33,22 @@
|
||||
# --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
|
||||
# --settings FILE your saved values (default: bench.local.env next to
|
||||
# bench.sh, if it exists)
|
||||
#
|
||||
# Other commands:
|
||||
# bench.sh init [FILE] write a settings file to fill in once, so you
|
||||
# don't type the values every time
|
||||
# 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.
|
||||
# Saved values: bench.local.env (see 'bench.sh init') or the environment, as
|
||||
# BENCH_SUBMITTER, BENCH_ENDPOINT, BENCH_MODEL, BENCH_SERVER_CMD_FILE,
|
||||
# BENCH_TP, BENCH_PP, BENCH_QUANT, BENCH_KV, BENCH_SPEC, BENCH_THINKING,
|
||||
# BENCH_POWER_LIMIT, BENCH_PCIE, BENCH_MEM_BW, BENCH_SPECIAL_NOTES,
|
||||
# BENCH_RESULTS_DIR, BENCH_ENV_FILE. Flags win over the environment, which
|
||||
# wins over the file.
|
||||
# Send the whole results/<run>/ folder. Only --full runs count.
|
||||
# The standard models and their hashes: README.md. For agents: AGENTS.md.
|
||||
|
||||
@@ -53,8 +59,6 @@ umask 002
|
||||
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 "$home/bench.local.env" ] && . "$home/bench.local.env"
|
||||
|
||||
die() { echo "bench.sh: $*" >&2; exit 1; }
|
||||
usage() { sed -n '2,/^$/p' "$0" | sed -e 's/^# \{0,1\}//' -e '$d'; exit "${1:-0}"; }
|
||||
@@ -86,13 +90,99 @@ trap 'on_signal 143' TERM
|
||||
# bg CMD...: run CMD in the background, wait for it; its status in $rc.
|
||||
bg() { "$@" & child=$!; rc=0; wait "$child" || rc=$?; child=""; }
|
||||
|
||||
# The settings file people fill in once (bench.sh init writes it).
|
||||
settings_template() {
|
||||
cat <<'EOF'
|
||||
# bench.local.env - your values for ./bench.sh, so you don't type them every
|
||||
# time. Fill in what's empty, then run just: ./bench.sh (or --dry-run, --full)
|
||||
#
|
||||
# One KEY=value per line; '#' starts a comment; quote values with spaces.
|
||||
# Relative paths are relative to this file. Flags on the command line win over
|
||||
# the environment, which wins over this file. Never put the API key here:
|
||||
# export BETTERBENCH_API_KEY in your shell instead.
|
||||
|
||||
# --- you and your server -------------------------------------------------
|
||||
BENCH_SUBMITTER= # your name
|
||||
BENCH_ENDPOINT=http://localhost:8080/v1 # the server's base URL, ending in /v1
|
||||
BENCH_MODEL= # the id exactly as /v1/models lists it
|
||||
BENCH_SERVER_CMD_FILE= # file with the server's launch command,
|
||||
# e.g. server-cmd.txt; empty behind llama-swap
|
||||
|
||||
# --- what you declare (README: "What you declare") -----------------------
|
||||
BENCH_QUANT= # from the model table: Q4_K_M, UD-Q4_K_M or w4a16
|
||||
BENCH_KV=f16 # f16, q8_0, q8_0/f16 (K/V differ), bf16, fp8
|
||||
BENCH_TP=1 # tensor parallel size
|
||||
BENCH_PP=1 # pipeline parallel size
|
||||
BENCH_SPEC=none # none, mtp:5, eagle3:4, ngram:4, draft:8
|
||||
BENCH_THINKING=default # set on the server: default, off, on, low, medium, high
|
||||
|
||||
# --- only when needed ----------------------------------------------------
|
||||
# BENCH_POWER_LIMIT=250 # when the GPU can't report it, or: stock
|
||||
# BENCH_PCIE="Gen4 x16" # inside a VM
|
||||
# BENCH_MEM_BW=608 # the card's spec memory bandwidth, GB/s
|
||||
# BENCH_SPECIAL_NOTES="undervolted" # anything unusual
|
||||
# BENCH_RESULTS_DIR=results # where run folders go
|
||||
# WARM_TIMEOUT=1800 # a slow first model load behind llama-swap
|
||||
EOF
|
||||
}
|
||||
|
||||
# load_settings FILE - set each KEY=value the environment doesn't set already.
|
||||
# Read as data, not run as shell code.
|
||||
loaded=""
|
||||
load_settings() {
|
||||
sdir=$(cd "$(dirname "$1")" && pwd) n=0
|
||||
while IFS= read -r line || [ -n "$line" ]; do
|
||||
n=$((n + 1))
|
||||
line=${line#"${line%%[![:space:]]*}"}
|
||||
case $line in ''|'#'*) continue ;; esac
|
||||
line=${line#export }
|
||||
case $line in *=*) ;; *) die "$1 line $n: want KEY=value" ;; esac
|
||||
key=${line%%=*} val=${line#*=}
|
||||
case $key in ''|[0-9]*|*[!A-Z0-9_]*) die "$1 line $n: '$key' is not a variable name" ;; esac
|
||||
[ "$key" != BETTERBENCH_API_KEY ] ||
|
||||
die "$1 line $n: keep the API key out of files; export BETTERBENCH_API_KEY in your shell"
|
||||
case $val in
|
||||
\"*) val=${val#\"}; case $val in *\"*) val=${val%%\"*} ;; *) die "$1 line $n: missing closing quote" ;; esac ;;
|
||||
\'*) val=${val#\'}; case $val in *\'*) val=${val%%\'*} ;; *) die "$1 line $n: missing closing quote" ;; esac ;;
|
||||
*) val=${val%%[[:space:]]#*}; val=${val%"${val##*[![:space:]]}"} ;;
|
||||
esac
|
||||
# shellcheck disable=SC2088 # a literal ~/ in the file, expanded here
|
||||
case $val in '~/'*) val=$HOME/${val#'~/'} ;; '$HOME/'*) val=$HOME/${val#'$HOME/'} ;; esac
|
||||
case $key in *_FILE|*_DIR) case $val in /*|'') ;; *) val=$sdir/$val ;; esac ;; esac
|
||||
eval "isset=\${$key+y}"
|
||||
if [ -z "$isset" ]; then
|
||||
eval "$key=\$val"; export "${key?}"
|
||||
[ -z "$val" ] || loaded="$loaded $key"
|
||||
fi
|
||||
done < "$1"
|
||||
}
|
||||
|
||||
case "${1:-}" in
|
||||
init)
|
||||
out=${2:-$home/bench.local.env}
|
||||
[ ! -e "$out" ] || die "$out exists; edit it, or remove it first"
|
||||
settings_template > "$out" || die "cannot write $out"
|
||||
echo "wrote $out - fill in the empty values, then run ./bench.sh --dry-run"
|
||||
exit 0 ;;
|
||||
collect-env) shift; rc=0; sh "$here/collect-env.sh" "$@" || rc=$?; exit "$rc" ;;
|
||||
power) shift; bg sh "$here/gpu-power.sh" "$@"; exit "$rc" ;;
|
||||
--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
|
||||
# --settings is read before the other flags, so that they win over it.
|
||||
settings="" prev=""
|
||||
for a; do [ "$prev" = --settings ] && settings=$a; prev=$a; done
|
||||
if [ -n "$settings" ]; then
|
||||
[ -f "$settings" ] && [ -r "$settings" ] || die "cannot read settings file $settings"
|
||||
load_settings "$settings"
|
||||
elif [ -f "$home/bench.local.env" ]; then
|
||||
settings=$home/bench.local.env
|
||||
load_settings "$settings"
|
||||
fi
|
||||
[ -z "$loaded" ] || echo "settings from $settings:$loaded" >&2
|
||||
|
||||
endpoint=${BENCH_ENDPOINT:-} model=${BENCH_MODEL:-} server_cmd_file=${BENCH_SERVER_CMD_FILE:-}
|
||||
env_file=${BENCH_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:-}
|
||||
@@ -108,6 +198,7 @@ while [ $# -gt 0 ]; do
|
||||
--server-cmd-file) need $# "$1"; server_cmd_file=$2; shift 2 ;;
|
||||
--env-file) need $# "$1"; env_file=$2; shift 2 ;;
|
||||
--results-dir) need $# "$1"; results_dir=$2; shift 2 ;;
|
||||
--settings) need $# "$1"; shift 2 ;;
|
||||
--tp) need $# "$1"; tp=$2; shift 2 ;;
|
||||
--pp) need $# "$1"; pp=$2; shift 2 ;;
|
||||
--quant) need $# "$1"; quant=$2; shift 2 ;;
|
||||
@@ -146,7 +237,8 @@ for f in endpoint model tp pp quant kv spec thinking submitter; do
|
||||
eval "v=\${$f}"
|
||||
[ -n "$v" ] || missing="$missing --$(printf '%s' "$f" | tr _ -)"
|
||||
done
|
||||
[ -z "$missing" ] || die "missing mandatory value(s):$missing"
|
||||
[ -z "$missing" ] || die "missing mandatory value(s):$missing" \
|
||||
"(as flags, or saved in ${settings:-bench.local.env}; './bench.sh init' writes one to fill in)"
|
||||
|
||||
matches "$tp" '[1-9][0-9]*' || die "--tp must be a positive integer"
|
||||
matches "$pp" '[1-9][0-9]*' || die "--pp must be a positive integer"
|
||||
|
||||
+40
@@ -138,6 +138,46 @@ check "interrupted run folder marked, no done:" 'ls -d "$t"/res2/*.interrupted >
|
||||
check "no betterbench left running" '! pgrep -f "FAKE_BB_SLEEP|dev/test/betterbench run" >/dev/null 2>&1'
|
||||
check "helpers cleaned up after a signal" '[ -z "$(ls -A "$t/tmpdir")" ]'
|
||||
|
||||
# ------------------------------------------------------------------ the settings file
|
||||
# plain bench.sh (no declared values on the command line) with BENCH_HOME=$t/home
|
||||
plain() { TMPDIR="$t/tmpdir" sh "$root/bench.sh" "$@" > "$t/out" 2>&1; }
|
||||
plain init; rc=$?
|
||||
check "init writes bench.local.env next to bench.sh" '[ $rc = 0 ] && grep -q "^BENCH_SUBMITTER=" "$t/home/bench.local.env"'
|
||||
plain init; rc=$?
|
||||
check "init doesn't overwrite" '[ $rc = 1 ] && grep -q "exists" "$t/out"'
|
||||
plain --dry-run
|
||||
check "an unfilled file names what's missing and how to save it" 'grep -q "missing mandatory value(s): --model --quant --submitter" "$t/out" && grep -q "bench.sh init" "$t/out"'
|
||||
s="$t/home/bench.local.env"
|
||||
sed -e "s|^BENCH_SUBMITTER=.*|BENCH_SUBMITTER=filer # me|" \
|
||||
-e "s|^BENCH_ENDPOINT=.*|BENCH_ENDPOINT=$LL|" -e "s|^BENCH_MODEL=.*|BENCH_MODEL=test-model|" \
|
||||
-e "s|^BENCH_SERVER_CMD_FILE=.*|BENCH_SERVER_CMD_FILE=cmd.txt|" -e "s|^BENCH_QUANT=.*|BENCH_QUANT=Q4_K_M|" \
|
||||
-e 's|^# BENCH_POWER_LIMIT=250 .*|export BENCH_POWER_LIMIT=200|' \
|
||||
-e 's|^# BENCH_SPECIAL_NOTES=.*|BENCH_SPECIAL_NOTES="two words # not a comment" # a comment|' \
|
||||
-e 's|^# BENCH_RESULTS_DIR=.*|BENCH_RESULTS_DIR=res|' "$s" > "$s.new" && mv "$s.new" "$s"
|
||||
printf 'llama-server -m /m.gguf -ngl 99\n' > "$t/home/cmd.txt"
|
||||
(cd / && TMPDIR="$t/tmpdir" sh "$root/bench.sh" --dry-run > "$t/out" 2>&1); rc=$?
|
||||
python3 - "$t/out" > "$t/notes" <<'PY'
|
||||
import shlex, sys
|
||||
line = next((l for l in open(sys.argv[1]) if l.startswith(" betterbench")), "")
|
||||
w = shlex.split(line)
|
||||
print("\n".join(w[i + 1] for i, x in enumerate(w) if x == "--note"))
|
||||
PY
|
||||
check "a filled file runs with no flags at all" '[ $rc = 0 ] && grep -q "settings from .*bench.local.env: BENCH_SUBMITTER" "$t/out"'
|
||||
check "file: comments stripped, quotes kept, export accepted" '[ "$(note submitter)" = filer ] && [ "$(note special_notes)" = "two words # not a comment" ] && note power_limit | grep -q "^200 W"'
|
||||
check "file: relative paths are relative to the file" 'note launch | grep -q "ngl 99" && grep -q "would write $t/home/res/" "$t/out"'
|
||||
plain --dry-run --kv q8_0
|
||||
check "a flag wins over the file" 'grep -q "weights Q4_K_M · kv q8_0" "$t/out"'
|
||||
BENCH_SUBMITTER=envname plain --dry-run
|
||||
check "the environment wins over the file" 'grep -q "submitter=envname" "$t/out"'
|
||||
sed 's|^BENCH_SUBMITTER=.*|BENCH_SUBMITTER=other|' "$s" > "$t/home/other.env"
|
||||
plain --settings "$t/home/other.env" --dry-run
|
||||
check "--settings picks another file" 'grep -q "submitter=other" "$t/out"'
|
||||
printf 'BETTERBENCH_API_KEY=sk-x\n' > "$t/key.env"; plain --settings "$t/key.env" --dry-run; rc=$?
|
||||
check "an API key in the file is refused" '[ $rc = 1 ] && grep -q "keep the API key out of files" "$t/out"'
|
||||
printf 'BENCH_KV=$(touch %s/pwned)\n' "$t" > "$t/code.env"; plain --settings "$t/code.env" --dry-run
|
||||
check "the file is data, never run" '[ ! -e "$t/pwned" ]'
|
||||
rm -f "$s"
|
||||
|
||||
# ------------------------------------------------------------------ power sampling
|
||||
f="$t/sys/bus/pci/drivers/amdgpu/0000:03:00.0/hwmon/hwmon1"; mkdir -p "$f"
|
||||
echo 150000000 > "$f/power1_input"; echo 2100000000 > "$f/freq1_input"
|
||||
|
||||
Reference in new issue
Block a user