From ca3eb4f8fa06b6e5552bcba1feab28e44b955ebb Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Mon, 2 Nov 2026 00:11:14 +0100 Subject: [PATCH] scripts: reboot series, prefetch of the KAR file and model shard (cold buffered reads run at ~30 MB/s on this NVMe), START_CYCLE Co-Authored-By: Claude Sonnet 5.5 --- scripts/e2e/decode/baseline-install.sh | 2 +- scripts/e2e/decode/baseline-prefetch.py | 40 ++++++++++++++++++++ scripts/e2e/decode/baseline-reboot-series.sh | 12 ++++-- 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 scripts/e2e/decode/baseline-prefetch.py diff --git a/scripts/e2e/decode/baseline-install.sh b/scripts/e2e/decode/baseline-install.sh index ea52b1a2..8c1c5055 100644 --- a/scripts/e2e/decode/baseline-install.sh +++ b/scripts/e2e/decode/baseline-install.sh @@ -10,7 +10,7 @@ D=/data/leleka-e2e/decode/dt SRC=$(cd "$(dirname "$0")" && pwd) mkdir -p "$BP/tools" chmod -R u+w "$BP/tools" 2>/dev/null || true -for f in baseline-pair-ab.sh baseline-sampler.py ts-wrap.sh cycle-hook.sh; do install -m 0444 "$SRC/$f" "$BP/tools/$f"; done +for f in baseline-pair-ab.sh baseline-sampler.py ts-wrap.sh cycle-hook.sh baseline-prefetch.py; do install -m 0444 "$SRC/$f" "$BP/tools/$f"; done chmod a-w "$BP/tools" ENG=$(ls -d /home/para/.local/share/strata/components/engine/*/strata | head -1) { diff --git a/scripts/e2e/decode/baseline-prefetch.py b/scripts/e2e/decode/baseline-prefetch.py new file mode 100644 index 00000000..791891e7 --- /dev/null +++ b/scripts/e2e/decode/baseline-prefetch.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 +"""Pre-read files into the page cache with large asynchronous readahead (posix_fadvise WILLNEED, a sliding window 3 GiB ahead of the reader). Read-only. + python3 -I baseline-prefetch.py FILE_OR_DIR [...] (a directory = every regular file in it, largest first) +Why: after a reboot the page cache is cold and the server's NVMe serves the plain buffered 128 KiB-readahead pattern of the holder / loaders at only ~30 MB/s (r_await 4 ms, queue +depth 1; measured 2026-11-01: 31 GB of the 55 GB KAR file in 15 min), while the same file read with large or WILLNEED requests runs at ~600 MB/s. Without this a reboot cycle +costs about an hour of cold loading. The reads change no data; the page cache ends up in the state a normal run starts from (model files cached). +""" +import mmap, os, sys, time +W = 1 << 30 +AHEAD = 3 +def files(args): + for a in args: + if os.path.isdir(a): + fs = [os.path.join(a, f) for f in os.listdir(a) if os.path.isfile(os.path.join(a, f))] + for f in sorted(fs, key=os.path.getsize, reverse=True): + yield f + else: + yield a +for path in files(sys.argv[1:]): + size = os.path.getsize(path) + if size == 0: + continue + fd = os.open(path, os.O_RDONLY) + t0 = time.time() + for o in range(0, min(size, AHEAD * W), W): + os.posix_fadvise(fd, o, min(W, size - o), os.POSIX_FADV_WILLNEED) + off = 0 + while off < size: + n = min(W, size - off) + nxt = off + AHEAD * W + if nxt < size: + os.posix_fadvise(fd, nxt, min(W, size - nxt), os.POSIX_FADV_WILLNEED) + m = mmap.mmap(fd, n, prot=mmap.PROT_READ, offset=off) + for i in range(0, n, 1 << 20): + m[i] + m.close() + off += n + os.close(fd) + dt = time.time() - t0 + print("prefetch %s %.1f GiB in %.0f s (%.0f MB/s)" % (path, size / 2**30, dt, size / 1e6 / max(dt, 1e-6)), flush=True) diff --git a/scripts/e2e/decode/baseline-reboot-series.sh b/scripts/e2e/decode/baseline-reboot-series.sh index 8d0b82aa..6d5cc5dd 100644 --- a/scripts/e2e/decode/baseline-reboot-series.sh +++ b/scripts/e2e/decode/baseline-reboot-series.sh @@ -14,6 +14,7 @@ set -uo pipefail BLOCKS=${1:-"1 2 3 4 5 6"} SSH="ssh -o ConnectTimeout=6 -o BatchMode=yes rnr5090" OUTR=/data/leleka-e2e/runs/baseline-pair-e +PF=/data/leleka-e2e/baseline-pair/tools/baseline-prefetch.py JOBS='$HOME/work/gpu-runs/holder2/jobs' SERIES_LOG=${SERIES_LOG:-./baseline-reboot-series.log} STOPFILE=${STOPFILE:-./baseline-reboot-series.STOP} @@ -66,6 +67,7 @@ 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 while :; do @@ -87,14 +89,18 @@ for b in $BLOCKS; do 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 (~600 MB/s) before the holder reads it + $SSH "python3 -I $PF /home/para/work/leleka/models/leleka-gates/assets/qwen-iq3-s-l2-v4.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 kar_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; pgrep -f kar_holder2 | head -1 >/dev/null; echo started' | while read -r l; do log "holder: $l"; done - for _ in $(seq 1 90); do $SSH 'test -s '"$JOBS"'/READY' 2>/dev/null && break; sleep 10; done + $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 150); do $SSH 'test -s '"$JOBS"'/READY' 2>/dev/null && break; sleep 10; done $SSH 'test -s '"$JOBS"'/READY' || die "KAR holder not READY within 15 min" log "holder READY: $($SSH 'cat '"$JOBS"'/READY; echo " uptime_s=$(cut -d" " -f1 /proc/uptime)"')" 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 + # same page-cache state for every arm: the model shard that holds the experts, the MTP files, the vanilla pack + $SSH "python3 -I $PF /home/para/work/leleka/models/leleka-gates/assets/model/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00001-of-00002.gguf \$HOME/.local/share/strata/Strata-data/mtp \$HOME/.local/share/strata/Strata-data/packs/iq3_s" 2>&1 | while read -r l; do log "prefetch: $l"; done stub="bpe-$(printf '%02d' $cyc)" $SSH "mkdir -p $OUTR; cat > $JOBS/$stub.sh <