Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
101 lines
6.2 KiB
Bash
101 lines
6.2 KiB
Bash
#!/usr/bin/env bash
|
|
# KAR on / off A/B (docs/experiments/kar-off-ab-5090.md): shared shell functions. Test tooling, never in serving. Source it, do not run it.
|
|
# Both arms run STANDALONE (holder-free window): the lab holder's sealed memfd is the FULL 51.5 GiB archive and leaves ~66 GiB, which cannot hold the 50 GB expert bank AND the 28.8 GB
|
|
# PLE table in the page cache. Arm KAR = the shipped profile rtx5090-32g (own sparse memfd of 16 GB, as `leleka run` makes it); arm GGUF = rtx5090-32g-gguf-ple (no archive, PLE rows from
|
|
# GGUF shard 1 through the page cache, LELEKA_PLE_DIRECT=0). Same binaries (engine, gateway, API), same assets, same expert profile, same flags otherwise.
|
|
K=${KO_ROOT:-/data/leleka-e2e/kar-off-ab}
|
|
CMP=/data/leleka-e2e/codex-compare
|
|
LOCK=/data/leleka-e2e/gpu.lock
|
|
G=$HOME/work/gpu-runs
|
|
CUBLAS=$HOME/cuda-toolkits/cublas-12.9.1.4/lib
|
|
PKG=$K/pkg # bin/ = the release 17e3729 binaries, `leleka` replaced by the kar_source=none build; MANIFEST.json updated (kar_off_install.sh)
|
|
AS=$K/assets # links to the codex-compare release assets (shards, KAR archive, MTP pack, expert profile): nothing is copied
|
|
SHARD1=$AS/model/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00002-of-00002.gguf
|
|
ko_state() { echo "$K/arm-$1/state"; }
|
|
ko_prefix() { echo "$K/arm-$1/prefix"; }
|
|
ko_profile() { case $1 in kar) echo rtx5090-32g;; gguf) echo rtx5090-32g-gguf-ple;; *) echo "bad arm $1" >&2; return 2;; esac; }
|
|
ko_log() { echo "[kar-off $(date -u +%T)] $*"; }
|
|
ko_note() { echo "[$(date -u +%FT%TZ)] [DEV kar-off-ab] $*" >>/data/leleka-e2e/decode/notes.md; }
|
|
|
|
# verify the installed tools and (standalone) take MODEL.lock + gpu.lock; sets KO_STANDALONE; call ko_release in the EXIT trap
|
|
ko_guard() {
|
|
( cd "$K" && sha256sum --quiet -c INSTALL.sha256 ) || { echo "installed tools differ from INSTALL.sha256"; return 3; }
|
|
( cd "$PKG" && sha256sum --quiet -c ../pkg.sha256 ) || { echo "the package differs from pkg.sha256"; return 3; }
|
|
mkdir "$G/MODEL.lock" 2>/dev/null || { echo "MODEL.lock is held (holder still up?)"; return 3; }
|
|
KO_STANDALONE=1
|
|
local got=0 _
|
|
for _ in $(seq 1 4320); do
|
|
if mkdir "$LOCK" 2>/dev/null; then echo "kar-off-ab $(date -u +%FT%TZ) $1" >"$LOCK/owner"; got=1; break; fi
|
|
sleep 5
|
|
done
|
|
[ $got = 1 ] || { echo "GPU lock held by: $(cat $LOCK/owner 2>/dev/null)"; rmdir "$G/MODEL.lock"; KO_STANDALONE=0; return 3; }
|
|
local shmem; shmem=$(awk '/^Shmem:/{print int($2/1048576)}' /proc/meminfo)
|
|
[ "$shmem" -lt 8 ] || { echo "Shmem is $shmem GiB: a sealed memfd is still resident"; return 3; }
|
|
if [ -n "$(nvidia-smi --query-compute-apps=pid --format=csv,noheader 2>/dev/null)" ]; then echo "something uses the GPU"; return 3; fi
|
|
if pgrep -u "$USER" -x 'leleka-inference|strata-next|leleka-daemon' >/dev/null; then echo "a stack process exists"; return 3; fi
|
|
for p in 18766 18080 8081 8090; do ss -ltn "sport = :$p" 2>/dev/null | grep -q LISTEN && { echo "port $p in use"; return 3; }; done
|
|
export LD_LIBRARY_PATH=$CUBLAS:$HOME/cuda-toolkits/13.2.2/lib64:${LD_LIBRARY_PATH:-}
|
|
}
|
|
ko_release() {
|
|
rm -f "$LOCK/owner"; rmdir "$LOCK" 2>/dev/null
|
|
[ "${KO_STANDALONE:-0}" = 1 ] && rmdir "$G/MODEL.lock" 2>/dev/null
|
|
}
|
|
|
|
# assets (links) and the per-arm state/prefix, idempotent. The verification stamps are copied from the codex-compare state: they are keyed by file identity, not by path.
|
|
ko_prepare() { # $1 arm
|
|
local arm=$1 st pf prof
|
|
st=$(ko_state "$arm"); pf=$(ko_prefix "$arm"); prof=$(ko_profile "$arm") || return 2
|
|
if [ ! -e "$AS/model" ]; then
|
|
mkdir -p "$AS"; cp -a "$CMP/ours-assets/." "$AS/" || return 5 # symlinks stay links; the small files (provenance, data/*) are hard-linked below
|
|
fi
|
|
if [ ! -f "$st/leleka.json" ]; then
|
|
mkdir -p "$st"; [ -d "$CMP/ours-state/stamps" ] && cp -a "$CMP/ours-state/stamps" "$st/stamps"
|
|
timeout 3000 "$PKG/bin/leleka" up --mode none --profile "$prof" --assets "$AS" --state-dir "$st" --prefix "$pf" --bin-src "$PKG/bin" --cublas-dir "$CUBLAS" --trust-archive \
|
|
>"$K/arm-$arm/up-prepare.txt" 2>&1
|
|
ko_log "up --mode none ($prof) rc=$?"
|
|
fi
|
|
[ -f "$st/leleka.json" ]
|
|
}
|
|
|
|
# start the stack of one arm in the background; waits for readiness. Sets KO_SUP_PID. $2 = output dir for the up log
|
|
ko_start() { # $1 arm $2 outdir
|
|
local arm=$1 out=$2 st pf t0 ready=0 _
|
|
st=$(ko_state "$arm"); pf=$(ko_prefix "$arm")
|
|
mkdir -p "$out"; : >"$st/logs/engine.log" 2>/dev/null
|
|
t0=$(date +%s)
|
|
# the engine inherits this environment (LELEKA_PLE_DIRECT=0 comes from the gguf profile's engine_env, not from here)
|
|
setsid "$PKG/bin/leleka" up --foreground --profile "$(ko_profile "$arm")" --assets "$AS" --state-dir "$st" --prefix "$pf" --bin-src "$PKG/bin" --cublas-dir "$CUBLAS" --trust-archive \
|
|
--timeout-s 1800 >"$out/up-foreground.txt" 2>&1 &
|
|
KO_SUP_PID=$!
|
|
for _ in $(seq 1 700); do
|
|
"$pf/bin/leleka" status --state-dir "$st" >/dev/null 2>&1 && { ready=1; break; }
|
|
kill -0 "$KO_SUP_PID" 2>/dev/null || break
|
|
sleep 3
|
|
done
|
|
if [ $ready != 1 ]; then ko_log "arm $arm NOT READY after $(( $(date +%s) - t0 )) s"; tail -20 "$out/up-foreground.txt" | cut -c1-240; return 7; fi
|
|
echo "$(( $(date +%s) - t0 ))" >"$out/ready_s.txt"
|
|
ko_log "arm $arm ready after $(( $(date +%s) - t0 )) s"
|
|
"$pf/bin/leleka" status --state-dir "$st" --json >"$out/status.json" 2>&1
|
|
}
|
|
ko_stop() {
|
|
if [ -n "${KO_SUP_PID:-}" ] && kill -0 "$KO_SUP_PID" 2>/dev/null; then
|
|
kill -TERM "$KO_SUP_PID" 2>/dev/null
|
|
local _; for _ in $(seq 1 120); do kill -0 "$KO_SUP_PID" 2>/dev/null || break; sleep 2; done
|
|
fi
|
|
KO_SUP_PID=
|
|
pkill -KILL -f "$K/arm-" 2>/dev/null
|
|
sleep 5
|
|
}
|
|
|
|
# host sampler: one line every 5 s: epoch, MemAvailable, Cached, Shmem (MiB), sectors read on the model disk, GPU clock/temperature. $1 file
|
|
ko_sampler() {
|
|
( while :; do
|
|
printf '%s %s %s %s %s %s\n' "$(date +%s)" \
|
|
"$(awk '/^MemAvailable:/{printf "%d",$2/1024}' /proc/meminfo)" "$(awk '/^Cached:/{printf "%d",$2/1024}' /proc/meminfo)" "$(awk '/^Shmem:/{printf "%d",$2/1024}' /proc/meminfo)" \
|
|
"$(awk '$3=="nvme0n1"{print $6}' /proc/diskstats)" "$(nvidia-smi --query-gpu=clocks.sm,temperature.gpu --format=csv,noheader,nounits 2>/dev/null | tr -d ' ')"
|
|
sleep 5
|
|
done ) >"$1" 2>/dev/null &
|
|
KO_SAMPLER_PID=$!
|
|
}
|
|
ko_sampler_stop() { [ -n "${KO_SAMPLER_PID:-}" ] && kill "$KO_SAMPLER_PID" 2>/dev/null; KO_SAMPLER_PID=; }
|