Merge claude/slots-footprint3: share byte-equal RT/MTP pack dense roles (verified at every start; -109 MiB, 12,144 -> 12,192 slots), bit-identical vs LELEKA_FOOTPRINT_LEGACY=1 at equal slots (353/353); placement-class gate PASS; A/B of alias/reserve130 neutral, defaults unchanged. No speed claim

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Pavlo Ratushnyi
2026-10-31 10:34:20 +01:00
co-authored by Claude Sonnet 5.5
7 changed files with 475 additions and 1 deletions
@@ -24,7 +24,45 @@ pub(in crate::qwen_forward) struct RetainedOriginalMtpWeights<'ctx>{
/// owned here for the life of the bank rather than being released early.
extras:Vec<Rc<DeviceBuffer<'ctx>>>,
}
/// What `MoeWeightCache::share_rt_mtp_dense` did.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub(in crate::qwen_forward) struct MtpDenseShare{
/// Roles whose pinned-pack copy was proven byte-equal to the RT bank's and replaced by it.
pub(in crate::qwen_forward) shared:usize,
/// Roles left as they were (not in the RT bank, or a different shape or different bytes).
pub(in crate::qwen_forward) kept:usize,
/// Roles found different from the RT bank's copy although the shape matches (a subset of `kept`; 0 expected).
pub(in crate::qwen_forward) differing:usize,
/// Device bytes the replaced buffers gave back.
pub(in crate::qwen_forward) released_bytes:usize,
}
/// Two copies of a dense role may be merged only when kind, shape, length and every byte agree.
fn dense_copies_equal(a:(MtpKind,usize,usize,&[u8]),b:(MtpKind,usize,usize,&[u8]))->bool{
(a.0,a.1,a.2)==(b.0,b.1,b.2)&&a.3==b.3
}
impl<'ctx> MoeWeightCache<'ctx>{
/// The RT-directory serve path holds the MTP layer's dense roles twice: the pinned pack's copy that this cache uploaded (read by the prompt path's draft-KV recording through
/// `mtp_matrix`) and the RT bank's own. When a role's two device copies are proven byte-equal here (both read back and compared), this cache adopts the RT bank's allocation
/// and releases its own, so the model holds one copy. Values read by any kernel do not change. Roles the RT bank lacks (the indexer roles) and roles that differ are left alone.
pub(in crate::qwen_forward) fn share_rt_mtp_dense(&mut self,retained:&RetainedOriginalMtpWeights<'ctx>)->Result<MtpDenseShare>{
if retained.source!=WeightSource::RtDirectory||!std::ptr::eq(retained.context,self.context){return Err(Error::IdentityMismatch);}
let mut report=MtpDenseShare::default();
for entry in self.dense.iter_mut(){
let Some(rt)=retained.dense.iter().find(|r|r.role==entry.role)else{report.kept+=1;continue};
if Rc::ptr_eq(&rt.buffer,&entry.buffer){continue;}
if (rt.kind,rt.rows,rt.columns)!=(entry.kind,entry.rows,entry.columns)||rt.buffer.len()!=entry.buffer.len(){report.kept+=1;continue;}
let mine=entry.buffer.copy_to_owned(entry.buffer.len()).map_err(driver_error)?;
let theirs=rt.buffer.copy_to_owned(rt.buffer.len()).map_err(driver_error)?;
if !dense_copies_equal((entry.kind,entry.rows,entry.columns,&mine),(rt.kind,rt.rows,rt.columns,&theirs)){report.kept+=1;report.differing+=1;continue;}
let old=std::mem::replace(&mut entry.buffer,Rc::clone(&rt.buffer));
if let Ok(buffer)=Rc::try_unwrap(old){
report.released_bytes+=buffer.len();
if buffer.release().is_err(){self.failed.set(true);return Err(Error::CudaExecution);}
}
report.shared+=1;
}
Ok(report)
}
pub(in crate::qwen_forward) fn retain_original_mtp_weights(&self,binding:&ModelBinding,
context:&Context<'ctx>)->Result<RetainedOriginalMtpWeights<'ctx>>{
self.validate(binding,context)?;
@@ -251,3 +289,17 @@ mod rt_contract_tests{
assert_eq!(pinned_dense_bytes(),116_099_072);
}
}
#[cfg(test)]
mod share_tests {
use super::*;
#[test]
fn dense_copies_merge_only_when_kind_shape_and_every_byte_agree() {
let a=[1u8,2,3,4];
assert!(dense_copies_equal((MtpKind::Q8_0,2,2,&a),(MtpKind::Q8_0,2,2,&[1,2,3,4])));
assert!(!dense_copies_equal((MtpKind::Q8_0,2,2,&a),(MtpKind::Q8_0,2,2,&[1,2,3,5])), "one byte");
assert!(!dense_copies_equal((MtpKind::Q8_0,2,2,&a),(MtpKind::Bf16,2,2,&a)), "kind");
assert!(!dense_copies_equal((MtpKind::Q8_0,2,2,&a),(MtpKind::Q8_0,1,4,&a)), "shape");
assert!(!dense_copies_equal((MtpKind::Q8_0,2,2,&a),(MtpKind::Q8_0,2,2,&a[..3])), "length");
}
}
@@ -94,6 +94,8 @@ impl<'ctx> OriginalPromptExecutor<'ctx>{
if let Err(primary)=result{let _=owner.close_inner();return Err(primary);}
Ok(owner)
}
/// The immutable MTP roles this executor retains (the RT bank's on the product path).
pub(in crate::qwen_forward) fn retained_mtp_weights(&self)->Option<&RetainedOriginalMtpWeights<'ctx>>{self.mtp_weights.as_ref()}
/// Joins the source-created full MTP graph owner to this exact prompt
/// executor. The draft session is validated against the same target
/// session before it leaves the assembly, so callers cannot pair a full
@@ -420,7 +420,7 @@ impl<'a, 'ctx> OriginalServeStack<'a, 'ctx> {
None => None,
});
let dense = staged!("dense weights", context, DenseWeightCache::new_original_prompt_capacity(binding, context, config.capacity).map_err(at("DenseWeightCache::new_original_prompt_capacity"))?);
let moe = staged!("MoE arena cache", context, MoeWeightCache::new_original_prompt_arena(binding, context, layout, super::original_serve_config::mtp_pack_experts_needed(config.rt_directory.is_some())).map_err(at("MoeWeightCache::new_original_prompt_arena"))?);
let mut moe = staged!("MoE arena cache", context, MoeWeightCache::new_original_prompt_arena(binding, context, layout, super::original_serve_config::mtp_pack_experts_needed(config.rt_directory.is_some())).map_err(at("MoeWeightCache::new_original_prompt_arena"))?);
if !super::original_serve_config::mtp_pack_experts_needed(config.rt_directory.is_some()) {
operator_note("footprint: the pinned MTP pack's expert bank (675 MiB) is not uploaded: the draft layer is loaded from the RT directory and never reads it (LELEKA_FOOTPRINT_LEGACY=1 keeps it)");
}
@@ -443,6 +443,16 @@ impl<'a, 'ctx> OriginalServeStack<'a, 'ctx> {
(executor, draft)
}
};
// RT-directory draft: the MTP dense roles sit twice in VRAM (this cache's pinned-pack upload and the RT bank's); merge them when proven byte-equal
if config.rt_directory.is_some() && !super::original_serve_config::legacy_footprint() {
if let Some(retained) = executor.retained_mtp_weights() {
let share = moe.share_rt_mtp_dense(retained).map_err(at("share_rt_mtp_dense"))?;
operator_note(&format!(
"footprint: MTP dense roles shared with the RT bank (byte-equal): {} shared, {} kept ({} differing), {:.1} MiB released",
share.shared, share.kept, share.differing, share.released_bytes as f64 / f64::from(1u32 << 20)
));
}
}
vram_note(context, "after prompt executor and draft");
let mut executor = executor;
crate::memory_governor::end(executor_stage, Some(context));
+78
View File
@@ -0,0 +1,78 @@
# 5090 expert slots, third pass: the opt-ins measured, the MTP dense roles shared, the placement gate (claude/slots-footprint3)
Date 2026-10-31. RTX 5090, frozen corpus, upstream ranked profile, product budget 31,299 MiB, server uptime ~16 h. Base = `main` 4a1b9bfec (the footprint2 merge). Labels: M measured in the run named, E estimate, U unverified.
Follows [vram-footprint2-5090](vram-footprint2-5090.md).
## 1. Result
| item | status | slots on the 5090 |
| --- | --- | ---: |
| `LELEKA_PROMPT_EMBED_ALIAS=1` (+144 slots measured, 324 MiB) | measured, **no gain**; stays OFF | 12,288 |
| decode reserve 300 -> 130 MiB (+48 slots measured, 170 MiB) | measured, **no gain**, lowest free VRAM 407 MiB; stays at 300 | 12,192 |
| both | +1.7 % tok/s, inside the noise; stays OFF (lowest free VRAM 355 MiB) | 12,384 |
| MTP dense roles shared with the RT bank (new, default ON, `LELEKA_FOOTPRINT_LEGACY=1` off) | byte-equality proven on the server at every start; 109.1 MiB released | 12,144 -> 12,192 |
| QSA prompt scratch (128 MiB) / GDN prompt device (50 MiB) carved from the lent slots | **not implemented** (section 4) | |
| placement gate of the larger cache (11,568 -> 12,192 slots) | **PASS** (section 3) | |
## 2. Paired A/B of the two opt-ins, `runs/footprint3-ab` (job `footprint3-ab`, 2026-10-31 08:07-09:17Z)
ONE binary (`dt/bin-footprint3a` = main 4a1b9bfec), arms by environment only, 5 turns to ~245k, seed OFF, auto slots, all 18 runs VALID (final turn 246,885 / 247,062 input tokens, turn-5 `window.ple` 0.16-0.19 ms). 9 pairs (pair k = runs 2k-1, 2k), the base arm ran 9 times,
the order inside a pair alternated.
| arm | runs | slots | lowest free VRAM | tok/s T1..T5 | all-turn | tokens/round T1..T5 | ms/round T1..T5 | mean ms/round |
| --- | ---: | ---: | ---: | --- | ---: | --- | --- | ---: |
| base (main defaults) | 9 | 12,144 | 499 MiB | 132.2 148.2 151.3 139.6 149.5 | 144.2 | 2.04 2.11 2.15 1.86 2.05 | 15.46 14.23 14.23 13.30 13.68 | 14.18 |
| alias | 3 | 12,288 | 543 MiB | 135.6 144.3 149.7 144.2 139.9 | 142.7 | 2.09 2.00 2.16 2.01 1.88 | 15.44 13.83 14.45 13.93 13.47 | 14.22 |
| reserve 130 | 3 | 12,192 | 407 MiB | 142.7 148.6 142.3 141.0 142.4 | 143.4 | 2.15 2.15 2.02 1.95 1.96 | 15.10 14.46 14.17 13.86 13.74 | 14.27 |
| both | 3 | 12,384 | 355 MiB | 135.9 145.2 159.0 145.5 145.5 | 146.2 | 2.12 2.04 2.20 1.92 1.96 | 15.58 14.01 13.80 13.19 13.46 | 14.01 |
Pairs (all-turn tok/s, candidate against the base run next to it):
| candidate | pair 1 | pair 2 | pair 3 | mean |
| --- | ---: | ---: | ---: | ---: |
| alias | -1.32 % | +0.89 % | -2.23 % | **-0.89 %** |
| reserve 130 | -1.20 % | +1.46 % | -2.87 % | **-0.87 %** |
| both | +1.71 % | -0.15 % | +3.52 % | **+1.69 %** |
Reading it:
* The nine base runs spread by 141-147 tok/s all-turn (SD about 1.3 %); five of them reproduce the same text (tokens/round 2.04 2.16 2.11 1.80 2.04), the other four differ. Every candidate result lies inside that spread. With three pairs nothing here is distinguishable from zero. M.
* The alias adds 144 slots (1.2 %); the reserve adds 48 (one quota step, 0.4 %) although it frees 170 MiB: the planner grows in whole 48-slot steps. At footprint2's measured rate (576 slots, -0.46 ms/round) the expected effect is -0.12 ms/round for the alias, -0.04 ms for the reserve (E): below what 3 pairs resolve. The per-window misses
confirm it: CPU-pool entries per window in turns 3-5 are 29.9 (base), 30.4 (alias), 31.1 (reserve 130), 26.8 (both) (windows 20+ of each request, M).
* The alias also has a possible cost (the drafter gathers a row over PCIe): no sign of it in ms/round (14.22 against 14.18), but the sensitivity is that of the line above.
* **Decision (from this result only): no default changes.** Alias and reserve 130 stay opt-in. `both` is the only arm that moves (+1.7 %, ms/round 14.01 against 14.18, 10 % fewer CPU-pool entries) and also the one that gives up most headroom (355 MiB free at decode, vanilla runs at 315); three pairs with a
per-pair range of -0.15..+3.52 % do not justify taking it. If it is wanted, it needs a longer series (10+ pairs) and the owner's word on the 130 MiB reserve. U.
## 3. Placement-class relative gate of the larger cache, `runs/footprint3-gate` (job `footprint3-gate`, 2026-10-31 09:19-09:32Z)
Teacher-forced replay of the 256k capture `night5-long-256k` (5 requests, 240 forced tokens each), static tier, seed OFF, upstream profile, RT directory set, `EXPERT_SLOTS=auto` with the card-bound budget (31 GiB), top-16 logprobs; one test binary (`dt/rt-footprint3b`, code 9e13fc809):
| process | setting | slots |
| --- | --- | ---: |
| ref | `LELEKA_FOOTPRINT_LEGACY=1` (main before footprint2, the previous 11,568) | 11,568 |
| new | defaults (footprint2 + MTP dense sharing; main alone has 12,144) | 12,192 |
| ph | CONTROL: legacy footprint with the placeholder profile (unranked placement; copy of `gpu-runs/baseline/profile.bin` frozen at `decode/assets/profile-placeholder.bin`, sha256 b3e62120...) | 11,568 |
| comparison against ref | common rows | different | argmax flips | d_top1 p99 | d_top1 max |
| --- | ---: | ---: | ---: | ---: | ---: |
| control (placeholder placement) | 1717 | 1684 | 43 (2.50 %) | 0.2313 | 0.7602 |
| larger cache (new) | 1821 | 1775 | 36 (1.98 %) | 0.1844 | 0.4739 |
Criterion of `decode/notes.md` (rows >= 1000 in both, p99 and max <= 1.5x the control, flips <= 2.8 %): the larger cache has p99 0.80x and max 0.62x of the control and 1.98 % flips: **PASS** (M). The ratio is against a control that itself shows 2.50 % flips, as in the earlier gates; this
is the placement class (GPU-resident experts round differently from the CPU's), one replay, one capture, no repeat of the control. Perplexity and agent-task completion were not measured (U).
## 4. Levers implemented and not implemented
* **MTP dense roles shared with the RT bank (done, 9e13fc809).** `OriginalServeStack::open` builds the MoE cache first (its `new` uploads the pinned pack's 26 dense roles, 109.1 MiB, read by the prompt path's draft-KV recording through `mtp_matrix`) and the RT bank next (its own copy).
`MoeWeightCache::share_rt_mtp_dense` reads both device copies back, compares kind, shape, length and every byte, and only then adopts the RT bank's allocation and releases its own. On the server: `26 shared, 0 kept (0 differing), 109.1 MiB released`, free before the cache 24,717 -> 24,833 MiB, slots 12,144 -> 12,192
(`runs/slots2/ledger-footprint3b`). Equality is proven at every start, not assumed from the common source; a role that differs (or is not in the RT bank) is left alone. Replay identity against `LELEKA_FOOTPRINT_LEGACY=1` at an equal fixed slot count: 353/353 rows bitwise identical, A/A floor 0
(`runs/footprint3-id`, job `footprint3-id`). Unit test: the byte-equality predicate (`share_tests`).
* **QSA prompt scratch and GDN prompt device from the lent slots: not implemented, on purpose.** The ledger puts them at 128 MiB (`OriginalQsaPromptDevice::new_resident`: 64 MiB dequant scratch and a 64 MiB selection buffer) and 50 MiB (`OriginalGdnPromptDevice`: batch, scratch, two history buffers); they are prompt-only, but each is a `DeviceBuffer`
the driver validates by identity (`own`, `validate`) in several places, so making them per-request means a lifecycle (allocate at the first chunk, release before the decode assembly, handle the no-prefill request) across those paths. The gain is +90 slots at most (E), 0.7 % of the cache and, at footprint2's rate, about 0.07 ms/round,
which no series of this size can resolve. Not worth a risk to prefill correctness now.
## 5. What would raise the VRAM hit rate further (E, no run)
From the base runs of section 2 (turns 3-5, windows 20+): about 30 CPU-pool entries and 12.5 PCIe experts per window of 4 rows. A window routes 4 rows x 10 experts x 48 layers = 1,920 entries, so about 1.6 % are served by the CPU and under 0.7 % by PCIe: the VRAM hit rate is already about 97.7 %, vanilla's 97.6 %
(its figure includes 2 % skipped by the lossy tail skip; ours skips nothing). The remaining slot gap (12,575 - 12,192 = 383) is two thirds of footprint2's 576 slots, which bought -0.46 ms/round (section 5.1 of that page): about -0.3 ms/round if the rate holds (E). The ~3 ms window deficit is therefore not a hit-rate deficit: it is the cost
of serving ~30 entries on the CPU through 48 doorbells (about 0.1 ms per entry), where vanilla serves ~15. Levers that stay lossless: a smaller quota step (up to 48 slots, uneven quotas), the alias and reserve-130 slots when someone owns the headroom call, and the CPU-service path itself, not placement.
+182
View File
@@ -0,0 +1,182 @@
#!/usr/bin/env bash
# claude/slots-footprint3, goal (1): paired, interleaved 5-turn ~245k session (seed OFF, frozen corpus, upstream ranked profile, auto expert slots) of the two existing opt-ins on top of main
# (code 4a1b9bfec, binary dt/$BINDIR, default bin-footprint3a). ONE binary, arms differ by environment only:
# fp3-base-noseed main defaults (12,144 slots, decode reserve 300 MiB, prompt token table in VRAM)
# fp3-alias-noseed LELEKA_PROMPT_EMBED_ALIAS=1: the prompt-path token table (324 MiB) aliased onto the native embedding's host mapping (about +166 slots); values read are identical
# fp3-res130-noseed LELEKA_ORIGINAL_SERVE_DECODE_RESERVE_MIB=130 (about +87 slots; free VRAM at decode drops by 170 MiB)
# fp3-both-noseed both
# HOLDER JOB (rnr5090). Install: cp scripts/e2e/decode/footprint3-ab.sh /data/leleka-e2e/decode/dt/jobs/ ; stub in ~/work/gpu-runs/holder2/jobs/footprint3-ab.sh
# (#!/usr/bin/env bash / exec bash /data/leleka-e2e/decode/dt/jobs/footprint3-ab.sh) ; one line in jobs/PRIORITY. gpu.lock per arm, ~4 min an arm.
# ARMS (default: 3 pairs per candidate, base/candidate order alternated; pair k = runs 2k-1 and 2k; the candidate of pair k is the one that is not base):
# fp3-base fp3-alias | fp3-alias fp3-base | fp3-base fp3-alias | the same for res130 and both = 18 arms, ~70 min.
# 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.
# Reported: decode tok/s per turn, tokens/round, ms/round (decode wall / rounds), expert slots, lowest free VRAM (the reserve arms must keep it above vanilla's 315 MiB), and the
# CPU-pool entries / pool wait per window. Vanilla is not run here.
set -uo pipefail
D=/data/leleka-e2e/decode/dt
LOCK=/data/leleka-e2e/gpu.lock
OUTR=/data/leleka-e2e/runs/footprint3-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:-"fp3-base-noseed fp3-alias-noseed fp3-alias-noseed fp3-base-noseed fp3-base-noseed fp3-alias-noseed fp3-base-noseed fp3-res130-noseed fp3-res130-noseed fp3-base-noseed fp3-base-noseed fp3-res130-noseed fp3-base-noseed fp3-both-noseed fp3-both-noseed fp3-base-noseed fp3-base-noseed fp3-both-noseed"}
BINDIR=${BINDIR:-bin-footprint3a}
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
export LELEKA_ORIGINAL_SERVE_SEED=off
case $arm in
fp3-base-noseed) ;;
fp3-alias-noseed) export LELEKA_PROMPT_EMBED_ALIAS=1 ;;
fp3-res130-noseed) export LELEKA_ORIGINAL_SERVE_DECODE_RESERVE_MIB=130 ;;
fp3-both-noseed) export LELEKA_PROMPT_EMBED_ALIAS=1 LELEKA_ORIGINAL_SERVE_DECODE_RESERVE_MIB=130 ;;
*) 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 "footprint3-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
fp3-base-noseed|fp3-alias-noseed|fp3-res130-noseed|fp3-both-noseed) 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 and per arm, then the adjacent pairs (run numbers 2k-1 and 2k, one base and one candidate, in whatever order)
python3 -I - "$OUTR" <<'PY'
import glob, json, os, re, statistics, sys
root = sys.argv[1]
def run_number(path):
tail = path.rsplit("-r", 1)[-1]
tail = re.sub(r"\D+$", "", tail)
return int(tail) if tail.isdigit() else 0
def load(d):
sess = json.load(open(os.path.join(d, "long-session.json")))
reqs, prof = [], None
slots, lowest = None, 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 "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
elif "leleka-serve expert cache" in ln and slots is None:
slots = int(re.search(r"expert cache (\d+) slots", ln).group(1))
m = re.search(r"DBG vram .*lowest note so far (\d+) MiB", ln)
if m:
lowest = int(m.group(1)) if lowest is None else min(lowest, int(m.group(1)))
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
agg = float("nan")
if p and rounds and "round.verify_commit" in p and "round.finish" in p:
agg = (p["round.verify_commit"] + p["round.finish"]) / rounds
rows.append(dict(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")), ms_agg=agg))
return rows, slots, lowest
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, slots, lowest) in runs.items():
print("%-26s slots %s lowest-free-VRAM %s MiB | tok/s %s | tok/round %s | ms/round %s | ms/round(dt_agg) %s" % (n, slots, lowest,
" ".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), " ".join("%.2f" % r["ms_agg"] for r in 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)]
print("ARM %s (%d runs, slots %s): tok/s per turn %s all-turn %.1f | tokens/round %s | ms/round %s" % (a, len(ns), sorted({runs[n][1] for n in ns}),
" ".join("%.1f" % x for x in mean(lambda r: r["tps"])), statistics.mean(mean(lambda r: r["tps"])),
" ".join("%.2f" % x for x in mean(lambda r: r["tok_round"])), " ".join("%.2f" % x for x in mean(lambda r: r["ms_round"]))))
for cand in [a for a in by if a != "fp3-base-noseed"]:
diffs, per_turn = [], []
for k in range(1, 40):
pair = [n for n in runs if (run_number(n) + 1) // 2 == k]
b = [n for n in pair if arm(n) == "fp3-base-noseed"]; c = [n for n in pair 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)
diffs.append(100 * (mc / mb - 1)); per_turn.append([100 * (y["tps"] / x["tps"] - 1) for x, y in zip(rb, rc)])
print("pair %d %s vs base: all-turn tok/s %.1f vs %.1f (%+.2f %%), slots %s vs %s" % (k, cand, mc, mb, diffs[-1], runs[c[0]][1], runs[b[0]][1]))
if diffs:
print("%s over fp3-base-noseed: %d pairs, mean %+.2f %% (min %+.2f max %+.2f); per-turn mean %s" % (cand, len(diffs), statistics.mean(diffs), min(diffs), max(diffs),
" ".join("%+.2f" % statistics.mean(c[t] for c in per_turn) for t in range(5))))
PY
+79
View File
@@ -0,0 +1,79 @@
#!/usr/bin/env bash
# claude/slots-footprint3, goal (3): placement-class relative gate of the LARGER expert cache (main: 12,144 slots, + MTP dense sharing) against the previous 11,568 (LELEKA_FOOTPRINT_LEGACY=1), copy of dt-q4.sh.
# Teacher-forced replay of the 256k-class capture night5-long-256k (5 requests, recorded replies, decode capped at 240 tokens each => >= 1000 forced rows), production shape, STATIC tier
# (ADAPT_EVERY=0: the placement is reproducible), seed OFF, upstream ranked profile, EXPERT_SLOTS=auto with the card-bound budget (31 GiB), RT directory set (the product draft path), top-16 logprobs per row.
# ONE test binary (dt/rt-footprint3b) for the three processes:
# ref LELEKA_FOOTPRINT_LEGACY=1: the previous footprint (11,568 slots), arm 0 is the reference
# new defaults: the larger cache
# ph LELEKA_FOOTPRINT_LEGACY=1 with the PLACEHOLDER profile (layer-major, unranked): the CONTROL, a placement perturbation the earlier gates accepted as the yardstick
# Criterion (notes.md): rows >= 1000 in both comparisons, d_top1 p99 and max of new-vs-ref <= 1.5x those of control-vs-ref, argmax flips <= 2.8 %.
# Install: cp scripts/e2e/decode/footprint3-gate.sh /data/leleka-e2e/decode/dt/jobs/ ; stub ~/work/gpu-runs/holder2/jobs/footprint3-gate.sh (exec bash that file) ; one line in jobs/PRIORITY. ~40 GPU-min.
set -uo pipefail
LOCK=/data/leleka-e2e/gpu.lock
D=/data/leleka-e2e/decode/dt
O=/data/leleka-e2e/runs/footprint3-gate
BIN=${BIN:-$D/rt-footprint3b}
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/para/work/leleka/models/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=31
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=auto LELEKA_CHAIN=all
unset LELEKA_FOOTPRINT_LEGACY LELEKA_PROMPT_EMBED_ALIAS LELEKA_ORIGINAL_SERVE_DECODE_RESERVE_MIB
export LELEKA_ORIGINAL_SERVE_ADAPT_EVERY=0 LELEKA_ORIGINAL_SERVE_CPU_WORKERS=1 LELEKA_SPEC=4 LELEKA_SPEC_SUFFIX=0
sha256sum $BIN
shape="reply@8192/8192!orig!fast!nocluster!store!qpf!gpool!mspan"
run() { # label legacy(0|1) arms [profile]
PROFILE=${4:-/data/leleka-e2e/decode/assets/expert-profile-upstream.bin}
got=0
for i in $(seq 1 1080); do
if mkdir $LOCK 2>/dev/null; then echo "footprint3 gate $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 legacy=$2 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 LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE=$PROFILE LELEKA_ORIGINAL_SERVE_REPLAY=yes LELEKA_ORIGINAL_SERVE_SEED=off LELEKA_FOOTPRINT_LEGACY=$2 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=240 LELEKA_REPLAY_FORCE=1 LELEKA_REPLAY_ARMS=$3 \
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|footprint:" $O/$1.full | cut -c1-300 | tail -8
rm -f $LOCK/owner; rmdir $LOCK 2>/dev/null
sleep 15
}
shape1="$shape"
run ref 1 "G1=$shape1"
run new 0 "S1=$shape1"
run ph 1 "P1=$shape1" /data/leleka-e2e/decode/assets/profile-placeholder.bin
T=$D/tools
python3 - <<PY
import sys
sys.path.insert(0, "$T")
import q_pair, q_lib
off=q_pair.rows_of("$O/ref.full",0); on=q_pair.rows_of("$O/new.full",0); ph=q_pair.rows_of("$O/ph.full",0)
def stat(a,b,label):
common=sorted(set(a)&set(b)); d=[]; flips=0
for k in common:
if a[k].top1!=b[k].top1: flips+=1
v=b[k].lp(a[k].top1)
if v is not None and (a[k].topk[0][1]!=v): d.append(abs(a[k].topk[0][1]-v))
d.sort()
p99=q_lib.quantile(d,.99) if d else 0.0; mx=d[-1] if d else 0.0
print("%s: common %d, different %d, flips %d (%.2f%%), d_top1 p99 %.4f max %.4f"%(label,len(common),len(d),flips,100.0*flips/max(len(common),1),p99,mx))
return len(common),p99,mx,flips
c=stat(off,ph,"CONTROL placeholder placement (11,568 slots) vs upstream placement (11,568 slots)")
s=stat(off,on,"LARGER CACHE (new) vs previous (ref), upstream profile")
ok = s[0]>=1000 and c[0]>=1000 and s[1]<=1.5*c[1] and s[2]<=1.5*c[2] and s[3]/max(s[0],1)<=0.028
print("CRITERION (rows>=1000 both, p99 and max <= 1.5x control, flips <= 2.8%%):", "PASS" if ok else "FAIL/INCONCLUSIVE")
PY
sha256sum $O/*.full
date -u +%FT%TZ
+71
View File
@@ -0,0 +1,71 @@
#!/usr/bin/env bash
# claude/slots-footprint3 identity gate for share_rt_mtp_dense (the MTP dense roles shared with the RT bank, proven byte-equal at startup) together with the footprint2 changes, against the same binary with
# LELEKA_FOOTPRINT_LEGACY=1 (both buffers held as on main), at an EQUAL FIXED slot count. Nothing reads the two buffers, so the expectation is BITWISE identity (0 flips, max |dlogprob| 0).
# HOLDER JOB (copy of speedtrain3-id.sh / draftvocab-id.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), EXPERT_SLOTS=8000 per-layer, seed OFF, LELEKA_SPEC=4, ONE test binary (dt/rt-footprint3b) for both
# processes. LELEKA_ORIGINAL_SERVE_RT_DIR is set in EVERY process (the product path, `--mtp-rt-dir`); without it the replay stack takes the pack-driven draft and the change does not apply.
# p1 idLegacy LELEKA_FOOTPRINT_LEGACY=1, two identical arms I1 I2 (the A/A noise floor, expected 0)
# p2 idFp3 defaults, two arms I1 I2
# ~8 GPU-min a process, 2 processes, one at a time under gpu.lock; about 20 min.
# Install: cp scripts/e2e/decode/footprint3-id.sh /data/leleka-e2e/decode/dt/jobs/footprint3-id.sh; stub in ~/work/gpu-runs/holder2/jobs/footprint3-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/footprint3-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
for f in $D/rt-footprint3b $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-footprint3b
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 "footprint3 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-footprint3b "LELEKA_FOOTPRINT_LEGACY=1" "I1=$shape,I2=$shape"
run idFp3 rt-footprint3b "LELEKA_X=1" "I1=$shape,I2=$shape"
T=$D/tools
PROCS="idLegacy idFp3"
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 - <<PY
import sys
sys.path.insert(0, "$T")
import q_pair
rows = {p: [q_pair.rows_of("$O/%s.full" % p, i) for i in (0, 1)] for p in ("idLegacy", "idFp3")}
q_pair.compare(rows["idLegacy"][0], rows["idLegacy"][1], "legacy footprint, arm1 against arm0 (A/A noise floor)")
q_pair.compare(rows["idFp3"][0], rows["idFp3"][1], "footprint3b, arm1 against arm0 (A/A)")
q_pair.compare(rows["idLegacy"][0], rows["idFp3"][0], "footprint3b against legacy, arm0")
q_pair.compare(rows["idLegacy"][1], rows["idFp3"][1], "footprint3b against legacy, arm1")
PY
sha256sum $O/*.full
date -u +%FT%TZ