#!/usr/bin/env bash # Run the unmodified Original (`strata generate --serve`) on the laptop-profile prompts and record its timings, # outputs and memory (docs/laptop-profile.md). # original_bench.sh LABEL [extra engine args...] # Environment: STRATA (engine binary), MODEL_DIR (the two GGUF shards), PACK (data/iq3_s), MTP (data/mtp-rt), # PROFILE (expert-profile.bin), PROMPTS (one comma-separated token-ID line per prompt), OUT (results dir), # MAX_NEW (128), REPEAT (2), MAX_CONTEXT (8192). # The default arguments are setup.py's for IQ3_S (`--expert-cache auto --prefill auto --spec 4 --spec-min-p 0.5 # --mtp`, `--kv int8`), with the conversation cache off so repeats read the whole prompt again (the port's stack # has it off by default too). The low-RAM mode (`--resident-experts`, `--mmap-experts`, ...) is passed as extra args. # Requests are sent one at a time; TTFT is measured here from sending `GEN` to the first `T` line. set -uo pipefail label="$1"; shift here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" : "${STRATA:?}" "${MODEL_DIR:?}" "${PACK:?}" "${MTP:?}" "${PROFILE:?}" "${PROMPTS:?}" "${OUT:?}" MAX_NEW="${MAX_NEW:-128}"; REPEAT="${REPEAT:-2}"; MAX_CONTEXT="${MAX_CONTEXT:-8192}" mkdir -p "$OUT" shard1="$MODEL_DIR/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00001-of-00002.gguf" shard2="$MODEL_DIR/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00002-of-00002.gguf" args=(--serve --pack "$PACK" --native "$shard1" --ple-gguf "$shard2" --expert-profile "$PROFILE" --expert-cache auto --prefill auto --spec 4 --spec-min-p 0.5 --mtp "$MTP" --max-context "$MAX_CONTEXT" --kv int8 --prompt-cache 0 "$@") echo "strata ${args[*]}" > "$OUT/$label.cmd" mapfile -t prompts < <(grep -v '^[[:space:]]*$' "$PROMPTS") t_start=$EPOCHREALTIME coproc ENGINE { exec "$STRATA" "${args[@]}" 2> "$OUT/$label.stderr"; } pid=$ENGINE_PID bash "$here/monitor.sh" "$pid" "$OUT/$label.mem.tsv" > "$OUT/$label.mem.peak" & mon=$! : > "$OUT/$label.stdout" ready="" while IFS= read -r line <&"${ENGINE[0]}"; do echo "$line" >> "$OUT/$label.stdout" if [[ "$line" == READY* ]]; then ready=1; break; fi done if [[ -z "$ready" ]]; then echo "engine did not become ready"; tail -20 "$OUT/$label.stderr"; exit 1; fi echo "load_s=$(echo "$EPOCHREALTIME - $t_start" | bc)" > "$OUT/$label.timing" for ((pass = 0; pass < REPEAT; pass++)); do for i in "${!prompts[@]}"; do t0=$EPOCHREALTIME; first=""; toks=() echo "GEN $MAX_NEW ${prompts[$i]}" >&"${ENGINE[1]}" while IFS= read -r line <&"${ENGINE[0]}"; do echo "$line" >> "$OUT/$label.stdout" case "$line" in T\ *) [[ -z "$first" ]] && first=$EPOCHREALTIME; toks+=("${line#T }") ;; DONE*) break ;; ERR*) echo "p$((i + 1)) pass=$pass: $line"; break ;; esac done t1=$EPOCHREALTIME ttft=$(echo "(${first:-$t1} - $t0) * 1000" | bc) total=$(echo "($t1 - $t0) * 1000" | bc) # DONE produced prompt prompt_ms decode_ms finish accepted offered resume hits look ram_reads file_reads file_MB read -r _ produced n prompt_ms decode_ms finish acc off resume hits look ram files fmb <<< "$line" printf 'p%d pass=%d prompt=%s produced=%s ttft_ms=%.1f prompt_ms=%s decode_ms=%s total_ms=%.1f prefill_tok_s=%.1f decode_tok_s=%.2f accept=%s/%s hits=%s/%s ram=%s files=%s file_MB=%s finish=%s\n' \ $((i + 1)) "$pass" "$n" "$produced" "$ttft" "$prompt_ms" "$decode_ms" "$total" \ "$(echo "$n * 1000 / $prompt_ms" | bc -l)" "$(echo "$produced * 1000 / $decode_ms" | bc -l)" \ "$acc" "$off" "$hits" "$look" "$ram" "$files" "$fmb" "$finish" | tee -a "$OUT/$label.timing" if [[ $pass -eq 0 ]]; then (IFS=,; echo "output p$((i + 1)): ${toks[*]}") >> "$OUT/$label.outputs" fi done done echo QUIT >&"${ENGINE[1]}" wait "$pid"; rc=$? wait "$mon" || true echo "exit=$rc" >> "$OUT/$label.mem.peak" cat "$OUT/$label.mem.peak"