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| 1 |
+
#!/usr/bin/env bash
|
| 2 |
+
# =============================================================================
|
| 3 |
+
# run_peer_eval.sh -- NIAH on peer base checkpoints, scored identically to ours.
|
| 4 |
+
#
|
| 5 |
+
# WHAT THIS ANSWERS
|
| 6 |
+
# Our 1.06B scores 48% on niah_single at 16k. Every published comparison is
|
| 7 |
+
# either the wrong metric (RULER 13-task average, not single-NIAH), the wrong
|
| 8 |
+
# checkpoint type (instruct, not base), or the wrong size. Running the peers
|
| 9 |
+
# through OUR harness removes all three mismatches at once.
|
| 10 |
+
#
|
| 11 |
+
# MODELS (all BASE checkpoints)
|
| 12 |
+
# Qwen3-0.6B/1.7B/4B/8B-Base dense attention, native 32,768 ctx, no YaRN.
|
| 13 |
+
# The ladder gives a measured retrieval-vs-scale
|
| 14 |
+
# curve without training anything. Qwen3-1.7B is
|
| 15 |
+
# the closest peer to our 1.06B (1.41B non-emb
|
| 16 |
+
# vs our 0.906B); Qwen3-4B matches our 4B target.
|
| 17 |
+
# Spark-X2.5-4B-Base hybrid: 27 sliding-window(512) + 9 full-attention
|
| 18 |
+
# layers, claims NATIVE 1M context, publishes no
|
| 19 |
+
# NIAH/RULER number at all. custom_code, so vLLM
|
| 20 |
+
# cannot load it -- peer_run.py falls back to hf.
|
| 21 |
+
#
|
| 22 |
+
# FAIRNESS NOTES, all of which belong in any writeup
|
| 23 |
+
# * One shared haystack TEXT; each model cut to its own exact token count.
|
| 24 |
+
# * Qwen3/Spark run INSIDE their native windows at 16k. Ours is YaRN-extended
|
| 25 |
+
# from 4k and at 16k sits at the very edge. Not the same condition.
|
| 26 |
+
# * Peers use a KV cache; our CP_GENERATE re-runs a full forward per token.
|
| 27 |
+
# That is an engine difference, not a capability difference.
|
| 28 |
+
#
|
| 29 |
+
# usage: ./run_peer_eval.sh # all models, all lengths
|
| 30 |
+
# MODELS=qwen3-4b LENS=16384 ./run_peer_eval.sh
|
| 31 |
+
# =============================================================================
|
| 32 |
+
set -uo pipefail
|
| 33 |
+
cd "$(dirname "$0")"
|
| 34 |
+
|
| 35 |
+
PY=${PY:-python3}
|
| 36 |
+
ROOT=${ROOT:-$PWD/peer_out}
|
| 37 |
+
HAY=${HAY:-$ROOT/haystack.txt}
|
| 38 |
+
LENS=${LENS:-"1024 2048 4096 8192 16384"}
|
| 39 |
+
N=${N:-100}
|
| 40 |
+
TASKS=${TASKS:-"niah_single val_backward"}
|
| 41 |
+
MAX_NEW=${MAX_NEW:-24}
|
| 42 |
+
DEPTHS=${DEPTHS:-"0.0,0.25,0.5,0.75,1.0"}
|
| 43 |
+
GPUS=${GPUS:-"0 1 2 3 4 5 6 7"}
|
| 44 |
+
MODELS=${MODELS:-"qwen3-0.6b qwen3-1.7b qwen3-4b qwen3-8b spark-4b"}
|
| 45 |
+
|
| 46 |
+
# Spark-X2.5 needs transformers 4.57.x: modeling_spark.py targets 4.57 and breaks
|
| 47 |
+
# on 5.x twice over -- _tied_weights_keys became a mapping, and create_causal_mask
|
| 48 |
+
# lost its `input_embeds` kwarg. Rather than shim each API change, give it the
|
| 49 |
+
# version it was written for. Qwen3 stays on the vLLM venv.
|
| 50 |
+
PY_SPARK=${PY_SPARK:-/home/blubridge/venvs/tf457/bin/python}
|
| 51 |
+
declare -A PYFOR=( [spark-4b]="$PY_SPARK" )
|
| 52 |
+
|
| 53 |
+
declare -A REPO=(
|
| 54 |
+
[qwen3-0.6b]=Qwen/Qwen3-0.6B-Base
|
| 55 |
+
[qwen3-1.7b]=Qwen/Qwen3-1.7B-Base
|
| 56 |
+
[qwen3-4b]=Qwen/Qwen3-4B-Base
|
| 57 |
+
[qwen3-8b]=Qwen/Qwen3-8B-Base
|
| 58 |
+
[spark-4b]=XHToken/Spark-X2.5-4B-Base
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
mkdir -p "$ROOT"
|
| 62 |
+
M="$ROOT/master.log"
|
| 63 |
+
say(){ echo "[$(date -u +%H:%M:%S)] $*" | tee -a "$M" >&2; }
|
| 64 |
+
|
| 65 |
+
say "=== peer NIAH eval ==="
|
| 66 |
+
for m in $MODELS; do [ -n "${REPO[$m]:-}" ] || { say "unknown model key: $m"; exit 1; }; done
|
| 67 |
+
|
| 68 |
+
# ---- 1. one shared haystack ------------------------------------------------
|
| 69 |
+
if [ ! -s "$HAY" ]; then
|
| 70 |
+
say "building shared haystack"
|
| 71 |
+
$PY make_haystack.py --out "$HAY" --tokens 4000000 >>"$M" 2>&1 \
|
| 72 |
+
|| { say "FATAL: haystack build failed"; exit 1; }
|
| 73 |
+
fi
|
| 74 |
+
say "haystack $(stat -Lc%s "$HAY") bytes"
|
| 75 |
+
|
| 76 |
+
# ---- 2. prompts, per model (tokenizer differs) and per length --------------
|
| 77 |
+
for m in $MODELS; do
|
| 78 |
+
for L in $LENS; do
|
| 79 |
+
d="$ROOT/prompts/$m/$L"
|
| 80 |
+
# Must check EVERY task, not just the first: an interrupt between tasks would
|
| 81 |
+
# otherwise leave this dir looking complete and the generation step would fail
|
| 82 |
+
# on the missing prompts file.
|
| 83 |
+
have=1; for t in $TASKS; do [ -f "$d/${t}_meta.json" ] || have=0; done
|
| 84 |
+
[ "$have" = 1 ] && { say "prompts exist $m/$L"; continue; }
|
| 85 |
+
mkdir -p "$d"
|
| 86 |
+
for t in $TASKS; do
|
| 87 |
+
$PY peer_gen.py --tokenizer "${REPO[$m]}" --haystack "$HAY" --task "$t" \
|
| 88 |
+
--prompt-len "$L" --n "$N" --depths "$DEPTHS" --seed 0 --out-dir "$d" \
|
| 89 |
+
>>"$M" 2>&1 || { say "FATAL: prompt gen failed $m/$L/$t"; exit 1; }
|
| 90 |
+
done
|
| 91 |
+
say "prompts $m/$L"
|
| 92 |
+
done
|
| 93 |
+
done
|
| 94 |
+
|
| 95 |
+
# ---- 3. generate: a real work queue, not round-robin ----------------------
|
| 96 |
+
# The previous version picked the GPU by LAUNCH INDEX (i % NG). `wait -n` kept
|
| 97 |
+
# NG jobs in flight, but the card was chosen by counter rather than by which one
|
| 98 |
+
# was actually free -- and a 16,384-token job takes ~16x a 1,024-token one, so
|
| 99 |
+
# the counter desynchronised from real occupancy within seconds and left half
|
| 100 |
+
# the box idle. Now: one persistent worker per GPU, each pulling the next job
|
| 101 |
+
# from a shared cursor under flock, so a card is never idle while work remains.
|
| 102 |
+
#
|
| 103 |
+
# Jobs are ordered LONGEST FIRST (16384 -> 1024). Longest-processing-time-first
|
| 104 |
+
# is the standard greedy makespan heuristic; scheduling the big jobs last would
|
| 105 |
+
# end the run with one 16k job while seven GPUs sit idle.
|
| 106 |
+
JOBS="$ROOT/joblist.txt"; : > "$JOBS"
|
| 107 |
+
for L in $(echo $LENS | tr ' ' '\n' | sort -rn); do
|
| 108 |
+
for m in $MODELS; do
|
| 109 |
+
for t in $TASKS; do
|
| 110 |
+
out="$ROOT/gen/$L/${m}_${t}.jsonl"
|
| 111 |
+
# require the FULL row count: a job killed mid-write would otherwise look
|
| 112 |
+
# done to a `-s` test and silently truncate that cell.
|
| 113 |
+
if [ -f "$out" ] && [ "$(wc -l < "$out")" -eq "$N" ]; then continue; fi
|
| 114 |
+
mkdir -p "$(dirname "$out")"
|
| 115 |
+
echo "$m|$L|$t" >> "$JOBS"
|
| 116 |
+
done
|
| 117 |
+
done
|
| 118 |
+
done
|
| 119 |
+
NJOB=$(grep -c . "$JOBS" 2>/dev/null || echo 0)
|
| 120 |
+
say "queue: $NJOB job(s) to run on $(echo $GPUS | wc -w) GPU(s), longest first"
|
| 121 |
+
|
| 122 |
+
if [ "$NJOB" -gt 0 ]; then
|
| 123 |
+
CUR="$ROOT/.cursor"; echo 0 > "$CUR"
|
| 124 |
+
worker(){
|
| 125 |
+
local g="$1" idx line m L t
|
| 126 |
+
while :; do
|
| 127 |
+
idx=$(flock "$CUR" -c 'n=$(cat '"$CUR"'); echo $((n+1)) > '"$CUR"'; echo $n')
|
| 128 |
+
line=$(sed -n "$((idx+1))p" "$JOBS")
|
| 129 |
+
[ -n "$line" ] || break
|
| 130 |
+
m=${line%%|*}; rest=${line#*|}; L=${rest%%|*}; t=${rest##*|}
|
| 131 |
+
say " [gpu $g] $m / $L / $t"
|
| 132 |
+
CUDA_VISIBLE_DEVICES=$g "${PYFOR[$m]:-$PY}" peer_run.py --model "${REPO[$m]}" \
|
| 133 |
+
--prompts "$ROOT/prompts/$m/$L/${t}_prompts.jsonl" \
|
| 134 |
+
--out "$ROOT/gen/$L/${m}_${t}.jsonl" --max-new "$MAX_NEW" \
|
| 135 |
+
> "$ROOT/gen/$L/${m}_${t}.log" 2>&1 \
|
| 136 |
+
|| say " FAIL [gpu $g] $m/$L/$t (see $ROOT/gen/$L/${m}_${t}.log)"
|
| 137 |
+
done
|
| 138 |
+
}
|
| 139 |
+
for g in $GPUS; do worker "$g" & done
|
| 140 |
+
wait
|
| 141 |
+
fi
|
| 142 |
+
say "generation done"
|
| 143 |
+
|
| 144 |
+
# ---- 4. score, one summary per length --------------------------------------
|
| 145 |
+
CSV=$(echo $MODELS | tr ' ' ','); TSV=$(echo $TASKS | tr ' ' ',')
|
| 146 |
+
for L in $LENS; do
|
| 147 |
+
say "scoring $L"
|
| 148 |
+
$PY peer_score.py --gen-dir "$ROOT/gen/$L" --meta-dir "$ROOT/prompts" \
|
| 149 |
+
--out-dir "$ROOT/results/$L" --length "$L" --models "$CSV" --tasks "$TSV" \
|
| 150 |
+
>>"$M" 2>&1 || say " WARN: scoring failed at $L"
|
| 151 |
+
[ -f "$ROOT/results/$L/summary.csv" ] && say " -> $(sed -n 2p "$ROOT/results/$L/summary.csv")"
|
| 152 |
+
done
|
| 153 |
+
say "=== PEER EVAL DONE -> $ROOT/results ==="
|