From 6cb02ecc0af6cf97c3cc1435302d270f1fc18612 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 1 Nov 2026 20:41:55 +0000 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01EooZ9aTJE7srSQEYUqdQio --- AGENTS.md | 9 +++++ README.md | 28 +++++++++++-- bench.sh | 108 +++++++++++++++++++++++++++++++++++++++++++++++---- dev/bench.sh | 108 +++++++++++++++++++++++++++++++++++++++++++++++---- dev/test.sh | 40 +++++++++++++++++++ 5 files changed, 274 insertions(+), 19 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index ad4a32b..511ee10 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -62,6 +62,10 @@ Before I start, a few questions. Answer by number; "find it" is fine for any of 10. May I install BetterBench if it's missing? [yes; I'll ask before upgrading one] ``` +If `bench.local.env` exists next to `bench.sh` (your human saved values with +`./bench.sh init`), read it first and put its values in as the defaults. It never holds +the API key, so it's safe to read. Still ask every question; a saved value can be stale. + What the answers mean: - **2 = no:** BetterBench runs elsewhere. Use `--env-file` ([below](#when-something-goes-wrong)). - **4 = yes:** wait until they say it's set. Check with `[ -n "$BETTERBENCH_API_KEY" ]`, @@ -161,6 +165,11 @@ Every `bench.sh: warning:` needs fixing or an explanation before the real run. F `--X A but the launch command sets ...: declare --X B`, don't just switch to B: show it here and let your human decide. Rerun the dry run after any change. +Once the values are confirmed, offer to save them, so the next run needs no typing: +`./bench.sh init` writes `bench.local.env` (it refuses to overwrite one), then fill in +the confirmed values. Ask before changing an existing file. After that the run is +just `./bench.sh` plus `--dry-run` or `--full`. + ### 7. Quick run Run the same command without `--dry-run`. This is a quick check of a few minutes, diff --git a/README.md b/README.md index ea13dee..0ca2ea7 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,28 @@ process: ps -o args= -p "$(pgrep -f 'llama-server|vllm' | head -n1)" > server-cmd.txt ``` +### Save your values + +So you don't fill these in every time, save them once: + +```sh +./bench.sh init # writes bench.local.env next to bench.sh, every value explained +nano bench.local.env # fill in the empty ones +./bench.sh --dry-run # then just this; --full for the run that counts +``` + +`bench.local.env` holds one `BENCH_...=value` per line (`BENCH_SUBMITTER`, +`BENCH_ENDPOINT`, `BENCH_MODEL`, `BENCH_SERVER_CMD_FILE`, `BENCH_QUANT`, `BENCH_KV`, +`BENCH_TP`, `BENCH_PP`, `BENCH_SPEC`, `BENCH_THINKING`, and optional ones like +`BENCH_POWER_LIMIT`). It's read as plain values, never run as a script. Relative paths +in it are relative to the file. A flag on the command line wins over an environment +variable, which wins over the file. Every run prints which values came from the file. +For a second server or model, keep a second file and pass `--settings other.env`. +The API key never goes in it: `bench.sh` refuses `BETTERBENCH_API_KEY` there. Export +it in your shell. + +### The run + Without `--full`, that's a **quick check** of a few minutes. If the summary at the end looks right, run the same command with `--full`. That's the result that counts. It takes much longer and keeps the GPU busy the whole time. @@ -163,9 +185,9 @@ llama-swap you can leave it out, because the command is read automatically. | `--no-concurrency` | skip the concurrency sweep | | `--results-dir DIR` | where run folders go (default `results/` next to `bench.sh`) | -The declared values can also come from the environment (`BENCH_SUBMITTER=pascal`, -`BENCH_QUANT=...`, ...). Machine-local defaults like these go in a `bench.local.env` -file next to `bench.sh`. +| `--settings FILE` | read saved values from FILE instead of `bench.local.env` | + +Every value can also be saved, see [Save your values](#save-your-values). ## What a run does diff --git a/bench.sh b/bench.sh index 5138bba..c55a6a8 100755 --- a/bench.sh +++ b/bench.sh @@ -43,16 +43,22 @@ cat > "$d/bench.sh" <<'__BENCH_STANDARD_EOF__' # --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// folder. Only --full runs count. # The standard models and their hashes: README.md. For agents: AGENTS.md. @@ -63,8 +69,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}"; } @@ -96,13 +100,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:-} @@ -118,6 +208,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 ;; @@ -156,7 +247,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" diff --git a/dev/bench.sh b/dev/bench.sh index 3622215..98ffde8 100755 --- a/dev/bench.sh +++ b/dev/bench.sh @@ -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// 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" diff --git a/dev/test.sh b/dev/test.sh index a45a946..e879ed4 100644 --- a/dev/test.sh +++ b/dev/test.sh @@ -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"