Files
leleka/scripts/e2e/decode/draftvocab-ab.sh
T
Pavlo RatushnyiandClaude Sonnet 5.5 d6fc908641 scripts, docs: draft-vocab paired A/B and identity jobs, upstream findings and port notes
* scripts/e2e/decode/draftvocab-ab.sh: speedtrain3-ab shape, one binary in every arm, counterbalanced
  base/en order, arms dv-base, dv-en, dv-en-eqslots; spec-stats give tokens per round, accepted/offered and
  the accepted-length histogram; validity rejects fallback, missing or unexpected draft-vocab log lines
* scripts/e2e/decode/draftvocab-id.sh: teacher-forced replay with LELEKA_ORIGINAL_SERVE_RT_DIR set (the older
  identity jobs draft over the full head), A/A floor, en against default, optional LELEKA_SPEC=3 control
* docs/experiments/2026-10-30-draft-vocab-en.md: what upstream does (format, digests, selection, default off),
  our status, the port, expectations, what is not verified

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

255 lines
16 KiB
Bash

#!/usr/bin/env bash
# Draft-vocab A/B: the opt-in English draft subset (LELEKA_DRAFT_VOCAB, upstream draft_vocab_en.bin, 40,525 ids) against the default subset (rt/draft_vocab.bin, 106,299 ids),
# SAME binary in both arms, paired 5-turn ~245k session, seed OFF, frozen corpus, counterbalanced arm order. Shape copied from speedtrain3-ab.sh.
# HOLDER JOB (run on rnr5090 under the holder). Install:
# cp scripts/e2e/decode/draftvocab-ab.sh /data/leleka-e2e/decode/dt/jobs/draftvocab-ab.sh
# queue stub (~/work/gpu-runs/holder2/jobs/draftvocab-ab.sh): #!/usr/bin/env bash / exec bash /data/leleka-e2e/decode/dt/jobs/draftvocab-ab.sh (+ one line in jobs/PRIORITY)
# Needs dt/bin-draftvocab (claude/draft-vocab release build: leleka-inference leleka-daemon leleka-cli strata-next, see dt/BUILD.md) and the frozen asset
# /data/leleka-e2e/decode/assets/draft_vocab_en.bin (this script creates it from the read-only vanilla install copy when missing and REFUSES any file whose sha256 differs).
# It takes /data/leleka-e2e/gpu.lock per arm (one arm at a time) and skips an arm when something else uses the GPU. ~13 min an arm, 6 arms by default (~80 min).
#
# bash draftvocab-ab.sh # default order dv-base dv-en | dv-en dv-base | dv-base dv-en
# ARMS="dv-base-noseed dv-en-eqslots-noseed dv-en-eqslots-noseed dv-base-noseed" bash draftvocab-ab.sh # attributes the gain: same expert slot count as the base arm
#
# Arms (every arm: this binary, seed OFF via LELEKA_ORIGINAL_SERVE_SEED=off, upstream ranked profile, GPU budget 32,819,404,800 (the product profile), sm120 switches at their
# defaults, LELEKA_SPEC_STATS=1 and the bring-up traces; nothing else differs between two arms):
# dv-base-noseed LELEKA_DRAFT_VOCAB unset: rt/draft_vocab.bin, 106,299 ids, EXPERT_SLOTS=auto
# dv-en-noseed LELEKA_DRAFT_VOCAB=<asset>: draft_vocab_en.bin, 40,525 ids, EXPERT_SLOTS=auto. The ~110 MiB the smaller draft head frees appears as MORE auto expert slots
# (the bind reserve follows the file size), so this arm measures the product effect: faster draft step + more resident experts + a different acceptance.
# dv-en-eqslots-noseed as dv-en-noseed but EXPERT_SLOTS = the slot count the last dv-base arm of THIS job reported ("expert cache N slots"), so the placement is equal and the
# difference is the draft step and the acceptance only. Refuses to start when no dv-base arm has run yet.
# 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 mean window.ple < 5 ms, a `DBG spec-stats` line per request, and the draft-vocab
# log line matches the arm: dv-en* must log `subset=en ids=40525` and no FALLBACK; dv-base* must log no `draft-vocab:` line at all. An INVALID run is never used in a comparison.
# Metrics: per-turn decode_tok_s of the client (per arm over the repeats, paired difference of each (base, en) pair); tokens per round, accepted/offered drafts and the accepted-length
# histogram per arm from the spec-stats lines (summed over the 5 requests of a run, then compared per pair); the per-round ms budget (draft.finish, mtp.chain_step, round.run_window ...)
# and the expert slot count of each arm. A gain of the client tok/s that comes with a LOWER tokens per round is a draft-step gain paid for with acceptance; read both.
# Quality is NOT decided here: sampled text is not compared (thinking turns are empty in long-session.json); use draftvocab-id.sh (teacher-forced replay, fixed slots, q_pair).
set -uo pipefail
D=/data/leleka-e2e/decode/dt
LOCK=/data/leleka-e2e/gpu.lock
OUTR=/data/leleka-e2e/runs/draftvocab-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
VOCAB_EN=/data/leleka-e2e/decode/assets/draft_vocab_en.bin
VOCAB_EN_SHA=369151522226a5edaa5f12cfd1e2ae7db8f4fbdbd222f3dcf327dced9597fb25 # upstream Strata data/draft_vocab_en.bin at 41cf05a0, v0.2.7.1, v0.2.8; 162,100 bytes
VOCAB_EN_SRC=$HOME/work/vanilla-strata/control/data/draft_vocab_en.bin # read-only source of the copy
RUN_TAG=${RUN_TAG:-} # suffix of the run directories (a rerun next to earlier ones)
ARMS=${ARMS:-"dv-base-noseed dv-en-noseed dv-en-noseed dv-base-noseed dv-base-noseed dv-en-noseed"}
SESSION_ARGS="--turns 5 --target-tokens 245000 --max-output 300 --min-final-tokens 200000"
if [ ! -e "$VOCAB_EN" ] && [ -r "$VOCAB_EN_SRC" ]; then
cp "$VOCAB_EN_SRC" "$VOCAB_EN.tmp" && mv "$VOCAB_EN.tmp" "$VOCAB_EN"
fi
got_sha=$(sha256sum "$VOCAB_EN" 2>/dev/null | cut -d' ' -f1)
[ "$got_sha" = "$VOCAB_EN_SHA" ] || { echo "draft_vocab_en.bin: sha256 '$got_sha' is not $VOCAB_EN_SHA" >&2; exit 3; }
for f in "$UP" "$D/tools/long-session.py" "$D/scripts/e2e/run-e2e.sh" "$D/bin-draftvocab/leleka-inference" "$CORPUS/backend-api/src/lib.rs"; do
[ -r "$f" ] || { echo "missing $f" >&2; exit 3; }
done
last_base_slots() { # the slot count of the newest dv-base run that logged one
local d
for d in $(ls -dt "$OUTR"/dv-base-noseed-r* 2>/dev/null); do
n=$(grep -a -o -m1 "expert cache [0-9]* slots" "$d/inference.log" 2>/dev/null | grep -o "[0-9]*")
[ -n "$n" ] && { echo "$n"; return 0; }
done
return 1
}
ours() { # $1 tag, $2 arm
local tag=$1 arm=$2
( export E2E_BIN=$D/bin-draftvocab E2E_OUT=$OUTR/$tag
mkdir -p "$E2E_OUT"
export LELEKA_BRINGUP_TRACE=1 LELEKA_PREFIX_TRACE=1 LELEKA_SPEC_STATS=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_DRAFT_VOCAB 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
export LELEKA_ORIGINAL_SERVE_SEED=off
case $arm in
dv-base-noseed) ;;
dv-en-noseed) export LELEKA_DRAFT_VOCAB=$VOCAB_EN ;;
dv-en-eqslots-noseed)
export LELEKA_DRAFT_VOCAB=$VOCAB_EN
N=$(last_base_slots) || { echo "no dv-base arm with a slot count in $OUTR yet" >&2; exit 2; }
export LELEKA_ORIGINAL_SERVE_EXPERT_SLOTS=$N ;;
*) 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" "$VOCAB_EN" "$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|draft-vocab" | cut -c1-300
kill $SAMP 2>/dev/null
echo "run-e2e done $tag $(date -u +%FT%TZ)" )
}
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
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, vocab, stats = [], [], [], 0
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 = []
elif "leleka-serve draft-vocab:" in ln:
vocab.append(ln.strip())
elif ln.startswith("DBG spec-stats "):
stats += 1
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; %d spec-stats lines" % (ple, len(w), stats)
want_en = arm.startswith("dv-en")
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
elif stats < 5:
verdict = "INVALID: only %d spec-stats lines (LELEKA_SPEC_STATS not passed?)" % stats
elif want_en and not any("subset=en ids=40525" in v for v in vocab):
verdict = "INVALID: dv-en arm without the `subset=en ids=40525` line (%s)" % (vocab or "no draft-vocab line")
elif any("FALLBACK" in v for v in vocab):
verdict = "INVALID: draft-vocab FALLBACK to the default subset"
elif not want_en and vocab:
verdict = "INVALID: base arm logged a draft-vocab line: %s" % vocab[0]
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 "draftvocab-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
dv-base-noseed|dv-en-noseed|dv-en-eqslots-noseed) ours "$tag" "$arm" ;;
*) echo "unknown arm $arm" >&2; rm -f "$LOCK/owner"; rmdir "$LOCK" 2>/dev/null; exit 2 ;;
esac
validity "$OUTR/$tag" "$arm"
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, per-arm means, paired (base, candidate) differences, acceptance (tokens per round, accepted/offered, accepted-length histogram),
# the expert slot count and the per-round host budget
python3 -I - "$OUTR" <<'PY'
import glob, json, os, re, statistics, sys
root = sys.argv[1]
REF = "dv-base-noseed"
def run_number(path):
tail = path.rsplit("-r", 1)[-1]
m = re.match(r"\d+", tail)
return int(m.group()) if m else 0
def arm_of(k):
return k.rsplit("-r", 1)[0]
runs, order = {}, []
for d in sorted(glob.glob(os.path.join(root, "*")), key=run_number):
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]
order.append(os.path.basename(d))
for k in order:
print(k, " ".join("%.1f" % x for x in runs[k]), "mean %.1f" % statistics.mean(runs[k]))
by = {}
for k in order:
by.setdefault(arm_of(k), []).append(runs[k])
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)))
if REF in mean:
for a, m in sorted(mean.items()):
if a != REF:
print("%s minus %s per turn: %s mean %+.1f tok/s (%+.2f %%)" % (a, REF, " ".join("%+.1f" % (x - y) for x, y in zip(m, mean[REF])),
statistics.mean(m) - statistics.mean(mean[REF]), 100 * (statistics.mean(m) / statistics.mean(mean[REF]) - 1)))
# acceptance, slots and round time per run, from the logs
def stats_of(k):
log = os.path.join(root, k, "inference.log")
rounds = tokens = acc = off = 0
hist, ms = None, []
slots = None
for ln in open(log, errors="replace"):
if slots is None:
m = re.search(r"expert cache (\d+) slots", ln)
if m:
slots = int(m.group(1))
if ln.startswith("DBG spec-stats "):
g = lambda p: re.search(p, ln)
r = int(g(r"rounds=(\d+)").group(1)); tk = int(g(r"tokens=(\d+)").group(1))
a, o = map(int, g(r"accepted=(\d+)/(\d+)").groups())
h = [int(x) for x in g(r"acc_hist=([\d,]+)").group(1).split(",")]
rounds += r; tokens += tk; acc += a; off += o
hist = h if hist is None else [x + y for x, y in zip(hist, h + [0] * (len(hist) - len(h)))] + h[len(hist):]
ms.append((r, float(g(r"round_ms=([\d.]+)").group(1))))
rms = sum(r * m for r, m in ms) / max(sum(r for r, _ in ms), 1)
return dict(slots=slots, rounds=rounds, tpr=tokens / max(rounds, 1), acc=acc / max(off, 1), hist=hist or [], round_ms=rms)
S = {k: stats_of(k) for k in order if os.path.exists(os.path.join(root, k, "inference.log"))}
print("acceptance per run: slots, rounds, tokens/round, accepted/offered, round_ms (mean over rounds), accepted-length histogram")
for k in order:
if k in S:
s = S[k]
print("%-28s slots=%s rounds=%d tok/round=%.3f accepted/offered=%.3f round_ms=%.2f acc_hist=%s" % (k, s["slots"], s["rounds"], s["tpr"], s["acc"], s["round_ms"], ",".join(map(str, s["hist"]))))
# consecutive pairs (runs 1-2, 3-4, 5-6 ...): one base and one candidate in either order; the paired difference removes slow drift and the counterbalanced order cancels a linear one
for c in [a for a in by if a != REF]:
diffs, dt, dr = [], [], []
for i in range(0, len(order) - 1, 2):
a, b = order[i], order[i + 1]
if {arm_of(a), arm_of(b)} == {REF, c}:
ref, cand = (a, b) if arm_of(a) == REF else (b, a)
diffs.append(100 * (statistics.mean(runs[cand]) / statistics.mean(runs[ref]) - 1))
if ref in S and cand in S:
dt.append(S[cand]["tpr"] - S[ref]["tpr"]); dr.append(S[cand]["round_ms"] - S[ref]["round_ms"])
if diffs:
print("%s over %s, consecutive pairs, all-turn mean tok/s: %s %% mean %+.2f %% (min %+.2f max %+.2f)" % (c, REF, " ".join("%+.2f" % x for x in diffs), statistics.mean(diffs), min(diffs), max(diffs)))
if dt:
print(" same pairs: tokens/round %s (mean %+.3f), round_ms %s (mean %+.2f)" % (" ".join("%+.3f" % x for x in dt), statistics.mean(dt), " ".join("%+.2f" % x for x in dr), statistics.mean(dr)))
KEYS = ["round.apply_pending", "round.run_window", "round.draft_committed", "draft.launch", "round.adapt_deferred", "commit.wait", "commit.publish", "draft.finish",
"mtp.finish_first_step", "mtp.chain_step", "round.finish", "round.verify_commit", "window.ple", "ple.read_rows", "ple.device", "window.history"]
print("per-round budget, ms per round (chain_step per call); columns: " + " ".join(KEYS))
for k in order:
log = os.path.join(root, k, "inference.log")
if not os.path.exists(log):
continue
reqs, prof = [], None
for ln in open(log, errors="replace"):
if ln.startswith("DBG profile request:"):
prof = {m[0]: (float(m[1].split("/")[0]), int(m[1].split("/")[1])) for m in re.findall(r"(\S+?)=([\d.]+/\d+)", ln)}
elif "leleka-serve request outcome" in ln:
m = re.search(r"rounds=(\d+)", ln)
if prof and m:
reqs.append((int(m.group(1)), prof))
if reqs:
row = []
for key in KEYS:
vals = [(p[key][0] / (p[key][1] if key.endswith("chain_step") else r)) for r, p in reqs if key in p and p[key][1]]
row.append("%.3f" % statistics.mean(vals) if vals else "-")
print("%-28s %s" % (k, " ".join(row)))
PY