348 lines
24 KiB
Bash
348 lines
24 KiB
Bash
#!/usr/bin/env bash
|
|
# Single-copy A/B on the 5090: does the product hold ONE resident copy of every model byte in host RAM, with no decode or cold-start regression?
|
|
# Arms (balanced blocks, every arm first/second/last equally often; a block is the unit of pairing):
|
|
# base the code of main BEFORE this change (dt/bin-scbase, dt/rt-scbase) with the whole 55.3 GB archive in a sealed memfd (what the holder does).
|
|
# sparse this branch (dt/bin-singlecopy), `leleka seal-exec --sparse-ple`: only the 16.0 GB of extents the serve path reads are in the memfd (O_DIRECT copy, holes elsewhere).
|
|
# file this branch, the archive as an ordinary read-only file (`--kar-archive-file`, verification stamps): nothing is copied at start, the PLE rows go through the page cache on use.
|
|
# Everything else is identical: frozen corpus, 5 turns, target 245000 tokens, --max-output 300, seed OFF, upstream ranked profile, GPU budget 32,819,404,800,
|
|
# chunk and grid 8192, prefix cache 6144 MiB, PCIe share 0.45 (the product default), chain kernels. The EXPERT BANK IS THE SAME in all arms (resident, from GGUF shard 0).
|
|
#
|
|
# THIS IS NOT A HOLDER JOB: the holder's 55 GB memfd and the arms do not fit together on 121 GB. Run it with the holder stopped (it refuses otherwise), under MODEL.lock + gpu.lock.
|
|
# Phases (PHASES, default "cold id e2e"):
|
|
# cold per-arm cold start: archive/shard page cache evicted (posix_fadvise DONTNEED, never drop_caches), then `leleka seal-exec` of the full and the sparse memfd timed, and a RAM
|
|
# inventory taken while the memfd is held: allocated bytes (st_blocks) against apparent size, per-process Pss anon/file/shmem, page cache of the model files.
|
|
# id teacher-forced replay of night5-long-256k (top-16 logprobs of every forced row + draft traces), base against sparse, A/A inside each process: BITWISE identity gate.
|
|
# route (optional) one extra sparse-arm run with LELEKA_ORIGINAL_SERVE_DUMP_ROUTING: the routed experts of every decode window row, for the prefetch lead-time probe.
|
|
# e2e the 245k session, BLOCKS blocks of the three arms. Per run: memsample (5 s), RAM inventory (60 s + marks "idle" right after READY and "end" after turn 5), TTFT and decode tok/s
|
|
# per turn, engine load time, seal time.
|
|
# Env: BLOCKS (default 6; block b uses permutation b of the 3 arms), ARMS_SET (default "base sparse file"), PHASES, RUN_TAG, EXTENTS_SHA256 (default: the pin compiled into the binary), OUTR.
|
|
set -uo pipefail
|
|
D=/data/leleka-e2e/decode/dt
|
|
SC=/data/leleka-e2e/single-copy
|
|
LOCK=/data/leleka-e2e/gpu.lock
|
|
G=$HOME/work/gpu-runs
|
|
OUTR=${OUTR:-/data/leleka-e2e/runs/single-copy-ab}
|
|
CORPUS=/data/leleka-e2e/decode/corpus/src/crates
|
|
UP=/data/leleka-e2e/decode/assets/expert-profile-upstream.bin
|
|
A=$HOME/work/leleka/models/leleka-gates/assets
|
|
KAR=$A/qwen-iq3-s-l2-v4.kar
|
|
KAR_BYTES=55295529472
|
|
SHARD0=$A/model/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00001-of-00002.gguf
|
|
SHARD1=$A/model/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00002-of-00002.gguf
|
|
MTPX=$A/data/mtp-rt/experts.bin
|
|
BIN_BASE=${BIN_BASE:-$D/bin-scbase}; BIN_NEW=${BIN_NEW:-$D/bin-singlecopy}; RT_BASE=${RT_BASE:-$D/rt-scbase}; RT_NEW=${RT_NEW:-$D/rt-singlecopy}
|
|
CAP=/data/leleka-e2e/sm120/capture/night5-long-256k
|
|
INV=$SC/tools/ram-inventory.sh
|
|
STAMPS=$SC/stamps
|
|
PHASES=${PHASES:-"probe cold id e2e"}
|
|
BLOCKS=${BLOCKS:-6}
|
|
ARMS_SET=${ARMS_SET:-"base sparse file"}
|
|
RUN_TAG=${RUN_TAG:-}
|
|
SESSION_ARGS="--turns 5 --target-tokens 245000 --max-output 300 --min-final-tokens 200000"
|
|
CAP_MIB=6144
|
|
GPU_BUDGET=32819404800
|
|
MODELLOCK=$G/MODEL.lock
|
|
mkdir -p "$OUTR" "$STAMPS"; chmod 700 "$STAMPS"
|
|
export LD_LIBRARY_PATH=$HOME/cuda-toolkits/cublas-12.9.1.4/lib:$HOME/cuda-toolkits/13.2.2/lib64:${LD_LIBRARY_PATH:-}
|
|
|
|
# ---- guards -------------------------------------------------------------------------------------------------------------------
|
|
for f in "$UP" "$D/tools/long-session.py" "$SC/tools/run-e2e.sh" "$BIN_NEW/leleka" "$BIN_NEW/leleka-inference" "$BIN_NEW/leleka-daemon" "$BIN_NEW/leleka-cli" "$BIN_NEW/leleka-api" \
|
|
"$BIN_BASE/leleka-inference" "$BIN_BASE/leleka-daemon" "$BIN_BASE/leleka-cli" "$BIN_BASE/leleka-api" "$KAR" "$SHARD0" "$SHARD1" "$CORPUS/backend-api/src/lib.rs" "$INV"; do
|
|
[ -r "$f" ] || { echo "missing $f" >&2; exit 3; }
|
|
done
|
|
case " $PHASES " in *" id "*) for f in "$RT_BASE" "$RT_NEW" "$D/tools/q_pair.py" "$D/tools/q_lib.py" "$CAP"; do [ -e "$f" ] || { echo "missing $f (id phase)" >&2; exit 3; }; done ;; esac
|
|
"$BIN_NEW/leleka" --help 2>&1 | grep -q "seal-exec" || { echo "$BIN_NEW/leleka has no seal-exec" >&2; exit 3; }
|
|
command -v fincore >/dev/null || { echo "fincore (util-linux) is needed" >&2; exit 3; }
|
|
[ "$(stat -c %s "$KAR")" = "$KAR_BYTES" ] || { echo "$KAR is not $KAR_BYTES bytes" >&2; exit 3; }
|
|
if pgrep -u "$USER" -f 'kar_holder2?\.py' >/dev/null || [ -d "$MODELLOCK" ]; then echo "refusing to start: the holder is running (MODEL.lock/kar_holder): stop it first, its 51.5 GiB memfd and the arms do not fit" >&2; exit 3; fi
|
|
shmem_gib=$(awk '/^Shmem:/{print int($2/1048576)}' /proc/meminfo)
|
|
[ "$shmem_gib" -lt 8 ] || { echo "refusing to start: Shmem is $shmem_gib GiB (a sealed memfd is still resident)" >&2; exit 3; }
|
|
EXTENTS_SHA256=${EXTENTS_SHA256:-7568b1211419a7c10a9b39a86230f75b7fa9c02839e36c9b5f2494ec7af72143} # the pin compiled into the binary (kar_census --hash-extents, 2026-11-02)
|
|
case " $ARMS_SET " in *" file "*)
|
|
if [ "$(stat -c %h "$KAR")" != 1 ] || [ "$(( 0$(stat -c %a "$KAR") & 0222 ))" != 0 ]; then
|
|
echo "the file arm needs the archive as a single-link file without write bits: chmod 0400 $KAR (changes its ctime: old verification stamps of it are void, once)" >&2; exit 3
|
|
fi ;;
|
|
esac
|
|
mkdir "$MODELLOCK" 2>/dev/null || { echo "MODEL.lock is held" >&2; exit 3; }
|
|
take_gpu() { local got=0; for _ in $(seq 1 1080); do if mkdir "$LOCK" 2>/dev/null; then echo "single-copy-ab $1 $(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)"; return 3; }
|
|
if [ -n "$(nvidia-smi --query-compute-apps=pid --format=csv,noheader 2>/dev/null)" ]; then echo "GPU busy, skipping $1"; rm -f "$LOCK/owner"; rmdir "$LOCK" 2>/dev/null; return 4; fi; }
|
|
drop_gpu() { rm -f "$LOCK/owner"; rmdir "$LOCK" 2>/dev/null; }
|
|
trap 'drop_gpu; rmdir "$MODELLOCK" 2>/dev/null' EXIT
|
|
|
|
evict() { # posix_fadvise(DONTNEED) per file: clean pages only, no root
|
|
python3 -I - "$@" <<'PY'
|
|
import os, sys
|
|
for p in sys.argv[1:]:
|
|
try:
|
|
fd = os.open(p, os.O_RDONLY); os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_DONTNEED); os.close(fd)
|
|
except OSError as e:
|
|
print("evict failed", p, e)
|
|
PY
|
|
}
|
|
MODEL_FILES=("$KAR" "$SHARD0" "$SHARD1" "$MTPX" "$A/data/iq3_s/dense.bin")
|
|
resident() { fincore -b -n -o RES "$1" 2>/dev/null | tr -d ' '; }
|
|
sampler() { # $1 output prefix: memsample (5 s) and a full inventory every 60 s
|
|
local i=0
|
|
while sleep 5; do
|
|
i=$((i + 1))
|
|
pid=$(pgrep -u "$USER" -x leleka-inferenc | head -1)
|
|
eng=""; [ -n "$pid" ] && eng=$(awk '/^(RssAnon|RssShmem|RssFile|VmLck):/{printf "%s%s ", $1, $2}' /proc/$pid/status 2>/dev/null)
|
|
echo "$(date -u +%T) $(grep -E "SwapFree|MemAvailable|^Cached|^Shmem:|^AnonPages|^Mlocked|Dirty" /proc/meminfo | tr -s " " | tr "\n" " ") $(head -1 /proc/pressure/io) $(head -1 /proc/pressure/memory) $(awk '/pswpin|pswpout|pgmajfault/{printf "%s=%s ", $1, $2}' /proc/vmstat) ENGINE ${eng:-none}" >> "$1.memsample.txt"
|
|
if [ $((i % 12)) = 0 ]; then bash "$INV" "t+$((i*5))s" "${MODEL_FILES[@]}" >> "$1.inventory.txt" 2>&1; fi
|
|
done
|
|
}
|
|
record() { # $1 file $2 arm $3 tag
|
|
{ echo "arm=$2 tag=$3"; date -u +%FT%TZ; uname -r; nvidia-smi --query-gpu=driver_version --format=csv,noheader
|
|
echo "uptime: $(uptime -p)"; echo "meminfo at start:"; grep -E "MemTotal|MemAvailable|^Cached|^Shmem:|SwapFree" /proc/meminfo; free -g | sed -n 2p
|
|
echo "resident before start: kar=$(resident "$KAR") shard0=$(resident "$SHARD0") shard1=$(resident "$SHARD1")"
|
|
echo "extents_sha256=$EXTENTS_SHA256"; sha256sum "$UP" "$BIN_BASE"/leleka-inference "$BIN_NEW"/leleka "$BIN_NEW"/leleka-inference ${RT_BASE:+"$RT_BASE"} ${RT_NEW:+"$RT_NEW"} 2>/dev/null
|
|
cat "$BIN_BASE/COMMIT.txt" "$BIN_NEW/COMMIT.txt" 2>/dev/null; head -1 /data/leleka-e2e/decode/corpus/MANIFEST.txt
|
|
env | grep -E '^(LELEKA_|STRATA_|E2E_)' | sort; } > "$1"
|
|
}
|
|
seal_cmd() { # $1 arm: prints the seal-exec prefix for base/sparse
|
|
local flag=""; [ "$1" = sparse ] && flag="--sparse-ple"
|
|
echo "$BIN_NEW/leleka seal-exec --file $KAR --expect-bytes $KAR_BYTES $flag --"
|
|
}
|
|
|
|
# ---- phase cold ---------------------------------------------------------------------------------------------------------------
|
|
OC=$OUTR/cold$RUN_TAG
|
|
if [[ " $PHASES " == *" cold "* ]]; then
|
|
mkdir -p "$OC"
|
|
for arm in sparse full sparse full; do
|
|
flag=""; [ $arm = sparse ] && flag="--sparse-ple"
|
|
evict "${MODEL_FILES[@]}"
|
|
echo "== cold $arm $(date -u +%FT%TZ) resident before: kar=$(resident "$KAR")" | tee -a "$OC/cold.txt"
|
|
t0=$(date +%s.%N)
|
|
"$BIN_NEW/leleka" seal-exec --file "$KAR" --expect-bytes $KAR_BYTES $flag -- bash -c 'echo "sealed fd={FD} after $(echo "$(date +%s.%N) - '"$t0"'" | bc) s"; bash '"$INV"' "cold-'"$arm"'-held" '"$(printf '%q ' "${MODEL_FILES[@]}")"'; sleep 1' 2>&1 | tee -a "$OC/cold.txt" | tee -a "$OC/cold-$arm-inventory.txt" | grep -a -E "sealed fd|RAM-INVENTORY|memfd|pagecache|meminfo (Shmem|Cached|MemAvail)|process-sum"
|
|
sleep 5
|
|
done
|
|
fi
|
|
|
|
# ---- phase probe: cost of the existing KAR level-2 decode on the GPU (candidate B/C evidence; no model, a few seconds) -------------------------
|
|
if [[ " $PHASES " == *" probe "* ]]; then
|
|
mkdir -p "$OUTR"
|
|
if take_gpu probe; then
|
|
{ echo "== KAR decode cost probe $(date -u +%FT%TZ) $(sha256sum $SC/tools/kar-probe-test | cut -c1-16)"; nvidia-smi --query-gpu=name,clocks.sm,clocks.mem --format=csv,noheader
|
|
"$SC/tools/kar-probe-test" --ignored --nocapture kar_levels_expert_cost_probe 2>&1 | grep -a -E "KAR_PROBE|test result|panicked|error" ; } | tee -a "$OUTR/kar-probe.txt"
|
|
drop_gpu
|
|
fi
|
|
fi
|
|
|
|
# ---- phase id: teacher-forced replay (bitwise identity) ----------------------------------------------------------------------------
|
|
OI=$OUTR/id$RUN_TAG
|
|
id_env() {
|
|
export LELEKA_STRA169_KAR_PROVENANCE=$A/qwen-iq3-s-l2-v4.kar.provenance.json LELEKA_STRA169_IQ3S_SHARD0=$SHARD0 LELEKA_STRA169_IQ3S_SHARD1=$SHARD1
|
|
export LELEKA_STRA169_MTP_PACK=$A/data/mtp-rt LELEKA_STRA169_MTP_STAGING=$G/mtp-staging-own LELEKA_ORIGINAL_SERVE_BUDGET_GIB=30
|
|
export LELEKA_ORIGINAL_SERVE_EXPERT_PER_LAYER=yes LELEKA_ORIGINAL_SERVE_PCIE_FRAC=0.45
|
|
export LELEKA_SMOKE_PROMPT_CACHE=0 LELEKA_SERVE_PROFILE=1 LELEKA_GRAPH_EXEC_REUSE=off
|
|
export LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE=$UP LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS=8000 LELEKA_CHAIN=all
|
|
export LELEKA_ORIGINAL_SERVE_ADAPT_EVERY=4 LELEKA_ORIGINAL_SERVE_SEED=off LELEKA_ORIGINAL_SERVE_CPU_WORKERS=1 LELEKA_SPEC=4 LELEKA_SPEC_SUFFIX=0
|
|
export LELEKA_ORIGINAL_SERVE_RT_DIR=$A/data/mtp-rt
|
|
unset LELEKA_DRAFT_VOCAB LELEKA_SERVE_DRAFT_AFTER_COMMIT LELEKA_PROMPT_EMBED_ALIAS LELEKA_VRAM_LEDGER LELEKA_DENSE_SLAB LELEKA_KAR_SPARSE_EXTENTS_SHA256 LELEKA_SM120_ATTN_DAILY_MTP LELEKA_DRAFT_FUSED_COMMIT LELEKA_DRAFT_ROUND
|
|
}
|
|
id_run() { # $1 arm (base|sparse)
|
|
local arm=$1 label=id-$1 rt=$RT_NEW
|
|
[ "$arm" = base ] && rt=$RT_BASE
|
|
take_gpu "$label" || return $?
|
|
install -d -m 0700 "$G/mtp-staging-own"
|
|
echo "=== $label $(date -u +%FT%TZ)"; free -g | sed -n 2p
|
|
( id_env
|
|
[ "$arm" = sparse ] && export LELEKA_KAR_SPARSE_EXTENTS_SHA256=$EXTENTS_SHA256
|
|
shape="reply@8192/8192!orig!fast!nocluster!store!qpf!gpool!mspan"
|
|
export LELEKA_TRACE_DRAFT=1 LELEKA_ORIGINAL_SERVE_REPLAY=yes LELEKA_BRINGUP_TRACE=1 LELEKA_REPLAY_DIR=$CAP LELEKA_PREFIX_TRACE=1 LELEKA_REPLAY_PREFIX_MIB=6000 LELEKA_TRACE_PREFILL_R=1 LELEKA_TRACE_LOGPROBS=16
|
|
export LELEKA_REPLAY_MAX_NEW=${MAX_NEW:-240} LELEKA_REPLAY_FORCE=1 LELEKA_REPLAY_ARMS="I1=$shape,I2=$shape"
|
|
record "$OI/$label.env" "$arm" "$label"
|
|
sampler "$OI/$label" & SAMP=$!
|
|
flag=""; [ "$arm" = sparse ] && flag="--sparse-ple"
|
|
"$BIN_NEW/leleka" seal-exec --file "$KAR" --expect-bytes $KAR_BYTES $flag -- bash -c 'LELEKA_STRA169_KAR_FD={FD} exec nice -n 5 "$0" --ignored --exact --test-threads=1 --nocapture backend::original_serve_replay::original_serve_replay_smoke' "$rt" > "$OI/$label.full" 2>&1
|
|
echo "rc=$? label=$label"; kill $SAMP 2>/dev/null )
|
|
grep -a -E "^REPLAY #|test result|panicked|FAILED|expert cache [0-9]+ slots|prefix cache budget|leleka-kar-startup" "$OI/$label.full" | cut -c1-300 | tail -14
|
|
grep -a -c "^DRAFT " "$OI/$label.full"
|
|
drop_gpu; sleep 15
|
|
}
|
|
if [[ " $PHASES " == *" id "* ]]; then
|
|
mkdir -p "$OI"; id_run base; id_run sparse
|
|
fi
|
|
|
|
# ---- phase e2e ----------------------------------------------------------------------------------------------------------------
|
|
orders=("0 1 2" "1 2 0" "2 0 1" "2 1 0" "1 0 2" "0 2 1")
|
|
e2e_run() { # $1 tag $2 arm
|
|
local tag=$1 arm=$2
|
|
take_gpu "$tag" || return $?
|
|
echo "=== $tag $(date -u +%FT%TZ)"; free -g | sed -n 2p
|
|
( export E2E_OUT=$OUTR/$tag E2E_ASSETS=$A
|
|
mkdir -p "$E2E_OUT"
|
|
export E2E_BIN=$BIN_NEW; [ "$arm" = base ] && export E2E_BIN=$BIN_BASE
|
|
export LELEKA_BRINGUP_TRACE=1 LELEKA_PREFIX_TRACE=1
|
|
export LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS=auto E2E_GPU_BUDGET=$GPU_BUDGET LELEKA_ORIGINAL_SERVE_PCIE_FRAC=0.45
|
|
local engine_args="--prefix-cache-mib $CAP_MIB --prefix-cache-tail reply --original-prefill-capacity 8192 --prefix-cache-block 8192 --spec-min-p 0"
|
|
export E2E_SAMPLE_S=10 LELEKA_CHAIN=all LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE=$UP LELEKA_ORIGINAL_SERVE_SEED=off
|
|
unset 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_DRAFT_VOCAB E2E_KAR_FILE LELEKA_SM120_ATTN_DAILY_MTP LELEKA_DRAFT_FUSED_COMMIT
|
|
[ "${ROUTE:-}" = 1 ] && export LELEKA_ORIGINAL_SERVE_DUMP_ROUTING=$E2E_OUT/routing.bin # routed experts of every decode window row (prefetch lead-time probe), not part of the A/B
|
|
# a cold start for every arm: the model files are not in the page cache when the arm begins
|
|
evict "${MODEL_FILES[@]}"
|
|
case $arm in
|
|
sparse) engine_args="$engine_args --kar-sparse-extents-sha256 $EXTENTS_SHA256" ;;
|
|
file) export E2E_KAR_FILE=$KAR; engine_args="$engine_args --verify-stamps $STAMPS" ;;
|
|
esac
|
|
export E2E_ENGINE_ARGS=$engine_args
|
|
local FILES; FILES=$(printf '%q ' "${MODEL_FILES[@]}")
|
|
export E2E_RUN_CMD="bash $INV idle $FILES >> $E2E_OUT/inventory-marks.txt 2>&1; python3 -I $D/tools/long-session.py --src $CORPUS $SESSION_ARGS; rc=\$?; bash $INV end $FILES >> $E2E_OUT/inventory-marks.txt 2>&1; exit \$rc"
|
|
record "$E2E_OUT/env-arm.txt" "$arm" "$tag"; echo "engine args: $engine_args" >> "$E2E_OUT/env-arm.txt"
|
|
sampler "$E2E_OUT/run" & SAMP=$!
|
|
t0=$(date +%s.%N); echo "t0=$t0" >> "$E2E_OUT/env-arm.txt"
|
|
runner() { while IFS= read -r l; do printf "%s %s\n" "$(date +%s.%N)" "$l"; done; }
|
|
if [ "$arm" = file ]; then
|
|
bash "$SC/tools/run-e2e.sh" 2>&1 | runner > "$E2E_OUT/job.log"
|
|
else
|
|
flag=""; [ "$arm" = sparse ] && flag="--sparse-ple"
|
|
"$BIN_NEW/leleka" seal-exec --file "$KAR" --expect-bytes $KAR_BYTES $flag -- bash -c 'LELEKA_STRA169_KAR_FD={FD} exec bash "$0"' "$SC/tools/run-e2e.sh" 2>&1 | runner > "$E2E_OUT/job.log"
|
|
fi
|
|
kill $SAMP 2>/dev/null
|
|
grep -a -E "^[0-9.]+ (\{|.*(expert cache|prefix cache budget|ready after|refus|rror|client exit|leleka-kar-startup))" "$E2E_OUT/job.log" | cut -c1-300 | tail -12
|
|
echo "run-e2e done $tag $(date -u +%FT%TZ)" )
|
|
drop_gpu; sleep 15
|
|
}
|
|
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
|
|
p = os.path.join(d, "inference.log")
|
|
log = open(p, errors="replace").read() if os.path.exists(p) else ""
|
|
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" % (len(t), final)
|
|
elif arm != "base" and "prefix cache budget: 6144 MiB" not in log:
|
|
verdict = "INVALID: no 'prefix cache budget: 6144 MiB' in the engine log"
|
|
elif arm == "sparse" and "verify=sparse-extents" not in log:
|
|
verdict = "INVALID: the sparse arm's engine log has no leleka-kar-startup ... verify=sparse-extents line"
|
|
elif arm == "file" and "source=file" not in log:
|
|
verdict = "INVALID: the file arm did not run with source=file"
|
|
else:
|
|
wins, last = [], []
|
|
for ln in log.splitlines():
|
|
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 = "VALID: 5 turns, final-turn input tokens %d; turn-5 window.ple mean %.2f ms over %d windows" % (final, ple, len(w))
|
|
if not w:
|
|
verdict = "INVALID: no turn-5 window lines"
|
|
open(os.path.join(d, "VALIDITY.txt"), "w").write(verdict + "\n")
|
|
print(os.path.basename(d), verdict)
|
|
PY
|
|
}
|
|
if [[ " $PHASES " == *" route "* ]]; then # one extra run that dumps the routing (docs: candidate C prefetch probe); never mixed into the A/B arms
|
|
ROUTE=1 e2e_run "route-sparse$RUN_TAG" sparse && validity "$OUTR/route-sparse$RUN_TAG" sparse
|
|
fi
|
|
if [[ " $PHASES " == *" e2e "* ]]; then
|
|
set -- $ARMS_SET; arms=("$@"); narms=${#arms[@]}
|
|
if [[ " $ARMS_SET " == *" file "* ]]; then
|
|
# one CPU-only pass that records the verification stamps of the shards and the archive (file arm: the start must not hash 138 GB); twice, the second is a stamp hit
|
|
for pass in 1 2; do
|
|
( export LELEKA_RUNTIME_TOKEN=$(head -c 24 /dev/urandom | base64 | tr -d '\n')
|
|
echo "=== stamp seed pass $pass $(date -u +%FT%TZ)"
|
|
"$BIN_NEW/leleka-inference" --listen 127.0.0.1:18766 --token-env LELEKA_RUNTIME_TOKEN --shard0 "$SHARD0" --shard1 "$SHARD1" --gpu 0 --gpu-budget $GPU_BUDGET --context-tokens 262144 \
|
|
--kar-archive-file "$KAR" --kar-provenance "$A/qwen-iq3-s-l2-v4.kar.provenance.json" --verify-only --verify-stamps "$STAMPS" 2>&1
|
|
echo "rc=$? $(date -u +%FT%TZ)" ) | tee -a "$OUTR/seed-stamps.log" | grep -a -E "^===|leleka-kar-startup|^rc=|refus|rror" | cut -c1-300
|
|
evict "${MODEL_FILES[@]}"
|
|
done
|
|
fi
|
|
n=0
|
|
for b in $(seq 1 "$BLOCKS"); do
|
|
ord=(${orders[$(( (b - 1) % 6 ))]})
|
|
for idx in "${ord[@]}"; do
|
|
[ "$idx" -lt "$narms" ] || continue
|
|
if [ -e "$SC/STOP" ]; then echo "STOP file present: ending the A/B early so that the queue can use the GPU"; break 2; fi
|
|
arm=${arms[$idx]}; n=$((n + 1)); tag="b$(printf %02d "$b")-$arm$RUN_TAG"
|
|
e2e_run "$tag" "$arm" || continue
|
|
validity "$OUTR/$tag" "$arm"
|
|
echo "arm done $tag $(date -u +%FT%TZ)"
|
|
done
|
|
done
|
|
fi
|
|
|
|
# ---- summary ------------------------------------------------------------------------------------------------------------------
|
|
OUTR=$OUTR OI=$OI OC=$OC PHASES="$PHASES" python3 -I - <<'PY'
|
|
import glob, json, os, re, statistics as st, sys
|
|
root, oi, oc, phases = os.environ["OUTR"], os.environ["OI"], os.environ["OC"], os.environ["PHASES"].split()
|
|
if "id" in phases:
|
|
print("== identity (teacher-forced replay night5-long-256k; top-16 rows; A/A = arm I2 against I1 of one process)")
|
|
sys.path.insert(0, "/data/leleka-e2e/decode/dt/tools")
|
|
try:
|
|
import q_pair
|
|
logs = {a: os.path.join(oi, "id-%s.full" % a) for a in ("base", "sparse")}
|
|
rows = {a: [q_pair.rows_of(logs[a], i) for i in (0, 1)] for a in logs if os.path.exists(logs[a])}
|
|
res = []
|
|
def cmp(a, b, label):
|
|
n, bad, flips, _ = q_pair.compare(a, b, label); res.append((label, n, bad, flips))
|
|
for a in rows: cmp(rows[a][0], rows[a][1], a + " A/A")
|
|
if len(rows) == 2:
|
|
cmp(rows["base"][0], rows["sparse"][0], "sparse vs base arm I1"); cmp(rows["base"][1], rows["sparse"][1], "sparse vs base arm I2")
|
|
ok = bool(res) and all(n > 0 and bad == 0 and flips == 0 for _, n, bad, flips in res)
|
|
print("IDENTITY rows %s: %s" % ("PASS" if ok else "FAIL or incomplete", "; ".join("%s: common %d different %d flips %d" % r for r in res)))
|
|
except Exception as e:
|
|
print("identity not computed:", e)
|
|
if "e2e" not in phases: sys.exit(0)
|
|
runs = {}
|
|
for d in sorted(glob.glob(os.path.join(root, "b[0-9][0-9]-*"))):
|
|
name = os.path.basename(d); v = os.path.join(d, "VALIDITY.txt")
|
|
if not os.path.exists(v) or not open(v).read().startswith("VALID"):
|
|
print(name, "not used:", open(v).read().strip() if os.path.exists(v) else "no VALIDITY.txt"); continue
|
|
t = json.load(open(os.path.join(d, "long-session.json")))
|
|
r = dict(dec=[x.get("decode_tok_s") or 0.0 for x in t], ttft=[x.get("ttft_s") or 0.0 for x in t], arm=name.split("-", 1)[1].split("-")[0], block=name[1:3])
|
|
env = open(os.path.join(d, "env-arm.txt")).read()
|
|
t0 = re.search(r"^t0=([0-9.]+)", env, re.M); jl = open(os.path.join(d, "job.log"), errors="replace").read().splitlines()
|
|
first = next((float(l.split()[0]) for l in jl if "[run-e2e" in l), None)
|
|
ready = next((float(l.split()[0]) for l in jl if "model ready after" in l), None)
|
|
r["seal_s"] = (first - float(t0.group(1))) if (t0 and first) else None
|
|
r["ready_s"] = (ready - float(t0.group(1))) if (t0 and ready) else None
|
|
m = re.search(r"model ready after (\d+)s", "\n".join(jl)); r["load_s"] = int(m.group(1)) if m else None
|
|
runs[name] = r
|
|
def mean_all(r): return st.mean(r["dec"])
|
|
by = {}
|
|
for k, r in runs.items(): by.setdefault(r["arm"], []).append(k)
|
|
print("== per run: all-turn decode tok/s mean, decode per turn, ttft per turn, seal s (start to run-e2e's first line), engine load s, start to ready s")
|
|
for k, r in runs.items():
|
|
print("%-16s %.1f | %s | ttft %s | seal %s load %s ready %s" % (k, mean_all(r), " ".join("%.1f" % x for x in r["dec"]), " ".join("%.1f" % x for x in r["ttft"]),
|
|
"%.0f" % r["seal_s"] if r["seal_s"] else "-", r["load_s"], "%.0f" % r["ready_s"] if r["ready_s"] else "-"))
|
|
print("== arm means (n, mean, sd) of the all-turn decode tok/s")
|
|
for a, ks in by.items():
|
|
xs = [mean_all(runs[k]) for k in ks]
|
|
print("%-7s n=%d mean %.2f sd %.2f ttft(t1..t5 mean) %s" % (a, len(xs), st.mean(xs), st.stdev(xs) if len(xs) > 1 else 0, " ".join("%.1f" % st.mean(c) for c in zip(*[runs[k]["ttft"] for k in ks]))))
|
|
print("== block-paired differences (same block), tok/s and %")
|
|
for a in ("sparse", "file"):
|
|
diffs = []
|
|
for b in sorted({r["block"] for r in runs.values()}):
|
|
x = [k for k in by.get(a, []) if runs[k]["block"] == b]; y = [k for k in by.get("base", []) if runs[k]["block"] == b]
|
|
if x and y: diffs.append(mean_all(runs[x[0]]) - mean_all(runs[y[0]]))
|
|
if diffs:
|
|
base = st.mean(mean_all(runs[k]) for k in by["base"])
|
|
se = st.stdev(diffs) / len(diffs) ** 0.5 if len(diffs) > 1 else float("nan")
|
|
print("%s - base: %s | mean %+.2f tok/s (%+.2f %%) se %.2f, n=%d blocks, %d faster" % (a, " ".join("%+.1f" % x for x in diffs), st.mean(diffs), 100 * st.mean(diffs) / base, se, len(diffs), sum(1 for x in diffs if x > 0)))
|
|
print("== RAM: system Shmem / MemAvailable at the last sample with an engine, and the inventory marks (idle after READY, end after turn 5)")
|
|
for k in runs:
|
|
f = os.path.join(root, k, "run.memsample.txt")
|
|
if os.path.exists(f):
|
|
ls = [l for l in open(f, errors="replace") if "MemAvailable" in l]
|
|
if ls:
|
|
l = ls[-1]; g = lambda n: next((int(x) for x in re.findall(n + r":?\s*(\d+)", l)), 0) / 1048576
|
|
sw = [int(x) for ln in (ls[0], l) for x in re.findall(r"pswp(?:in|out)=(\d+)", ln)]
|
|
print("%-16s Shmem %.2f MemAvailable %.2f Cached %.2f AnonPages %.2f Mlocked %.2f GiB swapped pages %s" % (k, g("Shmem"), g("MemAvailable"), g("Cached"), g("AnonPages"), g("Mlocked"), (sw[2]-sw[0]+sw[3]-sw[1]) if len(sw)==4 else "?"))
|
|
m = os.path.join(root, k, "inventory-marks.txt")
|
|
if os.path.exists(m):
|
|
for ln in open(m, errors="replace"):
|
|
if ln.startswith(("== RAM-INVENTORY", "process pid", "memfd ", "process-sum", "pagecache", "model ", "meminfo MemAvailable", "meminfo Shmem")): print(" " + ln.rstrip()[:200])
|
|
PY
|
|
sha256sum "$OUTR"/*/long-session.json "$OI"/*.full 2>/dev/null | head -60
|
|
date -u +%FT%TZ
|