#!/usr/bin/env bash # baseline-pair: balanced, interleaved ours-vs-vanilla Strata 0.2.6 A/B on the RTX 5090 at ~245k context, with a machine-state record around every run. # HOLDER JOB (rnr5090). Install: scripts/e2e/decode/baseline-install.sh (copies the tools to /data/leleka-e2e/baseline-pair/tools, freezes them read-only, writes # MANIFEST.sha256) ; stub ~/work/gpu-runs/holder2/jobs/.sh = `#!/usr/bin/env bash` / `exec bash /data/leleka-e2e/baseline-pair/tools/baseline-pair-ab.sh` (+ env lines) ; # one line in jobs/PRIORITY (back PRIORITY up first). gpu.lock per arm; ~5 min an arm. # # Arms (one session each: the frozen 245k corpus, 5 turns, --max-output 300, final-turn input >= 200k tokens, the harness of speedtrain3-ab.sh): # ours dt/bin-footprint3b = code of main e381c3082 (git diff 9e13fc809 e381c3082 outside docs/ and scripts/ is empty), shipped lossless defaults: seed off (the profile # default), upstream ranked profile, auto expert slots (12,192), budget 31,300 MiB, spec-min-p 0, prefix cache auto. Nothing experimental. # v1 vanilla Strata 0.2.6 shipped defaults: route tail skip ON (rank 7, lossy), prefill CPU share ON (below 1024-token chunks). # v2 vanilla with STRATA_ROUTE_TAIL_SKIP=0 STRATA_PREFILL_CPU_SHARE=0 (lossless-comparable). # Order: a block runs the three arms once, in one of the 6 permutations (BLOCKS = permutation numbers). Permutations 1..6 are three reversed pairs, so over blocks 1-6 every arm # is first, second and last twice and every ordered neighbour pair occurs equally often (ABBA generalised to three arms). A block is the unit of pairing: ours - v1 and ours - v2 are # formed inside the block, never across blocks. # Warm-up discipline: all arms start from the same procedure (no GPU process, load1 < 0.5, GPU <= 48 C or 150 s, no page-cache drop, nothing pre-touched); the state is RECORDED # (pre.jsonl before the arm; state.jsonl every 15 s and per-CPU clocks every 2 s during it; startup.txt = the engine's own start lines: arena / THP / PCIe probe / pool). Block 1 is not discarded. # Per-turn client lines are timestamped (client.ts.log) so decode windows can be joined to the state samples. # # BLOCKS="1 2 3 4 5 6" BLOCK_BASE=0 RUN_TAG= bash baseline-pair-ab.sh # job bp-a ; job bp-b: BLOCK_BASE=6 set -uo pipefail BP=/data/leleka-e2e/baseline-pair D=/data/leleka-e2e/decode/dt LOCK=/data/leleka-e2e/gpu.lock OUTR=${OUTR:-/data/leleka-e2e/runs/baseline-pair} CORPUS=/data/leleka-e2e/decode/corpus/src/crates UP=/data/leleka-e2e/decode/assets/expert-profile-upstream.bin BINDIR=${BINDIR:-bin-footprint3b} BLOCKS=${BLOCKS:-"1 2 3 4 5 6"} BLOCK_BASE=${BLOCK_BASE:-0} RUN_TAG=${RUN_TAG:-} SESSION_ARGS="--turns 5 --target-tokens 245000 --max-output 300 --min-final-tokens 200000" perm() { case $1 in 1) echo "ours v1 v2";; 2) echo "v2 v1 ours";; 3) echo "v1 v2 ours";; 4) echo "ours v2 v1";; 5) echo "v2 ours v1";; 6) echo "v1 ours v2";; *) return 1;; esac; } mkdir -p "$OUTR" # frozen inputs: refuse to run when one is missing or its digest differs (MANIFEST.sha256 holds tools, the ours binaries, the vanilla launcher and engine, the profile, the harness) ( cd / && sha256sum --quiet -c "$BP/MANIFEST.sha256" ) || { echo "baseline-pair: MANIFEST.sha256 check failed" >&2; exit 3; } for f in "$UP" "$CORPUS/backend-api/src/lib.rs" "$D/$BINDIR/leleka-inference" "$BP/tools/baseline-sampler.py" "$BP/tools/ts-wrap.sh"; do [ -r "$f" ] || { echo "missing $f" >&2; exit 3; } done settle() { # $1 run dir: same start procedure for every arm; the waits are recorded local n=0 t l while [ $n -lt 30 ]; do # <= 150 s for the GPU to cool t=$(nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits | head -1) [ "${t:-99}" -le 48 ] && break sleep 5; n=$((n + 1)) done echo "gpu_temp_c=$t cooled_after_s=$((n * 5))" >"$1/settle.txt" n=0 while [ $n -lt 24 ]; do # <= 120 s for the machine to go quiet (a foreign CPU job is waited out, then recorded) l=$(cut -d" " -f1 /proc/loadavg) awk -v l="$l" 'BEGIN{exit !(l < 0.5)}' && break sleep 5; n=$((n + 1)) done echo "load1=$l quiet_after_s=$((n * 5))" >>"$1/settle.txt" python3 -I "$BP/tools/baseline-sampler.py" "$1/pre.jsonl" --once } start_sampler() { # $1 run dir -> SAMP taskset -c 31 python3 -I "$BP/tools/baseline-sampler.py" "$1/state.jsonl" --full-s 15 --fast-s 2 >/dev/null 2>&1 & SAMP=$! } stop_sampler() { kill -TERM "$SAMP" 2>/dev/null; wait "$SAMP" 2>/dev/null python3 -I "$BP/tools/baseline-sampler.py" "$1/post.jsonl" --once } ours() { # $1 tag, $2 run dir, $3 arm (ours | ours45) local tag=$1 R=$2 oarm=${3:-ours} ( export E2E_BIN=$D/$BINDIR E2E_OUT=$R export LELEKA_BRINGUP_TRACE=1 LELEKA_PREFIX_TRACE=1 export LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS=auto E2E_GPU_BUDGET=${GPU_BUDGET:-32819404800} export E2E_ENGINE_ARGS="--prefix-cache-mib auto --prefix-cache-tail reply --original-prefill-capacity 8192 --prefix-cache-block 8192 --spec-min-p 0" export E2E_SAMPLE_S=10 LELEKA_CHAIN=all export LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE=$UP unset LELEKA_FOOTPRINT_LEGACY LELEKA_ORIGINAL_SERVE_SEED_MAX_ROWS LELEKA_SM120_ATTN_DAILY LELEKA_SM120_GU_SWIGLU LELEKA_SM120_SIDE_MIXER LELEKA_SM120_PERF LELEKA_SERVE_DRAFT_AFTER_COMMIT LELEKA_PROMPT_EMBED_ALIAS LELEKA_VRAM_LEDGER LELEKA_DENSE_SLAB LELEKA_ORIGINAL_SERVE_DECODE_RESERVE_MIB LELEKA_ROUTE_TAIL_SKIP export LELEKA_ORIGINAL_SERVE_SEED=off unset LELEKA_ORIGINAL_SERVE_PCIE_FRAC # ours45 = the product default PCIe share 0.45; ours = whatever run-e2e.sh exports (its own default 0.55, the value every earlier harness A/B used) if [ "$oarm" = ours45 ]; then export LELEKA_ORIGINAL_SERVE_PCIE_FRAC=0.45; fi echo "pcie_frac_requested=${LELEKA_ORIGINAL_SERVE_PCIE_FRAC:-0.55 (run-e2e.sh default)}" >"$R/pcie-frac.txt" { echo "arm=$oarm tag=$tag"; date -u +%FT%TZ; free -g | sed -n 2p; uptime; sha256sum "$UP" "$E2E_BIN"/leleka-inference "$E2E_BIN"/leleka-daemon "$E2E_BIN"/leleka-cli "$E2E_BIN"/strata-next cat "$E2E_BIN/COMMIT.txt" 2>/dev/null; head -1 /data/leleka-e2e/decode/corpus/MANIFEST.txt env | grep -E '^(LELEKA_|STRATA_|E2E_)' | sort; } >"$R/env-arm.txt" export E2E_RUN_CMD="bash $BP/tools/ts-wrap.sh $R/client.ts.log python3 -I $D/tools/long-session.py --src $CORPUS $SESSION_ARGS" bash "$D/scripts/e2e/run-e2e.sh" 2>&1 | grep -a -E "^\{|expert cache|request outcome|ready after|rc=|refus|error|Error|long_session|client exit" | cut -c1-300 echo "run-e2e done $tag $(date -u +%FT%TZ)" ) } vanilla() { # $1 tag, $2 run dir, $3 variant (v1|v2) local tag=$1 R=$2 var=$3 ( export XDG_CONFIG_HOME=$R/xdg-config XDG_STATE_HOME=$R/xdg-state mkdir -p "$XDG_CONFIG_HOME/strata" "$XDG_STATE_HOME" cp ~/.config/strata/settings.json "$XDG_CONFIG_HOME/strata/" if [ "$var" = v2 ]; then export STRATA_ROUTE_TAIL_SKIP=0 STRATA_PREFILL_CPU_SHARE=0; fi { echo "arm=$var tag=$tag"; date -u +%FT%TZ; free -g | sed -n 2p; uptime; head -1 /data/leleka-e2e/decode/corpus/MANIFEST.txt; env | grep -E '^(STRATA_|LELEKA_)' | sort; } > "$R/env.txt" S=$HOME/work/vanilla-strata/control/bin/strata cd "$HOME/work/vanilla-strata/control" T0=$(date +%s) timeout 2400 $S launch --model iq3_s --family qwen --model-path /home/para/work/leleka/models/leleka-gates/assets/model --context 256k --kv int8 --vision off --parallel 1 --tune skip --access local --port 8090 --no-api-key --no-tui --yes > "$R/launch.out" 2>&1 echo "launch_rc=$? ready_wall_s=$(( $(date +%s) - T0 ))" >> "$R/env.txt" if curl -fs http://127.0.0.1:8090/v1/models > "$R/models.json"; then MODEL=$(python3 -c "import json;print(json.load(open('$R/models.json'))['data'][0]['id'])") E2E_BASE_URL=http://127.0.0.1:8090 E2E_MODEL=$MODEL E2E_API_KEY=none E2E_OUT_DIR=$R bash "$BP/tools/ts-wrap.sh" "$R/client.ts.log" python3 -I $D/tools/long-session.py --src $CORPUS $SESSION_ARGS > "$R/client.log" 2>&1 echo "session_rc=$?" >> "$R/env.txt" cp "$XDG_STATE_HOME/strata/launch/iq3_s-256k.engine.log" "$R/engine.log" else echo "not ready" >> "$R/env.txt" fi $S launch --stop >> "$R/launch.out" 2>&1 sleep 8 date -u +%FT%TZ >> "$R/env.txt" cut -c1-300 "$R/client.log" 2>/dev/null ) } validity() { # $1 run dir, $2 arm python3 -I - "$1" "$2" <<'PY' import json, os, re, sys d, arm = sys.argv[1], sys.argv[2] f = os.path.join(d, "long-session.json") verdict = "INVALID: no long-session.json" if os.path.exists(f): t = json.load(open(f)) final = (t[-1].get("input_tokens") or 0) if t else 0 if any("error" in r for r in t): verdict = "INVALID: a turn failed" elif len(t) < 5 or final < 200000: verdict = "INVALID: %d turns, final-turn input tokens %d < 200000 (short corpus?)" % (len(t), final) else: verdict = "VALID: 5 turns, final-turn input tokens %d" % final if arm.startswith("ours"): wins, last = [], [] for ln in open(os.path.join(d, "inference.log"), errors="replace"): if ln.startswith("DBG window "): last.append(dict((k, float(v)) for k, v in re.findall(r"(\w+)=([-\d.]+)", ln))) elif "leleka-serve request outcome" in ln: wins.append(last); last = [] w = wins[-1] if wins else [] ple = sum(x.get("ple", 0) for x in w) / max(len(w), 1) verdict += "; turn-5 window.ple mean %.2f ms over %d windows" % (ple, len(w)) if not w: verdict = "INVALID: no turn-5 window lines (trace env missing?)" elif ple >= 5: verdict = "INVALID: turn-5 window.ple mean %.2f ms >= 5 ms (PLE scan back?)" % ple else: log = open(os.path.join(d, "engine.log"), errors="replace").read() if os.path.exists(os.path.join(d, "engine.log")) else "" skip_on = "STRATA_ROUTE_TAIL_SKIP=7 is ON" in log share_on = "the CPU share is ON by default" in log if arm == "v1" and not (skip_on and share_on): verdict = "INVALID: v1 but tail skip on=%s cpu share on=%s in the engine log" % (skip_on, share_on) elif arm == "v2" and (skip_on or share_on): verdict = "INVALID: v2 but tail skip on=%s cpu share on=%s in the engine log" % (skip_on, share_on) else: verdict += "; engine log: tail skip %s, cpu share %s" % ("ON" if skip_on else "off", "ON" if share_on else "off") open(os.path.join(d, "VALIDITY.txt"), "w").write(verdict + "\n") print(os.path.basename(d), verdict) PY } # the run list: "block:pos:arm" entries. Default = permutations of BLOCKS. SEQ="v2 v2 ours ..." runs exactly that sequence instead (SEQ_GROUP arms per block, default 3), used by # the predecessor test of job bp-b (VV O repeated: a vanilla run directly after ours against a vanilla run directly after vanilla, interleaved in time). LIST="" if [ -n "${SEQ:-}" ]; then i=0; for arm in $SEQ; do LIST="$LIST $((BLOCK_BASE + i / ${SEQ_GROUP:-3} + 1)):$((i % ${SEQ_GROUP:-3} + 1)):$arm"; i=$((i + 1)); done else for b in $BLOCKS; do pos=0; for arm in $(perm "$b" | sed "s/v1/${SUBST_V1:-v1}/"); do pos=$((pos + 1)); LIST="$LIST $((BLOCK_BASE + b)):$pos:$arm"; done; done fi for ent in $LIST; do bn=${ent%%:*}; rest=${ent#*:}; pos=${rest%%:*}; arm=${rest#*:} tag=$(printf "b%02dp%d-%s%s" "$bn" "$pos" "$arm" "$RUN_TAG"); R=$OUTR/$tag [ -e "$BP/STOP" ] && { echo "STOP file present, ending before $tag"; exit 0; } got=0 for _ in $(seq 1 1080); do if mkdir "$LOCK" 2>/dev/null; then echo "baseline-pair $tag $(date -u +%FT%TZ)" >"$LOCK/owner"; got=1; break; fi sleep 5 done [ $got = 1 ] || { echo "GPU lock held by: $(cat $LOCK/owner 2>/dev/null)"; exit 3; } echo "=== $tag $(date -u +%FT%TZ)" if [ -n "$(nvidia-smi --query-compute-apps=pid --format=csv,noheader)" ]; then echo "GPU busy, skipping $tag"; rm -f "$LOCK/owner"; rmdir "$LOCK" 2>/dev/null; continue fi mkdir -p "$R"; echo "block=$bn pos=$pos arm=$arm" >"$R/ARM.txt" # optional owner-run hook before the settle (e.g. a root script that compacts memory); default none. Its exit status and stdout go to hook.txt [ -n "${PRE_ARM_HOOK:-}" ] && { bash "$PRE_ARM_HOOK" "$arm" >"$R/hook.txt" 2>&1; echo "hook_rc=$?" >>"$R/hook.txt"; } settle "$R" start_sampler "$R" case $arm in ours|ours45) ours "$tag" "$R" "$arm" ;; v1|v2) vanilla "$tag" "$R" "$arm" ;; esac stop_sampler "$R" # the engine's own start lines (arena / THP / PCIe probe / pool / cache), one small file per run for lg in "$R/engine.log" "$R/inference.log"; do [ -r "$lg" ] && grep -a -E "arena|MAP_HUGETLB|huge|PCIe probe|pcie_frac|CPU pool|pool workers|expert cache|memory guard|ROUTE_TAIL_SKIP|CPU share|Cpus|pinned|affin" "$lg" | head -60 | cut -c1-300; done >"$R/startup.txt" validity "$R" "$arm" echo "arm done $tag $(date -u +%FT%TZ)" rm -f "$LOCK/owner"; rmdir "$LOCK" 2>/dev/null sleep 15 done [ -r "$BP/tools/baseline-analyze.py" ] && python3 -I "$BP/tools/baseline-analyze.py" "$OUTR" > "$OUTR/ANALYSIS.$(date -u +%Y%m%dT%H%M%SZ).txt" 2>&1 echo "baseline-pair job done $(date -u +%FT%TZ)"