Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
157 lines
11 KiB
Bash
157 lines
11 KiB
Bash
#!/usr/bin/env bash
|
|
# baseline-pair part e: ONE ARM PER FRESH BOOT. Runs on the LAPTOP (git bash), drives rnr5090 over ssh. Owner-authorised (chat, 2026-11-01): rebooting rnr5090 between runs.
|
|
# Allowed on the server: `sudo -n systemctl reboot` and nothing else privileged (no systemd units, sysctl, grub, drop_caches, compact_memory; `sudo -n dmesg` is read-only).
|
|
#
|
|
# [START_CYCLE=2] bash baseline-reboot-series.sh [BLOCKS="1 2 3"] env: SERIES_LOG (local log), STOPFILE (touch it to stop after the current cycle), START_CYCLE (resume)
|
|
#
|
|
# Per cycle: (1) nothing foreign may run (jobs pending/running other than our stubs, gpu.lock, a GPU process); wait otherwise, never reboot under a job;
|
|
# (2) `sync`, reboot, wait for ssh (new boot_id) up to 10 min; on timeout try the rescue sshd (:2222, `rboot`) once, then STOP; (3) safety net check (rescue sshd :2222, /dev/watchdog0,
|
|
# hung_task_panic=1, swap off, no NVMe errors in dmesg): any failure STOPs the series; (4) pre-read the KAR file (large WILLNEED requests), restart the KAR holder the way decode/notes.md did
|
|
# after a boot (remove the empty stale MODEL.lock, delete jobs/READY, `setsid nohup bash run_holder2.sh`), wait for READY (90 min);
|
|
# (5) EVICT the page cache of the files read so far with per-file posix_fadvise(DONTNEED) (KAR file, both model shards, MTP files, vanilla pack; read-only files, user level): the holder's read
|
|
# leaves ~50 GB of page cache that makes vanilla find no free 2 MiB blocks and run without huge pages; record MemFree and the free 2 MiB blocks; (6) queue ONE holder job (the arm) via
|
|
# ENTRIES, wait for its .done, read VALIDITY.txt; (7) a vanilla arm must show AnonHugePages >= 46.4 GiB (baseline-thpcheck.py), otherwise the run is moved to _poor/ and the cycle is
|
|
# repeated ONCE (a second poor run is kept and flagged); an invalid run is moved to _invalid/ and the cycle repeated once, a second failure STOPs the series; (8) next reboot.
|
|
# Arms: ours = dt/bin-main-ffd9322 (main d29e3dba2 has the same code outside docs/scripts), PCIe 0.45 pinned, defaults; v1 = vanilla shipped defaults; v2 = tail skip off + prefill CPU share 0.
|
|
# The job (baseline-pair-ab.sh) records settle.txt, pre.jsonl (uptime = time since boot, buddyinfo, meminfo), state.jsonl, post.jsonl, hook.txt (cycle-hook.sh: boot id/time, safety net, nvme dmesg hits).
|
|
set -uo pipefail
|
|
BLOCKS=${1:-"1 2 3"}
|
|
SSH="ssh -o ConnectTimeout=6 -o BatchMode=yes rnr5090"
|
|
OUTR=/data/leleka-e2e/runs/baseline-pair-e
|
|
TOOLS=/data/leleka-e2e/baseline-pair/tools
|
|
PF=$TOOLS/baseline-prefetch.py
|
|
EV=$TOOLS/baseline-evict.py
|
|
TC=$TOOLS/baseline-thpcheck.py
|
|
JOBS='$HOME/work/gpu-runs/holder2/jobs'
|
|
KAR=/home/para/work/leleka/models/leleka-gates/assets/qwen-iq3-s-l2-v4.kar
|
|
MODELDIR=/home/para/work/leleka/models/leleka-gates/assets/model
|
|
SERIES_LOG=${SERIES_LOG:-./baseline-reboot-series.log}
|
|
STOPFILE=${STOPFILE:-./baseline-reboot-series.STOP}
|
|
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";; esac; }
|
|
CYLOG=""
|
|
log() { local l="[$(date -u +%FT%TZ)] $*"; echo "$l" | tee -a "$SERIES_LOG"; CYLOG="$CYLOG$l"$'\n'; }
|
|
die() { log "STOP SERIES: $*"; push_log; exit 1; }
|
|
push_log() { [ -n "$CYLOG" ] && printf '%s' "$CYLOG" | $SSH "mkdir -p $OUTR/_cycles && cat >> $OUTR/_cycles/series.log" 2>/dev/null; CYLOG=""; }
|
|
|
|
foreign() { # prints what is running/queued that is not ours
|
|
$SSH 'cd ~/work/gpu-runs/holder2/jobs 2>/dev/null || exit 0
|
|
for f in *.sh; do b=${f%.sh}; case $b in 220-expert-tier|decode-sass-trace2|bpe-*) continue;; esac; [ -e $b.done ] || echo "job:$b"; done
|
|
for r in *.running; do b=${r%.running}; case $b in 220-expert-tier|decode-sass-trace2|bpe-*) continue;; esac; echo "running:$b"; done
|
|
[ -d /data/leleka-e2e/gpu.lock ] && echo "gpu.lock:$(cat /data/leleka-e2e/gpu.lock/owner 2>/dev/null)"
|
|
nvidia-smi --query-compute-apps=pid --format=csv,noheader | sed "s/^/gpu-pid:/"
|
|
pgrep -f "[l]eleka-inference|[s]trata-next|[/]strata --serve" | sed "s/^/proc:/"' 2>/dev/null
|
|
}
|
|
wait_quiet() { # up to 4 h
|
|
local n=0 f
|
|
while :; do
|
|
f=$(foreign | tr '\n' ' ')
|
|
[ -z "${f// /}" ] && return 0
|
|
n=$((n + 1)); [ $((n % 5)) = 1 ] && log "waiting for foreign work to finish: $f"
|
|
[ $n -gt 240 ] && die "foreign work still present after 4 h: $f"
|
|
sleep 60
|
|
done
|
|
}
|
|
wait_boot() { # $1 old boot_id ; up to 10 min after the reboot command
|
|
local t0=$SECONDS id
|
|
sleep 30
|
|
while [ $((SECONDS - t0)) -lt 600 ]; do
|
|
id=$($SSH 'cat /proc/sys/kernel/random/boot_id' 2>/dev/null) && [ -n "$id" ] && [ "$id" != "$1" ] && { log "ssh back after $((SECONDS - t0)) s, new boot_id $id"; return 0; }
|
|
sleep 10
|
|
done
|
|
log "no ssh within 10 min; trying the rescue sshd :2222"
|
|
ssh -o ConnectTimeout=10 -o BatchMode=yes -p 2222 -l root rnr5090 'uptime; dmesg | tail -15' 2>&1 | tail -20 | while read -r l; do log "rescue: $l"; done
|
|
ssh -o ConnectTimeout=10 -o BatchMode=yes -p 2222 -l root rnr5090 'rboot' >/dev/null 2>&1
|
|
t0=$SECONDS; sleep 30
|
|
while [ $((SECONDS - t0)) -lt 600 ]; do
|
|
id=$($SSH 'cat /proc/sys/kernel/random/boot_id' 2>/dev/null) && [ -n "$id" ] && [ "$id" != "$1" ] && { log "ssh back after rboot, $((SECONDS - t0)) s"; return 2; }
|
|
sleep 10
|
|
done
|
|
die "server did not come back after reboot and rboot"
|
|
}
|
|
memstate() { # MemFree / Cached / free 2 MiB+ blocks (buddyinfo orders 9-10, Normal + DMA32)
|
|
$SSH 'echo "MemFree_GiB=$(awk "/^MemFree/{printf \"%.1f\",\$2/2^20}" /proc/meminfo) Cached_GiB=$(awk "/^Cached/{printf \"%.1f\",\$2/2^20}" /proc/meminfo) Shmem_GiB=$(awk "/^Shmem:/{printf \"%.1f\",\$2/2^20}" /proc/meminfo) free2M_GiB=$(awk "/Normal|DMA32/{for(o=9;o<=10;o++) s+=\$(5+o)*4096*2^o} END{printf \"%.1f\",s/2^30}" /proc/buddyinfo)"'
|
|
}
|
|
|
|
mkdir -p "$(dirname "$SERIES_LOG")" 2>/dev/null
|
|
$SSH 'sudo -n true' || die "passwordless sudo not available"
|
|
cyc=0
|
|
for b in $BLOCKS; do
|
|
pos=0
|
|
for arm in $(perm "$b"); do
|
|
pos=$((pos + 1)); cyc=$((cyc + 1)); tag=$(printf "b%02dp%d-%s" "$b" "$pos" "$arm")
|
|
[ $cyc -lt ${START_CYCLE:-1} ] && continue # resume after a stopped series
|
|
[ -e "$STOPFILE" ] && die "stop file present before $tag"
|
|
tries=0; attempt=0; fails=0
|
|
while :; do
|
|
tries=$((tries + 1)); attempt=$((attempt + 1)); [ $tries -gt 4 ] && die "cycle $cyc ($tag) kept getting foreign work / retries"
|
|
log "=== cycle $cyc $tag (attempt $attempt)"
|
|
wait_quiet
|
|
old=$($SSH 'cat /proc/sys/kernel/random/boot_id') || die "ssh failed before reboot"
|
|
$SSH 'sudo -n true' || die "passwordless sudo vanished"
|
|
log "sync + reboot (old boot_id $old, uptime $($SSH 'uptime -p'))"
|
|
timeout 30 $SSH 'sync; sudo -n systemctl reboot' >/dev/null 2>&1
|
|
wait_boot "$old"; rc=$?
|
|
[ $rc = 2 ] && die "needed the rescue sshd (rboot) to come back: report to the owner"
|
|
# safety net after boot (retry briefly: services come up a little after sshd)
|
|
ok=0
|
|
for _ in 1 2 3 4 5 6; do
|
|
net=$($SSH 'echo rescue=$(ss -ltn | grep -c ":2222 ") wd=$(ls /dev/watchdog0 2>/dev/null | wc -l) hung=$(sysctl -n kernel.hung_task_panic) swap=$(swapon --show --noheadings | wc -l) nvme=$(sudo -n dmesg 2>/dev/null | grep -i -c -E "nvme.*(timeout|reset|abort|error)") up=$(cut -d" " -f1 /proc/uptime)')
|
|
case "$net" in *"rescue=1 "*"wd=1 hung=1 swap=0 nvme=0 "*) ok=1; break;; esac
|
|
sleep 10
|
|
done
|
|
log "safety net: $net"
|
|
[ $ok = 1 ] || die "safety net check failed after boot ($net)"
|
|
# cold page cache + this NVMe = ~30 MB/s for buffered reads (measured); pre-read the KAR file with large WILLNEED requests before the holder reads it
|
|
$SSH "python3 -I $PF $KAR" 2>&1 | while read -r l; do log "prefetch: $l"; done
|
|
# KAR holder, as after the boot of 2026-10-29 (notes.md): stale empty MODEL.lock removed, ONE holder started, READY rewritten
|
|
$SSH 'pgrep -f "[k]ar_holder2" >/dev/null && echo HOLDER_ALREADY_RUNNING; rm -f '"$JOBS"'/READY; [ -d $HOME/work/gpu-runs/MODEL.lock ] && { rmdir $HOME/work/gpu-runs/MODEL.lock || echo MODEL_LOCK_NOT_EMPTY; }
|
|
cd $HOME/work/gpu-runs/holder2 && { setsid nohup bash run_holder2.sh >> holder2.out 2>&1 < /dev/null & } ; sleep 1; echo started' | while read -r l; do log "holder: $l"; done
|
|
for _ in $(seq 1 480); do $SSH 'test -s '"$JOBS"'/READY' 2>/dev/null && break; sleep 10; done
|
|
$SSH 'test -s '"$JOBS"'/READY' || die "KAR holder not READY within 90 min"
|
|
log "holder READY: $($SSH 'cat '"$JOBS"'/READY; echo " uptime_s=$(cut -d" " -f1 /proc/uptime)"')"
|
|
log "memory before eviction: $(memstate)"
|
|
# evict the page cache of every file read so far (per-file posix_fadvise DONTNEED, twice), then record what is left
|
|
$SSH "python3 -I $EV $KAR $MODELDIR \$HOME/.local/share/strata/Strata-data/mtp \$HOME/.local/share/strata/Strata-data/packs/iq3_s; python3 -I $EV $KAR $MODELDIR; fincore $KAR | tail -1" 2>&1 | while read -r l; do log "evict: $l"; done
|
|
ms=$(memstate); log "memory after eviction: $ms"
|
|
f=$(foreign | grep -v '^proc:' | tr '\n' ' ')
|
|
if [ -n "${f// /}" ]; then log "foreign work appeared after boot ($f): waiting for it, then redoing the reboot for a fresh state"; wait_quiet; continue; fi
|
|
stub="bpe-$(printf '%02d' $cyc)-a$attempt"
|
|
$SSH "mkdir -p $OUTR; cat > $JOBS/$stub.sh <<EOF
|
|
#!/usr/bin/env bash
|
|
# baseline-pair part e, cycle $cyc attempt $attempt: one arm on a fresh boot (memory after eviction: $ms)
|
|
export OUTR=$OUTR BINDIR=bin-main-ffd9322 PCIE_FRAC=0.45 ENTRIES=\"$b:$pos:$arm\" PRE_ARM_HOOK=$TOOLS/cycle-hook.sh
|
|
exec bash $TOOLS/baseline-pair-ab.sh
|
|
EOF"
|
|
log "queued $stub ($tag)"
|
|
for _ in $(seq 1 270); do $SSH "test -e $JOBS/$stub.done" 2>/dev/null && break; sleep 10; done
|
|
$SSH "test -e $JOBS/$stub.done" || die "$stub did not finish within 45 min"
|
|
val=$($SSH "cat $OUTR/$tag/VALIDITY.txt 2>&1 | cut -c1-160")
|
|
log "$stub done rc=$($SSH "cat $JOBS/$stub.done") validity: $val"
|
|
$SSH "mkdir -p $OUTR/_cycles; cp $JOBS/$stub.log $OUTR/_cycles/$stub.log" 2>/dev/null
|
|
case "$val" in
|
|
VALID*) ;;
|
|
*) fails=$((fails + 1)); $SSH "mkdir -p $OUTR/_invalid && mv $OUTR/$tag $OUTR/_invalid/$tag-a$attempt"
|
|
[ $fails -ge 2 ] && die "cycle $cyc ($tag) failed twice: $val"
|
|
log "invalid run moved to _invalid; repeating the cycle once"; push_log; continue;;
|
|
esac
|
|
case $arm in
|
|
v1|v2)
|
|
thp=$($SSH "python3 -I $TC $OUTR/$tag")
|
|
log "THP check $tag: $thp"
|
|
case "$thp" in
|
|
*POOR*) if [ $attempt -lt 2 ]; then
|
|
$SSH "mkdir -p $OUTR/_poor && mv $OUTR/$tag $OUTR/_poor/$tag-a$attempt"
|
|
log "poor state (no full huge-page coverage): run moved to _poor; repeating the cycle once"; push_log; continue
|
|
else
|
|
$SSH "echo 'POOR STATE after the repeat: kept' > $OUTR/$tag/POOR.txt"; log "poor state again after the repeat: kept and flagged"
|
|
fi;;
|
|
esac;;
|
|
esac
|
|
push_log
|
|
break
|
|
done
|
|
done
|
|
done
|
|
log "series complete: $cyc cycles"
|
|
push_log
|