Files
benchmarks/dev/gpu-power.sh
T
Claude b36805d1cb bench-standard 0.5.0: fix silent exits and signals, check declared values, hash the model
Fixes:
- A run on a machine without nvidia-smi/xpu-smi (every AMD box) exited
  silently with status 1 after BetterBench: the power sampler had already
  exited, so `kill` failed under set -e. No summary, no post_run, no done.
- Ctrl-C or kill didn't stop the script: the INT/TERM traps cleaned up and
  carried on, so a partial run could print a summary and `done:`. Now
  BetterBench is stopped at once and the folder is renamed .interrupted. The
  one-file bench.sh exec's the real script, so kill PID reaches it.
- Redaction turned --max-num-batched-tokens=8192 into <redacted>, corrupting
  the launch note. Env-style secrets and user:pass@ in URLs are still redacted.
- The --kv check was inverted when only -ctk is set: it warned on the
  correct q8_0/f16 and accepted q8_0.
- Negative flag values (-t -1) were parsed as flags.
- Model sizes in the HF cache counted symlinks, not the weights.
- A failed greedy check was recorded without any message.

Improvements:
- The served model is hashed (cached) and checked against the README's table
  (dev/models.txt), with a --quant cross-check.
- --spec, --thinking and vLLM --tp/--pp are checked against the launch
  command, like --kv; warnings name the value to declare.
- Weights are found through docker -v/--mount for any launch command, not
  only llama-swap's, and vLLM repo ids through the HF cache.
- AMD power and clock are sampled from amdgpu's hwmon sysfs files.
- Warnings are repeated after the summary and in the dry run, and saved in
  meta.json; the summary is saved as summary.txt.
- dev/test.sh: 36 end-to-end tests with a fake server and fake BetterBench,
  no GPU; CI runs them under dash and bash, plus shellcheck and build --check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EooZ9aTJE7srSQEYUqdQio
2026-11-01 20:05:40 +00:00

60 lines
2.4 KiB
Bash
Executable File

#!/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,
# or amdgpu's hwmon files in sysfs, which have no energy counter).
#
# usage: gpu-power.sh [INTERVAL_S] (default 2)
# GPU_POWER_SYSFS=DIR: the sysfs root for the amdgpu lookup (tests)
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
# amdgpu: power1_average (older kernels) or power1_input, in microwatts;
# freq1_input is the graphics clock in Hz.
amd=""
for h in "${GPU_POWER_SYSFS:-/sys}"/bus/pci/drivers/amdgpu/*:*/hwmon/hwmon*; do
{ [ -r "$h/power1_average" ] || [ -r "$h/power1_input" ]; } && amd="$amd $h"
done
[ -n "$amd" ] || exit 0
sample() {
for h in $amd; do
p=$(cat "$h/power1_average" 2>/dev/null || cat "$h/power1_input" 2>/dev/null)
f=$(cat "$h/freq1_input" 2>/dev/null)
echo "${p:-0} ${f:-0}"
done | awk '$1 > 0 {w += $1 / 1e6; c += $2 / 1e6; n++}
END {if (n) printf "%.2f,,%.0f\n", w, c / n}'
}
fi
while :; do
t=$(date +%s.%N)
s=$(sample)
[ -n "$s" ] && printf '%s,%s\n' "$t" "$s"
sleep "$interval"
done