Files
leleka/scripts/e2e/decode/slots-footprint-ab.sh
T
Pavlo RatushnyiandClaude Sonnet 5.5 5e4c9c9530 models: all model paths point into the work folder (models/leleka-gates, models/deepseek-v41-flash)
Rewrite the 5090 server model paths in 30 repo files (scripts, tools, docs) from the old
locations (/home/para/leleka-gates, $HOME/leleka-gates, /data/models) to
/home/para/work/leleka/models/..., add the AGENTS.md workspace rule and the move record
docs/experiments/models-move.md. Not merged: the smoke test is pending.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-29 19:12:29 +01:00

221 lines
15 KiB
Bash

#!/usr/bin/env bash
# STRA-245 slots-footprint: paired A/B of the fixed-VRAM-footprint reductions (claude/slots-footprint) against the speed-train base, ours vs ours, seed OFF,
# same harness, same frozen corpus, upstream ranked profile, alternating arms. HOLDER JOB (run on rnr5090 under the holder, like speedtrain-ab.sh, which this is a copy of). Install:
# cp scripts/e2e/decode/slots-footprint-ab.sh /data/leleka-e2e/decode/dt/jobs/slots-footprint-ab.sh
# queue stub (~/work/gpu-runs/holder2/jobs/slots-footprint-ab.sh): #!/usr/bin/env bash / exec bash /data/leleka-e2e/decode/dt/jobs/slots-footprint-ab.sh (+ one line in jobs/PRIORITY)
# It takes /data/leleka-e2e/gpu.lock per arm (one arm at a time) and skips an arm when something else uses the GPU. ~12 min an arm; default 4 arms = 2 alternating pairs.
#
# ARMS="base-noseed slots-noseed base-noseed slots-noseed" bash slots-footprint-ab.sh # the order IS the repeat order; this is the default
# ARMS="slots-ledger" bash slots-footprint-ab.sh # the per-call-site VRAM account of the new build (short session), no performance claim
# ARMS="slots-embed-noseed base-noseed slots-embed-noseed" ... # the opt-in token-table alias (LELEKA_PROMPT_EMBED_ALIAS=1)
#
# Arms (the only variable between base and slots is the binary; both seed OFF as in the owner's baseline):
# base-noseed ours, /data/leleka-e2e/decode/dt/bin-speedtrain (claude/speed-train 47d2d389), env of speedtrain-ab.sh seed OFF
# slots-noseed ours, /data/leleka-e2e/decode/dt/bin-slots (claude/slots-footprint), same env, defaults of the new build (dense slabs ON, decode reserve 130 MiB)
# slots-embed-noseed slots-noseed plus LELEKA_PROMPT_EMBED_ALIAS=1 (prompt-path token table aliased onto the mapped host copy: -324 MiB VRAM, -322 MiB pinned RAM; EXPERIMENTAL)
# slots-res130-noseed slots-noseed plus LELEKA_ORIGINAL_SERVE_DECODE_RESERVE_MIB=130 (free VRAM at decode ~316 MiB, +87 slots; opt-in)
# slots-ledger slots-noseed plus LELEKA_VRAM_LEDGER=1 and a short session (2 turns, ~60k tokens): the full allocation account; the ledger takes a backtrace per allocation, so this arm is never a performance arm
# v-def vanilla Strata 0.2.6 as in speedtrain-ab.sh (not in the default ARMS)
# Workload (the only valid one): the FROZEN corpus /data/leleka-e2e/decode/corpus/src/crates (MANIFEST.txt), 5 turns, target 245000 tokens, --max-output 300.
# Validity per run (VALIDITY.txt): no turn failed, 5 turns, final-turn input tokens >= 200000, turn-5 window.ple mean < 5 ms (as speedtrain-ab.sh).
# Footprint per run (FOOTPRINT.txt): the expert-cache slot count, the DBG vram lines (free after each opening stage, at decode, lowest note), the memory ledger table, the
# dense-weights slab line, and the card's peak used memory from a 100 ms nvidia-smi sampler (gpumem.csv; nvidia-smi total 32607 MiB = CUDA total 32110 + 497).
# GPU context budget: E2E_GPU_BUDGET defaults here to 31,300 MiB (the speed-train jobs used 30 GiB). The Context charges allocations (not the driver's rounding) against the budget, so
# slabs that save physical bytes need a budget that leaves the same reserve above them; the cache planner now sizes against min(card free, budget - allocated). Both arms run with the same budget
# (the base build is card-bound at either value). The first slots-footprint run (30 GiB, 7823672f) failed every request with BudgetExceeded at layer 27: no budget room for the lazy buffers.
# Metric: per-turn decode_tok_s of the client, per-turn mean of the repeats, never a single run. Quality: the arms are greedy but the auto-sized caches differ in slot count, so
# placement (and with it GPU-vs-CPU expert rounding) differs: the lossless claim is the static-tier identity job slots-id.sh at an equal fixed slot count, not these arms.
set -uo pipefail
D=/data/leleka-e2e/decode/dt
LOCK=/data/leleka-e2e/gpu.lock
OUTR=/data/leleka-e2e/runs/slots-footprint
CORPUS=/data/leleka-e2e/decode/corpus/src/crates
UP=/data/leleka-e2e/decode/assets/expert-profile-upstream.bin # ranked upstream profile; run-e2e.sh refuses any other digest
RUN_TAG=${RUN_TAG:-} # suffix of the run directories (a rerun next to earlier ones)
ARMS=${ARMS:-"base-noseed slots-noseed base-noseed slots-noseed"}
SESSION_ARGS="--turns 5 --target-tokens 245000 --max-output 300 --min-final-tokens 200000"
for f in "$UP" "$D/tools/long-session.py" "$D/scripts/e2e/run-e2e.sh" "$D/bin-speedtrain/leleka-inference" "$D/bin-slots/leleka-inference" "$CORPUS/backend-api/src/lib.rs" \
"$HOME/work/vanilla-strata/control/bin/strata" "$HOME/.config/strata/settings.json"; do
[ -r "$f" ] || { echo "missing $f" >&2; exit 3; }
done
ours() { # $1 tag, $2 arm
local tag=$1 arm=$2 bin=bin-slots session="$SESSION_ARGS"
case $arm in base-*) bin=bin-speedtrain ;; esac
( export E2E_BIN=$D/$bin E2E_OUT=$OUTR/$tag
mkdir -p "$E2E_OUT"
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_ORIGINAL_SERVE_SEED LELEKA_ORIGINAL_SERVE_SEED_MAX_ROWS LELEKA_SM120_ATTN_DAILY LELEKA_SM120_GU_SWIGLU LELEKA_SM120_SIDE_MIXER LELEKA_SM120_PERF
export LELEKA_ORIGINAL_SERVE_SEED=off
unset LELEKA_PROMPT_EMBED_ALIAS LELEKA_VRAM_LEDGER LELEKA_DENSE_SLAB
case $arm in
base-noseed|slots-noseed) ;;
slots-embed-noseed) export LELEKA_PROMPT_EMBED_ALIAS=1 ;;
slots-res130-noseed) export LELEKA_ORIGINAL_SERVE_DECODE_RESERVE_MIB=130 ;;
slots-ledger) export LELEKA_VRAM_LEDGER=1; session="--turns 2 --target-tokens 60000 --max-output 100 --min-final-tokens 40000" ;;
*) echo "unknown ours arm $arm" >&2; exit 2 ;;
esac
{ echo "arm=$arm tag=$tag"; date -u +%FT%TZ; free -g | sed -n 2p; 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; } >"$E2E_OUT/env-arm.txt"
export E2E_RUN_CMD="python3 -I $D/tools/long-session.py --src $CORPUS $session"
( while sleep 5; do echo "$(date +%T) $(grep -E "SwapFree|MemAvailable|^Cached|Shmem:|Dirty" /proc/meminfo | tr -s " " | tr "
" " ") $(head -1 /proc/pressure/io) $(head -1 /proc/pressure/memory) $(awk "/pswpin|pgmajfault/{printf \"%s=%s \",\$1,\$2}" /proc/vmstat)"; done > "$E2E_OUT/memsample.txt" 2>/dev/null ) & SAMP=$!
( while true; do echo "$(date +%T.%N | cut -c1-12),$(nvidia-smi --query-gpu=memory.used,memory.total --format=csv,noheader,nounits)"; sleep 0.1; done > "$E2E_OUT/gpumem.csv" 2>/dev/null ) & GSAMP=$!
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
kill $SAMP $GSAMP 2>/dev/null
echo "run-e2e done $tag $(date -u +%FT%TZ)" )
}
vanilla() { # $1 tag
local tag=$1
local R=$OUTR/$tag; mkdir -p "$R"
( 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/"
{ echo "arm=v-def tag=$tag"; date -u +%FT%TZ; free -g | sed -n 2p; head -1 /data/leleka-e2e/decode/corpus/MANIFEST.txt; env | grep -E '^(STRATA_|LELEKA_)' | sort; } > "$R/env.txt"
( while sleep 5; do echo "$(date +%T) $(grep -E "SwapFree|MemAvailable|^Cached|Shmem:|Dirty" /proc/meminfo | tr -s " " | tr "
" " ") $(head -1 /proc/pressure/io) $(head -1 /proc/pressure/memory) $(awk "/pswpin|pgmajfault/{printf \"%s=%s \",\$1,\$2}" /proc/vmstat)"; done > "$R/memsample.txt" 2>/dev/null ) & SAMP=$!
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
( while true; do echo "$(date +%T),$(nvidia-smi --query-gpu=temperature.gpu,utilization.gpu,power.draw,clocks.sm,memory.used --format=csv,noheader)" >> "$R/mon.csv"; sleep 5; done ) & MON=$!
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 python3 -I $D/tools/long-session.py --src $CORPUS $SESSION_ARGS > "$R/client.log" 2>&1
echo "session_rc=$?" >> "$R/env.txt"
kill $MON 2>/dev/null
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
kill $SAMP 2>/dev/null
date -u +%FT%TZ >> "$R/env.txt"
cut -c1-300 "$R/client.log" 2>/dev/null )
}
footprint() { # $1 run dir, $2 arm kind: what the arm's VRAM looked like (the numbers the slot count and the reserve are judged by)
local d=$1 kind=$2
{ echo "== $(basename "$d")"
if [ "$kind" = ours ]; then
grep -a -E "expert cache [0-9]+ slots|DBG vram|DBG memory stage|dense weights:|leleka-vram-ledger|WARNING: the VRAM reserves|^ +[-+][0-9.]+ MiB req" "$d/inference.log" | cut -c1-330
else
grep -a -E "expert cache [0-9]+ slots|VRAM free|MiB of VRAM|prompt path borrows" "$d/engine.log" 2>/dev/null | cut -c1-300
fi
python3 -I - "$d" <<'PY'
import csv, os, sys
d = sys.argv[1]
f = os.path.join(d, "gpumem.csv") if os.path.exists(os.path.join(d, "gpumem.csv")) else os.path.join(d, "mon.csv")
used, total = [], 32607
if os.path.exists(f):
for row in csv.reader(open(f, errors="replace")):
try:
used.append(int(row[1].split()[0]))
if len(row) > 2:
total = int(row[2].split()[0])
except Exception:
pass
if used:
print("card peak used %d MiB of %d (nvidia-smi); lowest free %d MiB (CUDA free = this - 497); %d samples" % (max(used), total, total - max(used), len(used)))
PY
} > "$d/FOOTPRINT.txt" 2>&1
tail -3 "$d/FOOTPRINT.txt" | cut -c1-200
}
validity() { # $1 run dir, $2 arm kind (ours|vanilla)
python3 -I - "$1" "$2" <<'PY'
import json, os, re, sys
d, kind = 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 os.path.basename(d).startswith("slots-ledger"):
verdict = "LEDGER-ONLY (not a performance run): %d turns, final-turn input tokens %d" % (len(t), final)
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 kind == "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
open(os.path.join(d, "VALIDITY.txt"), "w").write(verdict + "\n")
print(os.path.basename(d), verdict)
PY
}
n=0
for arm in $ARMS; do
n=$((n + 1)); tag="$arm-r$n$RUN_TAG"
got=0
for _ in $(seq 1 1080); do
if mkdir "$LOCK" 2>/dev/null; then echo "speedtrain-ab $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)"; free -g | sed -n 2p
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
case $arm in
v-def) vanilla "$tag"; kind=vanilla ;;
base-noseed|slots-noseed|slots-embed-noseed|slots-res130-noseed|slots-ledger) ours "$tag" "$arm"; kind=ours ;;
*) echo "unknown arm $arm" >&2; rm -f "$LOCK/owner"; rmdir "$LOCK" 2>/dev/null; exit 2 ;;
esac
validity "$OUTR/$tag" $kind
footprint "$OUTR/$tag" $kind
echo "arm done $tag $(date -u +%FT%TZ)"
rm -f "$LOCK/owner"; rmdir "$LOCK" 2>/dev/null
sleep 15
done
# summary: decode tok/s per turn per VALID run, the per-turn mean of the repeats of each arm, and every ours arm against v-def (per turn and over turns 1-5)
python3 -I - "$OUTR" <<'PY'
import glob, json, os, statistics, sys
root = sys.argv[1]
runs = {}
for d in sorted(glob.glob(os.path.join(root, "*"))):
v = os.path.join(d, "VALIDITY.txt")
if not os.path.exists(v) or not open(v).read().startswith("VALID"):
print(os.path.basename(d), "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")))
runs[os.path.basename(d)] = [x.get("decode_tok_s") or 0.0 for x in t]
for k, v in runs.items():
print(k, " ".join("%.1f" % x for x in v), "mean %.1f" % statistics.mean(v))
by = {}
for k, v in runs.items():
by.setdefault(k.rsplit("-r", 1)[0], []).append(v)
mean = {a: [statistics.mean(c) for c in zip(*vs)] for a, vs in by.items()}
for a, m in sorted(mean.items()):
print("%s (%d runs) per-turn mean: %s all-turn mean %.1f" % (a, len(by[a]), " ".join("%.1f" % x for x in m), statistics.mean(m)))
base = mean.get("base-noseed") or mean.get("v-def")
if base:
for a, m in sorted(mean.items()):
if m is not base:
print("%s minus the base per turn: %s mean %+.1f tok/s (%+.1f %%)" % (a, " ".join("%+.1f" % (x - y) for x, y in zip(m, base)),
statistics.mean(m) - statistics.mean(base), 100 * (statistics.mean(m) / statistics.mean(base) - 1)))
PY