diff --git a/docs/experiments/vram-footprint-5090.md b/docs/experiments/vram-footprint-5090.md new file mode 100644 index 00000000..bd7ceded --- /dev/null +++ b/docs/experiments/vram-footprint-5090.md @@ -0,0 +1,88 @@ +# 5090 fixed VRAM footprint: where ours spends 2.2 GiB more than vanilla, and what was reclaimed (claude/slots-footprint, STRA-245) + +Date 2026-10-29. RTX 5090 (32 GB, CUDA reports 32,110 MiB, nvidia-smi 32,607 MiB), frozen corpus, upstream profile. Base = `claude/speed-train` 47d2d389 (`bin-speedtrain`). +Sources: `runs/speedtrain-ab/speedtrain-noseed-r3/inference.log` (ours, `DBG vram`, `DBG memory stage`, `leleka-memory` load ledger) and `runs/speedtrain-ab/v-def-r2/engine.log` (vanilla 0.2.6). +Labels: M measured in those logs, E estimate, U unverified. Nothing below is a performance claim; the A/B job is `scripts/e2e/decode/slots-footprint-ab.sh`. + +## 1. Result + +| item | commit | VRAM freed | expert slots | status | +| --- | --- | ---: | ---: | --- | +| driver rounding of the ~700 dense weight buffers (0.5-10 MiB each, 2 MiB granule): pack into 64 MiB slabs | 8c9748a3 | 688 MiB minus slab tails (E: 600-650) | +310 (E, +6 or +7 quota steps of 48) | default ON, `LELEKA_DENSE_SLAB=0` rolls back | +| decode reserve 300 -> 130 MiB (free at decode 563 -> 316 MiB; vanilla runs down to 315) | 981c7aad | 170 MiB | +87 (E, +1 or +2 steps) | default | +| prompt-path token table aliased onto the native embedding's mapped host copy (a second copy sits in VRAM and in pinned RAM) | this branch, last code commit | 324 MiB VRAM + 322 MiB pinned RAM | +166 (E) | EXPERIMENTAL, `LELEKA_PROMPT_EMBED_ALIAS=1`, own A/B arm and identity arm | +| per-call-site allocation ledger, low-water mark | bea07c3d | diagnostic | 0 | `LELEKA_VRAM_LEDGER=1` | +| total of the three reductions | | about 1.2 GiB | about +560 (11,280 -> about 11,840) vs vanilla's 12,575 | slots are read from the log of the first A/B arm | + +Greedy identity: a slot count change moves expert placement, and GPU-resident experts round differently from CPU ones (`bench/results/2026-09-27-cache-parity`), so equal slot counts are the only +valid identity comparison. `scripts/e2e/decode/slots-id.sh` replays the 256k capture with a static tier and a fixed `EXPERT_SLOTS=8000` on the base and the new build and requires zero flips and +bitwise-equal top-16 logprobs. The slab and the alias move buffers only; the reserve moves the cache size only. + +## 2. The account (M) + +Ours, MiB, driver-seen (`dev driver`) against what the owners accounted (`dev acct`); free VRAM is `cuMemGetInfo`: + +| stage | driver | accounted | driver minus accounted | +| --- | ---: | ---: | ---: | +| context before the stack opens (32,110 - 31,603 free) | 507 | | | +| token embedding table (prompt path, VRAM copy) | 324.0 | 322.1 | 1.9 | +| native head (Q5_K, 497 MiB) + native embedding (mapped host copy, 0 VRAM) | 506.0 | 497.3 | 8.7 | +| KAR PLE row cache | 64.0 | 64.0 | 0 | +| dense weights | 4,578.0 | 3,890.0 | **688.0** | +| MoE arena cache (stream-K workspace, prompt device buffers, group-bank modules) | 944.0 | 818.0 | 126.0 | +| prompt executor + MTP drafter (MTP bank 816, 12 resident QSA layers 401, prompt stage 264, ring, scratch) | 2,092.0 | 2,034.8 | 57.2 | +| fixed before the cache | 8,508 | 7,626 | **882** | +| free before the cache | 23,093 | | | +| expert cache, 11,280 slots (1.952 MiB each, 48 per quota step = 93.7 MiB) | 22,016 | 22,014 | 2 | +| free after the cache (reserve 700 + 300 = 1,000, plus 77 of quota rounding) | 1,077 | | | +| per-request verifier assembly at decode | 514 | | | +| free at decode (and the lowest the card ever had: nvidia-smi 31,548 of 32,607 used, every turn, 10 s samples) | 563 | | | + +Vanilla (same card, same model): 24.77 GiB (25,364 MiB) free when it sizes the cache; weights 1,466 + 2,019 native projections = 3,485, MTP layer 835, native Q5_K head 497, token table in mapped +host memory (0); cache 12,575 slots (23.87 GiB) with 700 + 218 reserved; 389 MiB free after loading everything, 315 after the window captures. +Ours left 23,093 MiB free before the cache against vanilla's 25,364: 2,271 MiB less, which is the -1,295 slots. + +What the 2,271 MiB is, as far as the logs tell (E where marked): + +* 882 MiB (39 %) is not data: **the driver reserves more than was asked.** The 322.1 MiB token table took 324.0, a 3 MiB buffer takes 4 MiB on the laptop (`scripts/dev/alloc-granularity-probe.py`: + 4 KiB..1 MiB take their size, 3 MiB takes 4, 2.5 MiB takes 4). Allocations above 1 MiB are rounded to a multiple of 2 MiB; ~700 dense matrices lose about 1 MiB each. The parity audit listed the 688 MiB of the + dense stage as "unaccounted"; it is this. The whole 882 MiB is a mix of that rounding (dense, MoE arena buffers, the 36 GDN mirrors of 3 MiB each) and module residency (E: the group-bank kernels). +* 324 MiB (14 %) is a second copy of the token table. `OriginalPromptEmbedding::load` and `OriginalNativeOutput::load(.., true)` both stream `GlobalRole::TokenEmbedding` (the same IQ4_XS tensor, + 248,320 rows x 1,360 B); the second one is already a pinned host mapping the decode gather reads over PCIe (`shmem +321.9 MiB`). Vanilla keeps one. +* 64 MiB: the KAR PLE row cache; vanilla keeps PLE in RAM. +* about 1.0 GiB (E) is the prompt executor / MoE arena / MTP side against vanilla's equivalents (vanilla borrows its prompt buffers from 2,089 cache slots, 3.98 GiB; ours borrows 2,238 slots for the + prefill arena only and keeps the 818 MiB MoE arena and 264 MiB prompt stage resident). The per-site ledger is what splits this; it was not available before this branch. + +Reserve: at decode ours has 563 MiB free (a verifier assembly of 514 out of the 1,077 left by the cache). Vanilla runs with 389 MiB at the start of a request and 315 after its window captures, and the +full 5 x 245k session never took ours below 563 (nvidia-smi at 10 s, all four ours arms). The #2065 warning (below 512 MiB the Windows driver can page) does not apply to the Linux server; the laptop profile +sets its own `DECODE_RESERVE_MIB` (1024) and keeps it. + +## 3. What each commit does + +* `bea07c3d` `LELEKA_VRAM_LEDGER=1`: every `Context::allocate` is recorded by call site (innermost workspace frames), freed on release, and printed as a delta at each opening stage and at the decode notes, + with the bytes the driver is estimated to reserve. `DBG vram` lines now show the lowest free VRAM seen, and a "decode end before disassemble" note reads the card after the graph pools exist. +* `8c9748a3` `SlabAllocator`/`DeviceSlice` in `leleka-cuda-driver`; `DenseWeightCache` allocates its weights through it. Requests up to 16 MiB are placed first-fit in 64 MiB slabs, 512-byte aligned; + larger keep their own allocation. `DeviceBuffer` gained a `borrowed` flag (an alias frees nothing and is not charged). Tests: placement (aligned, non-overlapping, in-slab, hole filling, direct limit), a + model of the dense mix that must save the rounding, and a CUDA test that reads every view back (passes on the RTX 3080 laptop). +* `981c7aad` `ExpertTierConfig::decode_reserve_mib` 300 -> 130, `decode_headroom_mib()` states the arithmetic (700 + 130 - 514 = 316 >= 315) and a startup warning fires for operator values below it. +* the alias commit: `OriginalNativeEmbed::table_alias()` (a borrowed `DeviceBuffer` over the mapped host copy, not charged), `OriginalPromptEmbedding::alias_native`, native head/embedding opened first. Off by default: + the MTP drafter gathers one row per draft step over PCIe, in a graph that runs beside the expert staging traffic, and a latency of tens of microseconds per row could cost what 166 slots gain (E: the slot gap + as a whole is 0.2-0.6 ms/token in the parity audit). It has its own A/B arm and identity arm. + +## 4. Not done, and why (the next candidates, all need the ledger run first) + +| candidate | size (E) | why not now | +| --- | ---: | --- | +| carve the prompt-only buffers (MoE arena stream-K workspace and prompt device buffers, `kv.prompt_stage` 264 MiB) from the lent slots as vanilla does | 0.5-0.9 GiB, +250..450 slots | needs the per-site sizes; every lent MiB is refilled after the prefill (307-419 ms per request for 4.2 GiB), so the TTFT cost must be measured | +| the 36 GDN mirrors (3 MiB each take 4), the QSA/GDN scratch and the MoE arena buffers through the slab | 40-120 MiB | same mechanism as the dense slab, sizes from the ledger | +| per-layer quota granularity: up to 93 MiB (average 47 MiB, 24 slots) of the cache is the remainder that does not make a full 48-slot step | 0-48 slots | the slot table indexes layers as `layer * quota`; uneven quotas change the table | +| a smaller prefill loan (ours 2,238 slots against vanilla's 2,089) | 0 VRAM, shorter refill | not a footprint item | + +## 5. Not verified + +* Everything about 5090 behaviour: no GPU run was possible (the queue belongs to the decode-tail DEV). The slab and alias were exercised only on the RTX 3080 laptop with unit/CUDA tests; the sealed sm_120 kernels cannot load there, + so `native_embed_table_alias_*` (ignored) has to be run on the server. +* That the 5090 driver rounds like the laptop's: the token table (322.1 -> 324.0) and the sum 688/126/57 agree, the dense stage after this change will show it (the dense summary line and the ledger). +* The slot gain is arithmetic from the log (1.952 MiB per slot, 48-slot quota steps), not a measurement. +* That 316 MiB free at decode is safe for the whole 256k session (vanilla's floor is the only evidence). The A/B job samples the card every 100 ms and prints the lowest free value per arm. +* That the alias does not slow the drafter. diff --git a/scripts/e2e/decode/slots-footprint-ab.sh b/scripts/e2e/decode/slots-footprint-ab.sh new file mode 100644 index 00000000..634acdcd --- /dev/null +++ b/scripts/e2e/decode/slots-footprint-ab.sh @@ -0,0 +1,214 @@ +#!/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-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). +# 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 +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=32212254720 + 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-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/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" + 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-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 diff --git a/scripts/e2e/decode/slots-id.sh b/scripts/e2e/decode/slots-id.sh new file mode 100644 index 00000000..e6268787 --- /dev/null +++ b/scripts/e2e/decode/slots-id.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# STRA-245 slots-footprint: greedy/logprob identity gate of the fixed-VRAM-footprint reductions (claude/slots-footprint) against the speed-train base. +# HOLDER JOB (copy of dt-id2.sh): teacher-forced replay of the 256k-class capture night5-long-256k (5 requests, recorded replies, decode capped at 48 tokens each), production shape, +# top-16 logprobs of every row, STATIC tier (ADAPT_EVERY=0) and an EQUAL FIXED slot count (EXPERT_SLOTS=8000, per-layer sized: the cache is capped at 8000 x the largest blob, +# which both builds can hold, so the placement is the same 11,xxx-independent quota in both). The footprint changes only move buffers; they must not move a single logit: +# p1 base rt-speedtrain (claude/speed-train 47d2d389) two identical arms I1 I2 (the A/A noise floor, expected 0) +# p2 slots rt-slots, defaults (dense slabs ON, decode reserve 130) two arms +# p3 alias rt-slots + LELEKA_PROMPT_EMBED_ALIAS=1 (prompt table on the mapped host copy) two arms +# Then q_pair across processes: every comparison must report 0 flips and max |dlogprob| 0 (bitwise): the kernels read the same bytes in the same order. +# Install: cp scripts/e2e/decode/slots-id.sh /data/leleka-e2e/decode/dt/jobs/slots-id.sh; stub in ~/work/gpu-runs/holder2/jobs/slots-id.sh (exec bash that file); one line in jobs/PRIORITY. +set -uo pipefail +LOCK=/data/leleka-e2e/gpu.lock +D=/data/leleka-e2e/decode/dt +O=/data/leleka-e2e/runs/slots-footprint-id +mkdir -p $O +export LD_LIBRARY_PATH=$HOME/cuda-toolkits/cublas-12.9.1.4/lib:$HOME/cuda-toolkits/13.2.2/lib64:${LD_LIBRARY_PATH:-} +A=$HOME/leleka-gates/assets +G=$HOME/work/gpu-runs +CAP=/data/leleka-e2e/sm120/capture +export LELEKA_STRA169_KAR_PROVENANCE=$A/qwen-iq3-s-l2-v4.kar.provenance.json +export LELEKA_STRA169_IQ3S_SHARD0=$A/model/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00001-of-00002.gguf +export LELEKA_STRA169_IQ3S_SHARD1=$A/model/Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00002-of-00002.gguf +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.55 +export LELEKA_SMOKE_PROMPT_CACHE=0 LELEKA_SERVE_PROFILE=1 LELEKA_GRAPH_EXEC_REUSE=off +export LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE=/data/leleka-e2e/decode/assets/expert-profile-upstream.bin +export LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS=8000 LELEKA_CHAIN=all +export LELEKA_ORIGINAL_SERVE_ADAPT_EVERY=0 LELEKA_ORIGINAL_SERVE_SEED=off LELEKA_ORIGINAL_SERVE_CPU_WORKERS=1 LELEKA_SPEC=4 LELEKA_SPEC_SUFFIX=0 +sha256sum $D/rt-speedtrain $D/rt-slots +shape="reply@8192/8192!orig!fast!nocluster!store!qpf!gpool!mspan" +run() { # label bin extra-env arms + BIN=$D/$2 + got=0 + for i in $(seq 1 1080); do + if mkdir $LOCK 2>/dev/null; then echo "DEV slots-footprint identity $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; } + avail=$(awk '/MemAvailable/{print int($2/1048576)}' /proc/meminfo); echo "=== $1 bin=$2 extra=[$3] MemAvailable GiB: $avail"; free -g | sed -n 2,3p + if [ "$avail" -lt 60 ]; then echo "abort: less than 60 GiB available"; rm -f $LOCK/owner; rmdir $LOCK; return 4; fi + date -u +%FT%TZ + env $3 LELEKA_ORIGINAL_SERVE_REPLAY=yes LELEKA_BRINGUP_TRACE=1 LELEKA_REPLAY_DIR=$CAP/night5-long-256k LELEKA_PREFIX_TRACE=1 LELEKA_REPLAY_PREFIX_MIB=6000 LELEKA_TRACE_PREFILL_R=1 LELEKA_TRACE_LOGPROBS=16 \ + LELEKA_REPLAY_MAX_NEW=48 LELEKA_REPLAY_FORCE=1 LELEKA_REPLAY_ARMS=$4 \ + nice -n 5 $BIN --ignored --exact --test-threads=1 --nocapture backend::original_serve_replay::original_serve_replay_smoke > $O/$1.full 2>&1 + echo "rc=$? label=$1"; date -u +%FT%TZ + grep -a -E "^REPLAY|test result|panicked|FAILED|expert cache [0-9]+ slots|leleka-serve dense weights" $O/$1.full | cut -c1-300 | tail -10 + rm -f $LOCK/owner; rmdir $LOCK 2>/dev/null + sleep 15 +} +run idBase rt-speedtrain "LELEKA_X=1" "I1=$shape,I2=$shape" +run idSlots rt-slots "LELEKA_X=1" "I1=$shape,I2=$shape" +run idAlias rt-slots "LELEKA_PROMPT_EMBED_ALIAS=1" "I1=$shape,I2=$shape" +T=$D/tools +for p in idBase idSlots idAlias; do echo "== q_tail_gate $p"; python3 $T/q_tail_gate.py $O/$p.full $CAP/night5-long-256k 2>&1 | tail -12; done +python3 - <