#!/bin/zsh # End-to-end KV-cache quantization benchmark. No network needed; models must already be # in the local Hugging Face cache. Target wall time: <= 40 min on a 64 GB M3 Max. # Before running: close other apps, plug in the charger, enable High Power mode. set -u cd "${0:A:h}" PY=/opt/homebrew/Caskroom/miniconda/base/bin/python export HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 TOKENIZERS_PARALLELISM=false PYTHONUNBUFFERED=1 START=$(date +%s) DEADLINE=$(( START + 36 * 60 )) # bench starts no new run after this; leaves time to aggregate if [[ -d results ]]; then mv results "results.prev.$(date +%Y%m%d-%H%M%S)" fi mkdir -p results data echo "== power: $(pmset -g batt | head -1)" pmset -g | grep -iE "powermode|lowpowermode" || true echo "== 1/3 building haystacks (seeded, tokenizer-counted)" $PY haystack.py 2>&1 | tee results/haystack.log || { echo "haystack generation failed"; exit 1; } echo "== 2/3 benchmark (deadline $(date -r $DEADLINE +%H:%M:%S))" caffeinate -dimsu $PY bench.py --deadline $DEADLINE 2>&1 | tee results/bench.log BENCH_RC=${pipestatus[1]} echo "== 3/3 aggregating" $PY aggregate.py 2>&1 | tee results/aggregate.log echo "== done in $(( $(date +%s) - START )) s (bench exit code $BENCH_RC); see results.json" exit $BENCH_RC