#!/usr/bin/env bash # Sweep llama-bench across thread counts on this machine to pick the best # --threads for a given Gemma 4 GGUF. Results saved under scripts/bench-results/. # # ./bench.sh /models/gemma-4-E4B-it-Q4_K_M.gguf # THREADS_LIST="2 4 8" ./bench.sh # # Requires the GGUF present in ./models (pre-download with download-models.sh # --weights). Uses the prebuilt llama.cpp image (CPU). set -euo pipefail cd "$(dirname "$0")/.." MODEL="${1:?usage: bench.sh /models/.gguf (path is inside the container)}" THREADS_LIST="${THREADS_LIST:-1 2 4 8}" IMAGE="${LLAMA_IMAGE:-ghcr.io/ggml-org/llama.cpp:full}" OUT="scripts/bench-results"; mkdir -p "$OUT" STAMP="$(date +%Y%m%d-%H%M%S)" REPORT="$OUT/bench-$STAMP.md" echo "# llama-bench $(uname -n) $STAMP" | tee "$REPORT" echo "model: $MODEL" | tee -a "$REPORT" echo | tee -a "$REPORT" for t in $THREADS_LIST; do echo "## threads=$t" | tee -a "$REPORT" docker run --rm -v "$PWD/models:/models" "$IMAGE" \ llama-bench -m "$MODEL" -t "$t" -p 512 -n 128 2>/dev/null \ | tee -a "$REPORT" || echo " (run failed for t=$t)" | tee -a "$REPORT" echo | tee -a "$REPORT" done echo "Saved: $REPORT"