From f9bc7dd8a437edc68096965a59f15c361c61467b Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Thu, 12 Nov 2026 23:24:10 +0100 Subject: [PATCH] Stage 6d: teacher-forced multi-arm replay of a real Codex session for speculation knobs (accept-knobs-replay.sh, summary with A/A floor, identity gate for the English draft vocabulary) Co-Authored-By: Claude Sonnet 5.5 --- scripts/e2e/decode/accept-knobs-identity.sh | 99 +++++++++++++++++++++ scripts/e2e/decode/accept-knobs-replay.sh | 58 ++++++++++++ scripts/e2e/decode/accept-knobs-summary.py | 75 ++++++++++++++++ 3 files changed, 232 insertions(+) create mode 100644 scripts/e2e/decode/accept-knobs-identity.sh create mode 100644 scripts/e2e/decode/accept-knobs-replay.sh create mode 100644 scripts/e2e/decode/accept-knobs-summary.py diff --git a/scripts/e2e/decode/accept-knobs-identity.sh b/scripts/e2e/decode/accept-knobs-identity.sh new file mode 100644 index 00000000..f50fcbe3 --- /dev/null +++ b/scripts/e2e/decode/accept-knobs-identity.sh @@ -0,0 +1,99 @@ +#!/usr/bin/env bash +# Stage 6d: copy of verify-switches-identity.sh for drafter knobs (LELEKA_DRAFT_VOCAB=en ...): the verify window is FIXED (LELEKA_SPEC=4, suffix off), so the windows do not depend on timing and +# the rows of a common context are comparable; the draft trace (idcmp) differs by design for a knob that changes the drafts. Inputs in the task directory $T (MANIFEST.sha256). Header of the original: +# draft-round identity gate (bitwise): teacher-forced replay of the 256k-class capture night5-long-256k (5 requests, recorded replies, decode capped at MAX_NEW forced tokens +# each), production shape, top-16 logprobs of every row and the draft trace (LELEKA_TRACE_DRAFT=1: every draft's ids and IEEE bits of its probabilities), seed OFF, ONE test binary +# (dt/$ID_BIN) for all processes, one process per setting, two arms in each (I1 I2: the A/A floor). HOLDER JOB (copy of footprint3-id.sh). +# ID_BIN test binary directory name under /data/leleka-e2e/decode/dt (required) +# P1_ENV extra env of the reference process (default: nothing) +# P2_ENV extra env of the changed process (required) +# P3_ENV .. P9_ENV optional further processes (verify-switches-identity.sh: one setting each) +# ID_OUT output directory (required) MAX_NEW (default 240) ADAPT (default 4: the adaptive tier swaps, as dt-id2) +# SKIP_P1=1 reuse $ID_OUT/idP1.full of an earlier job (same binary, same environment) as the reference instead of running it again +# ~10 GPU-min a process. Verdict: q_pair (top-16 logprob rows, all common rows must be identical) and draftround-idcmp.py (the draft trace lines must be identical). +set -uo pipefail +LOCK=/data/leleka-e2e/gpu.lock +D=${D:-/data/leleka-e2e/decode/dt} # binaries (dt/), dt/tools, dt/scripts; override to run from another tree +DR=${DR:-/data/leleka-e2e/draft-round} # tools + MANIFEST.sha256; override to run from another tree +O=${ID_OUT:?ID_OUT} +ID_BIN=${ID_BIN:?ID_BIN} +MAX_NEW=${MAX_NEW:-240} +ADAPT=${ADAPT:-4} +mkdir -p "$O" +( cd / && sha256sum --quiet -c "$DR/MANIFEST.sha256" ) || { echo "draft-round: MANIFEST.sha256 check failed" >&2; exit 3; } +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 +T=${ACCEPT_ROOT:-/data/leleka-e2e/prefill-latency/accept-knobs} +( cd "$T" && sha256sum --quiet -c MANIFEST.sha256 ) || { echo "accept-knobs inputs do not match MANIFEST.sha256" >&2; exit 3; } +CAP=$T/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.45 +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_RT_DIR=$A/data/mtp-rt +export LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS=8000 LELEKA_CHAIN=all +export LELEKA_ORIGINAL_SERVE_ADAPT_EVERY=$ADAPT LELEKA_ORIGINAL_SERVE_SEED=off LELEKA_ORIGINAL_SERVE_CPU_WORKERS=1 LELEKA_SPEC=4 LELEKA_SPEC_SUFFIX=0 +unset LELEKA_SERVE_DRAFT_AFTER_COMMIT LELEKA_PROMPT_EMBED_ALIAS LELEKA_VRAM_LEDGER LELEKA_DENSE_SLAB LELEKA_FOOTPRINT_LEGACY LELEKA_SM120_ATTN_DAILY_MTP LELEKA_DRAFT_FUSED_COMMIT LELEKA_DRAFT_ROUND +for f in $D/$ID_BIN $D/tools/q_pair.py $D/tools/q_tail_gate.py $DR/tools/draftround-idcmp.py $CAP/night5-long-256k; do + [ -e "$f" ] || { echo "missing $f" >&2; exit 3; } +done +sha256sum $D/$ID_BIN | tee $O/rt.sha256 +shape="reply@8192/8192!orig!fast!nocluster!store!qpf!gpool!mspan" +# The holder's memfd may be the sparse PLE-only one (leleka seal-exec --sparse-ple, 14.9 GiB of 51.5): the test binary +# must then verify the extents (LELEKA_KAR_SPARSE_EXTENTS_SHA256) instead of reading the whole archive, which would +# touch every hole and fill the holder. Detected from the allocated size of the descriptor; a full holder keeps the old path. +unset LELEKA_KAR_SPARSE_EXTENTS_SHA256 +if [ -n "${LELEKA_STRA169_KAR_FD:-}" ] && [ -e "/proc/self/fd/$LELEKA_STRA169_KAR_FD" ]; then + read -r kar_size kar_blocks < <(stat -L -c '%s %b' "/proc/self/fd/$LELEKA_STRA169_KAR_FD") + if [ $((kar_blocks * 512)) -lt $((kar_size / 2)) ]; then + export LELEKA_KAR_SPARSE_EXTENTS_SHA256=${EXTENTS_SHA256:-7568b1211419a7c10a9b39a86230f75b7fa9c02839e36c9b5f2494ec7af72143} + echo "sparse holder memfd detected ($kar_blocks blocks of 512 B for $kar_size bytes): verifying the extents" + fi +fi +run() { # label extra-env + got=0 + for i in $(seq 1 1080); do + if mkdir $LOCK 2>/dev/null; then echo "draft-round 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 extra=[$2] MemAvailable GiB: $avail" + 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 $2 LELEKA_TRACE_DRAFT=1 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=$MAX_NEW LELEKA_REPLAY_FORCE=1 LELEKA_REPLAY_ARMS="I1=$shape,I2=$shape" \ + nice -n 5 $D/$ID_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" $O/$1.full | cut -c1-200 | tail -14 + grep -a -c "^DRAFT " $O/$1.full + rm -f $LOCK/owner; rmdir $LOCK 2>/dev/null + sleep 15 +} +if [ "${SKIP_P1:-0}" = 1 ]; then [ -s "$O/idP1.full" ] || { echo "SKIP_P1 set but $O/idP1.full is missing" >&2; exit 3; }; else run idP1 "${P1_ENV:-LELEKA_X=1}"; fi +run idP2 "${P2_ENV:?P2_ENV}" +PROCS="idP1 idP2" +for k in 3 4 5 6 7 8 9; do # further processes: P3_ENV .. P9_ENV, one setting each, in order (a gap ends the list) + var="P${k}_ENV"; [ -n "${!var:-}" ] || break + run idP$k "${!var}"; PROCS="$PROCS idP$k" +done +T=$D/tools +for p in $PROCS; do echo "== q_tail_gate $p"; python3 $T/q_tail_gate.py $O/$p.full $CAP/night5-long-256k 2>&1 | tail -8; done +python3 - <&2; exit 3; } +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 +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_SMOKE_PROMPT_CACHE=0 LELEKA_SERVE_PROFILE=1 LELEKA_GRAPH_EXEC_REUSE=off +export LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE=$T/assets/expert-profile-upstream.bin +export LELEKA_ORIGINAL_SERVE_RT_DIR=$A/data/mtp-rt LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS=auto +# the release profile's engine_env, verbatim (tier layout, PCIe share, seed, sm_120 kernels, graph reuse, ...) +eval "$(python3 -I -c 'import json,shlex,sys; [print("export %s=%s" % (k, shlex.quote(str(v)))) for k, v in json.load(open(sys.argv[1]))["engine_env"].items()]' "$T/profile-rtx5090-32g.json")" +unset LELEKA_SPEC LELEKA_SPEC_ADAPTIVE LELEKA_SPEC_SUFFIX LELEKA_ORIGINAL_SERVE_ADAPT_EVERY LELEKA_SERVE_DRAFT_AFTER_COMMIT LELEKA_PROMPT_EMBED_ALIAS LELEKA_VRAM_LEDGER LELEKA_DENSE_SLAB LELEKA_FOOTPRINT_LEGACY LELEKA_DRAFT_VOCAB +CAPDIR=$T/capture/cap-s3 +shape="reply@8192/8192!orig!fast!nocluster!store!qpf!gpool!mspan" +# the holder's memfd may be the sparse PLE-only one: the test binary verifies the extents instead of the whole archive +unset LELEKA_KAR_SPARSE_EXTENTS_SHA256 +if [ -n "${LELEKA_STRA169_KAR_FD:-}" ] && [ -e "/proc/self/fd/$LELEKA_STRA169_KAR_FD" ]; then + read -r kar_size kar_blocks < <(stat -L -c '%s %b' "/proc/self/fd/$LELEKA_STRA169_KAR_FD") + if [ $((kar_blocks * 512)) -lt $((kar_size / 2)) ]; then export LELEKA_KAR_SPARSE_EXTENTS_SHA256=${EXTENTS_SHA256:-7568b1211419a7c10a9b39a86230f75b7fa9c02839e36c9b5f2494ec7af72143}; fi +fi +echo "arms=$ARMS reps=$REPS max_new=$MAX_NEW envx=[${ENVX:-}] bin=$BIN" | tee "$O/args.txt" +env | grep -E '^(LELEKA|STRATA)_' | grep -v -E 'KAR_(FD|PROVENANCE)' | sort >"$O/env.txt" +got=0 +for _ in $(seq 1 2160); do + if mkdir $LOCK 2>/dev/null; then echo "accept-knobs replay $(date -u +%FT%TZ) $O" >$LOCK/owner; got=1; break; fi + sleep 5 +done +[ $got = 1 ] || { echo "GPU lock held by: $(cat $LOCK/owner 2>/dev/null)"; exit 3; } +avail=$(awk '/MemAvailable/{print int($2/1048576)}' /proc/meminfo); echo "MemAvailable GiB: $avail" +if [ "$avail" -lt 60 ]; then echo "abort: less than 60 GiB available"; rm -f $LOCK/owner; rmdir $LOCK; exit 4; fi +date -u +%FT%TZ +env ${ENVX:-LELEKA_X=1} LELEKA_ORIGINAL_SERVE_REPLAY=yes LELEKA_BRINGUP_TRACE=1 LELEKA_REPLAY_DIR=$CAPDIR LELEKA_PREFIX_TRACE=1 LELEKA_REPLAY_PREFIX_MIB=6000 \ + LELEKA_REPLAY_MAX_NEW=$MAX_NEW LELEKA_REPLAY_FORCE=1 LELEKA_REPLAY_ARMS="W=$shape" LELEKA_REPLAY_REPS=$REPS LELEKA_REPLAY_SPEC_MIN_P=0 \ + LELEKA_SPEC_ARMS="$ARMS" LELEKA_SPEC_STATS=1 \ + "$T/dt/$BIN" --ignored --exact --test-threads=1 --nocapture backend::original_serve_replay::original_serve_replay_smoke >"$O/replay.full" 2>&1 +echo "rc=$?"; date -u +%FT%TZ +grep -a -E "^REPLAY PASS|test result|panicked|FAILED|expert cache [0-9]+ slots|draft-vocab|draft head over" "$O/replay.full" | cut -c1-240 | tail -60 +rm -f $LOCK/owner; rmdir $LOCK 2>/dev/null +python3 -I "$T/tools/accept-knobs-summary.py" "$O/replay.full" | tee "$O/SUMMARY.txt" diff --git a/scripts/e2e/decode/accept-knobs-summary.py b/scripts/e2e/decode/accept-knobs-summary.py new file mode 100644 index 00000000..c5421f4b --- /dev/null +++ b/scripts/e2e/decode/accept-knobs-summary.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 +"""Per-arm summary of accept-knobs-replay.sh (teacher-forced replay, several speculation policies in one process, identical text for every arm). + +Per arm: tokens, rounds, decode seconds summed over its passes (the warm-up pass is dropped); the passes are rebuilt from the per-request REPLAY lines +(decode_ms to 0.1 ms). Then, paired by repetition against the first arm (the base), the mean difference of tok/s, tokens per round and ms per round in +percent of the base with a 95 % interval (Student t on the repetition differences). The twin arm (the same policy under another label) is the A/A floor: +a knob is read only against it. usage: accept-knobs-summary.py [base-arm] [twin-arm]""" +import re +import statistics as st +import sys + +T95 = {1: 12.706, 2: 4.303, 3: 3.182, 4: 2.776, 5: 2.571, 6: 2.447, 7: 2.365, 8: 2.306, 9: 2.262, 10: 2.228} + + +def read_passes(path): + reqs = {} + pat = re.compile(r"REPLAY #(\d+) pass=(\d+) (\S+) arm=(\S+) .*? produced=(\d+) rounds=(\d+) tok_per_round=\S+ decode_ms=([\d.]+)") + for ln in open(path, errors="replace"): + m = pat.match(ln) + if not m: + continue + _, ps, lab, arm, produced, rounds, ms = m.groups() + r = reqs.setdefault(int(ps), dict(lab=lab, arm=arm, tok=0, sec=0.0, rounds=0)) + r["tok"] += int(produced) + r["sec"] += float(ms) / 1000.0 + r["rounds"] += int(rounds) + return [dict(n=ps, tps=r["tok"] / r["sec"], tpr=r["tok"] / r["rounds"], mpr=1000 * r["sec"] / r["rounds"], **r) for ps, r in sorted(reqs.items())] + + +def paired(rows, by, base, arm, key): + reps = sorted({p["lab"] for p in rows}) + d = [] + for r in reps: + x = [p for p in by[arm] if p["lab"] == r] + y = [p for p in by[base] if p["lab"] == r] + if x and y: + d.append(100.0 * (x[0][key] / y[0][key] - 1.0)) + if len(d) < 2: + return None + se = st.stdev(d) / len(d) ** 0.5 + return st.mean(d), T95.get(len(d) - 1, 2.0) * se, sum(1 for z in d if z > 0), len(d) + + +def main(): + passes = read_passes(sys.argv[1]) + rows = [p for p in passes if p["lab"] != "warm"] + arms = [] + for p in rows: + if p["arm"] not in arms: + arms.append(p["arm"]) + base = sys.argv[2] if len(sys.argv) > 2 else arms[0] + twin = sys.argv[3] if len(sys.argv) > 3 else (arms[1] if len(arms) > 1 else None) + print("passes %d (+%d warm-up), arms %d, base %s, twin (A/A floor) %s" % (len(rows), len(passes) - len(rows), len(arms), base, twin)) + print("%-40s %3s %8s %7s %9s %9s" % ("arm", "n", "tok/s", "sd", "tok/round", "ms/round")) + by = {} + for a in arms: + v = [p for p in rows if p["arm"] == a] + by[a] = v + tok, sec, rd = sum(p["tok"] for p in v), sum(p["sec"] for p in v), sum(p["rounds"] for p in v) + tps = [p["tps"] for p in v] + print("%-40s %3d %8.2f %7.2f %9.3f %9.3f" % (a, len(v), tok / sec, st.pstdev(tps) if len(tps) > 1 else 0.0, tok / rd, 1000 * sec / rd)) + print("\npaired against %s, percent of base, mean (95%% interval), arm better in n of N repetitions" % base) + print("%-40s %-26s %-26s %-26s" % ("arm", "tok/s", "tok/round", "ms/round")) + for a in arms: + if a == base: + continue + cells = [] + for key in ("tps", "tpr", "mpr"): + r = paired(rows, by, base, a, key) + cells.append("n/a" if r is None else "%+.2f (+-%.2f) %d/%d" % (r[0], r[1], r[2], r[3])) + print("%-40s %-26s %-26s %-26s%s" % (a, cells[0], cells[1], cells[2], " <- A/A floor" if a == twin else "")) + + +if __name__ == "__main__": + main()