diff --git a/scripts/e2e/decode/cpu-service2-eager-ab.sh b/scripts/e2e/decode/cpu-service2-eager-ab.sh new file mode 100644 index 00000000..9c6d8c15 --- /dev/null +++ b/scripts/e2e/decode/cpu-service2-eager-ab.sh @@ -0,0 +1,178 @@ +#!/usr/bin/env bash +# claude/cpu-service2: eager admission. Paired, interleaved 5-turn ~245k session (seed OFF, frozen corpus, upstream ranked profile, auto expert slots, PCIe share 0.55 = the harness +# default), ONE binary (dt/$BINDIR, default bin-cs2e), LELEKA_POOL_TIMING=1 in every arm, arms by environment only: +# ea-on defaults: every routed expert admitted at CPU pool open (stack open) +# ea-off LELEKA_CPU_ADMIT_EAGER=off LELEKA_Q8K=legacy: admission at first use and main's q8_k (= main 11e021161) +# HOLDER JOB. Install: cp scripts/e2e/decode/cpu-service2-eager-ab.sh /data/leleka-e2e/decode/dt/jobs/ ; stub ~/work/gpu-runs/holder2/jobs/cpu-service2-eager-ab.sh. +# ARMS default: 6 pairs, order alternated (pair k = runs 2k-1, 2k) = 12 runs, ~60 min. gpu.lock per arm. +# Validity per run: no turn failed, 5 turns, final-turn input tokens >= 200000, turn-5 mean window.ple < 5 ms. An INVALID run is never used. +set -uo pipefail +D=/data/leleka-e2e/decode/dt +LOCK=/data/leleka-e2e/gpu.lock +OUTR=/data/leleka-e2e/runs/cpu-service2-eager-ab +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:-"ea-off ea-on ea-on ea-off ea-off ea-on ea-on ea-off ea-off ea-on ea-on ea-off"} +BINDIR=${BINDIR:-bin-cs2e} +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/$BINDIR/leleka-inference" "$CORPUS/backend-api/src/lib.rs"; do + [ -r "$f" ] || { echo "missing $f" >&2; exit 3; } +done + +ours() { # $1 tag, $2 arm + local tag=$1 arm=$2 + ( export E2E_BIN=$D/$BINDIR 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_FOOTPRINT_LEGACY 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_IQ_SINGLE LELEKA_SINK_SCAN LELEKA_OPEN_CACHE LELEKA_ORIGINAL_SERVE_PCIE_FRAC LELEKA_Q8K LELEKA_IQ_MULTI LELEKA_POOL_TASKS_PER_THREAD LELEKA_CPU_ADMIT_EAGER + export LELEKA_POOL_TIMING=1 + export LELEKA_ORIGINAL_SERVE_SEED=off + case $arm in + ea-on) export LELEKA_ORIGINAL_SERVE_PCIE_FRAC=0.55 ;; + ea-off) export LELEKA_ORIGINAL_SERVE_PCIE_FRAC=0.55 LELEKA_CPU_ADMIT_EAGER=off LELEKA_Q8K=legacy ;; + *) echo "unknown ours arm $arm" >&2; exit 2 ;; + esac + { echo "arm=$arm tag=$tag"; date -u +%FT%TZ; free -g | sed -n 2p; uptime; 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_ARGS" + ( 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=$! + 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 2>/dev/null + echo "run-e2e done $tag $(date -u +%FT%TZ)" ) +} + +validity() { # $1 run dir + python3 -I - "$1" <<'PY' +import json, os, re, sys +d = sys.argv[1] +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 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 + 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 "cpu-service2-eager-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 + ea-on|ea-off) ours "$tag" "$arm" ;; + *) echo "unknown arm $arm" >&2; rm -f "$LOCK/owner"; rmdir "$LOCK" 2>/dev/null; exit 2 ;; + esac + validity "$OUTR/$tag" + echo "arm done $tag $(date -u +%FT%TZ)" + rm -f "$LOCK/owner"; rmdir "$LOCK" 2>/dev/null + sleep 15 +done + +# summary: per run, per arm, per block (pair k = runs 2k-1..2k, one run of each arm) the candidate against the base of its block, and the window decomposition +python3 -I - "$OUTR" <<'PY' +import glob, json, os, re, statistics, sys +root = sys.argv[1] +def run_number(path): + tail = re.sub(r"\D+$", "", path.rsplit("-r", 1)[-1]) + return int(tail) if tail.isdigit() else 0 +def load(d): + sess = json.load(open(os.path.join(d, "long-session.json"))) + reqs, prof, wins, cur = [], None, [], [] + for ln in open(os.path.join(d, "inference.log"), errors="replace"): + if ln.startswith("DBG profile request:"): + prof = {m[0]: float(m[1].split("/")[0]) for m in re.findall(r"(\S+?)=([\d.]+/\d+)", ln)} + elif ln.startswith("DBG window "): + cur.append(dict((k, float(v)) for k, v in re.findall(r"(\w+)=([-\d.]+)", ln))) + elif "leleka-serve request outcome" in ln: + m = re.search(r"produced=(\d+) rounds=(\d+)", ln) + reqs.append((int(m.group(1)), int(m.group(2)), prof)); prof = None; wins.append(cur); cur = [] + rows = [] + for i, t in enumerate(sess): + produced, rounds, p = reqs[i] if i < len(reqs) else (0, 0, None) + tps = t.get("decode_tok_s") or 0.0 + out = t.get("output_tokens") or produced + span = lambda k: (p.get(k, 0.0) / rounds) if p and rounds else float("nan") + stage = {k: span(k) for k in ("cpu.admit", "cpu.t.pre", "cpu.t.gu_drain", "cpu.t.gu_wait_done", "cpu.t.dn_drain", "cpu.t.dn_wait_done", "cpu.t.post", "cpu.t.requant", "pool.spans", "pool.publish_plan", "pool.split")} + rows.append(dict(stage=stage, tps=tps, tok_round=(produced / rounds if rounds else float("nan")), + ms_round=(1000.0 * out / tps / rounds if rounds and tps else float("nan")), + compute=span("cpu.compute"), sink=span("cpu.sink"), open=span("cpu.open"), pool=span("pool.cpu"), bell=span("drv.doorbell_wait"), verifier=span("window.verifier"))) + late = [w for ws in wins[2:5] for w in ws[20:]] + keys = ("total", "pool", "join", "gpu_wait_and_head", "experts", "entries", "pcie_experts", "rows") + wavg = {k: statistics.mean(w.get(k, 0.0) for w in late) for k in keys} if late else {} + return rows, wavg +def arm(n): return re.sub(r"-r\d+.*$", "", n) +runs = {} +for d in sorted(glob.glob(os.path.join(root, "*-r[0-9]*")), key=run_number): + 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 + runs[name] = load(d) +for n, (rows, w) in runs.items(): + print("%-16s tok/s %s | tok/round %s | ms/round %s | turns 3-5 per round: compute %.2f sink %.2f open %.2f pool %.2f bell %.2f verifier %.2f" % ((n, + " ".join("%.1f" % r["tps"] for r in rows), " ".join("%.2f" % r["tok_round"] for r in rows), " ".join("%.2f" % r["ms_round"] for r in rows)) + + tuple(statistics.mean(r[k] for r in rows[2:]) for k in ("compute", "sink", "open", "pool", "bell", "verifier")))) + print(" " + (open(os.path.join(root, n, "inference.log"), errors="replace").read().split("routed experts admitted at open in ")[1].split(" s")[0] + " s admission at open" if "routed experts admitted at open" in open(os.path.join(root, n, "inference.log"), errors="replace").read() else "no admission at open")) + print(" turns 3-5 per round: " + " ".join("%s %.3f" % (k, statistics.mean(r["stage"][k] for r in rows[2:])) for k in rows[0]["stage"])) + if w: + print(" windows 20+ of turns 3-5: total %.2f pool %.2f join %.2f gpu_wait %.2f | cpu experts %.1f entries %.1f pcie %.1f rows %.2f" % tuple(w[k] for k in ("total", "pool", "join", "gpu_wait_and_head", "experts", "entries", "pcie_experts", "rows"))) +by = {} +for n in runs: by.setdefault(arm(n), []).append(n) +for a, ns in sorted(by.items()): + allrows = [runs[n][0] for n in ns] + mean = lambda f: [statistics.mean(f(r[t]) for r in allrows) for t in range(5)] + alltps = [statistics.mean(x["tps"] for x in r) for r in allrows] + print("ARM %s (%d runs): tok/s per turn %s all-turn %.1f (runs %.1f..%.1f, sd %.2f %%) | tokens/round %s | ms/round %s mean %.2f" % (a, len(ns), + " ".join("%.1f" % x for x in mean(lambda r: r["tps"])), statistics.mean(alltps), min(alltps), max(alltps), 100 * statistics.pstdev(alltps) / statistics.mean(alltps), + " ".join("%.2f" % x for x in mean(lambda r: r["tok_round"])), " ".join("%.2f" % x for x in mean(lambda r: r["ms_round"])), statistics.mean(mean(lambda r: r["ms_round"])))) +for cand, ref in (("ea-on", "ea-off"),): + diffs, msd = [], [] + for k in range(1, 40): + blk = [n for n in runs if (run_number(n) + 1) // 2 == k] + b = [n for n in blk if arm(n) == ref]; c = [n for n in blk if arm(n) == cand] + if len(b) == 1 and len(c) == 1: + rb, rc = runs[b[0]][0], runs[c[0]][0] + mb, mc = statistics.mean(x["tps"] for x in rb), statistics.mean(x["tps"] for x in rc) + ab, ac = statistics.mean(x["ms_round"] for x in rb), statistics.mean(x["ms_round"] for x in rc) + diffs.append(100 * (mc / mb - 1)); msd.append(ac - ab) + print("block %d %s vs %s: all-turn tok/s %.1f vs %.1f (%+.2f %%), ms/round %.2f vs %.2f (%+.2f)" % (k, cand, ref, mc, mb, diffs[-1], ac, ab, msd[-1])) + if diffs: + print("%s over %s: %d blocks, tok/s mean %+.2f %% (min %+.2f max %+.2f, %d/%d positive); ms/round mean %+.2f (min %+.2f max %+.2f)" % (cand, ref, len(diffs), statistics.mean(diffs), min(diffs), max(diffs), + sum(d > 0 for d in diffs), len(diffs), statistics.mean(msd), min(msd), max(msd))) +PY diff --git a/scripts/e2e/decode/cpu-service2e-id.sh b/scripts/e2e/decode/cpu-service2e-id.sh new file mode 100644 index 00000000..75932fa4 --- /dev/null +++ b/scripts/e2e/decode/cpu-service2e-id.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +# claude/cpu-service2 identity gate (eager admission + q8_k; legacy = LELEKA_Q8K=legacy LELEKA_CPU_ADMIT_EAGER=off = main): the AVX2 q8_k of the CPU group's tokens and the vectorized token/output checks (defaults of the branch) against the same binary with +# LELEKA_Q8K=legacy (main's scalar q8_k and element-wise checks), at an EQUAL FIXED slot count. Expectation: BITWISE identity. +# HOLDER JOB (copy of cpu-service-id.sh): replay of night5-long-256k, 5 requests, 48 forced tokens, static tier, EXPERT_SLOTS=8000, seed OFF, LELEKA_SPEC=4, RT directory set, +# ONE test binary (dt/rt-cs2e): p1 idLegacy LELEKA_Q8K=legacy, two arms (A/A floor) p2 idNew defaults, two arms. ~20 min. +# Install: cp scripts/e2e/decode/cpu-service2e-id.sh /data/leleka-e2e/decode/dt/jobs/; stub ~/work/gpu-runs/holder2/jobs/cpu-service2e-id.sh. +set -uo pipefail +LOCK=/data/leleka-e2e/gpu.lock +D=/data/leleka-e2e/decode/dt +O=/data/leleka-e2e/runs/cpu-service2e-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_RT_DIR=$A/data/mtp-rt +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 +unset LELEKA_SERVE_DRAFT_AFTER_COMMIT LELEKA_PROMPT_EMBED_ALIAS LELEKA_VRAM_LEDGER LELEKA_DENSE_SLAB LELEKA_FOOTPRINT_LEGACY LELEKA_IQ_SINGLE LELEKA_SINK_SCAN LELEKA_OPEN_CACHE LELEKA_Q8K LELEKA_IQ_MULTI LELEKA_POOL_TIMING LELEKA_POOL_TASKS_PER_THREAD LELEKA_CPU_ADMIT_EAGER +for f in $D/rt-cs2e $D/tools/q_pair.py $D/tools/q_tail_gate.py $CAP/night5-long-256k; do + [ -e "$f" ] || { echo "missing $f" >&2; exit 3; } +done +sha256sum $D/rt-cs2e +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 "cpu-service2 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 idLegacy rt-cs2e "LELEKA_Q8K=legacy LELEKA_CPU_ADMIT_EAGER=off" "I1=$shape,I2=$shape" +run idNew rt-cs2e "LELEKA_X=1" "I1=$shape,I2=$shape" +T=$D/tools +PROCS="idLegacy idNew" +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 -12; done +python3 - <