From eb9470545f86f4c8653247204af3bbb99d26654c Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Fri, 23 Oct 2026 16:13:53 +0200 Subject: [PATCH] scripts/profile: window loader fixes, jobs 9003/9004/9062 --- scripts/profile/jobs/9003-ledger-guard-grid.sh | 13 +++++++++++++ .../profile/jobs/9004-ledger-decode-aligned.sh | 10 ++++++++++ scripts/profile/jobs/9062-ledger-decode-hit.sh | 16 ++++++++++++++++ scripts/profile/lct.py | 12 +++++++++++- scripts/profile/lct_ledger.py | 11 +++++++---- 5 files changed, 57 insertions(+), 5 deletions(-) create mode 100644 scripts/profile/jobs/9003-ledger-guard-grid.sh create mode 100644 scripts/profile/jobs/9004-ledger-decode-aligned.sh create mode 100644 scripts/profile/jobs/9062-ledger-decode-hit.sh diff --git a/scripts/profile/jobs/9003-ledger-guard-grid.sh b/scripts/profile/jobs/9003-ledger-guard-grid.sh new file mode 100644 index 00000000..59fe6925 --- /dev/null +++ b/scripts/profile/jobs/9003-ledger-guard-grid.sh @@ -0,0 +1,13 @@ +# claude/ledger: QSA prompt guard grid (LELEKA_PREFILL_GUARD_GRID=64 = literal 64 blocks; default = full grid), aligned copies on in both arms, binary rt-ledger2 (all four guard launch sites). +# bit gate (FNV of R per chunk + greedy ids), a CUPTI trace of the new arm, timing ABAB untraced. +source ~/work/ledger/ledger-common.sh +mem_ok 30 || { echo "abort: MemAvailable < 30 GiB"; exit 3; } +export BIN=$LD/bin/rt-ledger2 +header +port_long hash-G 16000 1 PREFILL-PROFILE 0 9 LELEKA_TRACE_PREFILL_R=1 +port_long port-16k-G 16000 2 PREFILL-PROFILE 2 9 X=1 +for r in 1 2; do + port_long ab-G64-$r 16000 2 PREFILL-PROFILE 0 9 LELEKA_PREFILL_GUARD_GRID=64 + port_long ab-G-$r 16000 2 PREFILL-PROFILE 0 9 X=1 +done +date -u +%FT%TZ diff --git a/scripts/profile/jobs/9004-ledger-decode-aligned.sh b/scripts/profile/jobs/9004-ledger-decode-aligned.sh new file mode 100644 index 00000000..a3f6d0b7 --- /dev/null +++ b/scripts/profile/jobs/9004-ledger-decode-aligned.sh @@ -0,0 +1,10 @@ +# claude/ledger: the port's decode windows aligned with the Original's (jobs 906/9062 trace requests 3-6 = corpus prompts 2 and 3, each twice): +# the port's smoke prints one "DBG profile request" per request (5 smoke requests + corpus 0 pass 0/1 = 7), so the window starts after the 7th and covers +# corpus 1 pass 0/1, corpus 2. Standard profile and the corpus-own profile (high hit rate). +source ~/work/ledger/ledger-common.sh +mem_ok 60 || { echo "abort: MemAvailable < 60 GiB"; exit 3; } +header +CP=$LD/corpus-profile.bin +port_corpus port-corpus-b 7 10 +[ -e $CP ] && port_corpus port-corpus-hit-b 7 10 LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE=$CP +date -u +%FT%TZ diff --git a/scripts/profile/jobs/9062-ledger-decode-hit.sh b/scripts/profile/jobs/9062-ledger-decode-hit.sh new file mode 100644 index 00000000..b844ac47 --- /dev/null +++ b/scripts/profile/jobs/9062-ledger-decode-hit.sh @@ -0,0 +1,16 @@ +# claude/ledger: decode ledger in the regime of real agent sessions (high tier hit rate): a STATIC tier (2048 slots/layer) ranked by the corpus's OWN routing. +# 1) the Original serves the 6-prompt corpus once with --dump-routing (untraced); 2) tools/make_profile.py --no-base turns the trace into a profile; +# 3) port (traced window) and Original (traced window) run the corpus again with that profile, static (adapt 0). +source ~/work/ledger/ledger-common.sh +mem_ok 60 || { echo "abort: MemAvailable < 60 GiB"; exit 3; } +header +RT=$LD/corpus.routing; CP=$LD/corpus-profile.bin; rm -f $RT $CP +R=$G/round-profile/original-requests.txt +OF="--prefill 2048 --max-context 4096 --spec 4 --suffix-draft 3 --spec-min-p 0.5 --expert-cache 2048 --expert-cache-per-layer --pcie-frac 0.55 --adapt-every 0" +orig_serve orig-routing-dump 0 0 "$OF --expert-profile $PROFILE --dump-routing $RT" $R +ls -la $RT +python3 $G/round-profile/make_profile.py $RT --no-base --out $CP 2>&1 | tail -3 +ls -la $CP || { echo "no profile"; exit 4; } +port_corpus port-corpus-hit 2 10 LELEKA_ORIGINAL_SERVE_EXPERT_PROFILE=$CP +orig_serve orig-corpus-hit 3 10 "$OF --expert-profile $CP" $R +date -u +%FT%TZ diff --git a/scripts/profile/lct.py b/scripts/profile/lct.py index 502aabfc..ebb1edae 100644 --- a/scripts/profile/lct.py +++ b/scripts/profile/lct.py @@ -34,9 +34,14 @@ class Trace: self.path = path self._win = window_ms self.meta = {} - for line in open(os.path.join(path, "meta.txt")): + text = open(os.path.join(path, "meta.txt"), errors="replace").read() + for line in text.split("\n"): k, _, v = line.strip().partition(" ") self.meta[k] = v + for key in ("window_start", "window_stop"): # tolerate a meta.txt damaged by a window cut at exit (old tracer) + m = re.search(key + r" (\d+)", text) + if m: + self.meta[key] = m.group(1) self.names = {} p = os.path.join(path, "strings.tsv") if os.path.exists(p): @@ -230,6 +235,11 @@ def chunk_windows(full_log, trace_dir): if os.path.exists(cand): done = json.load(open(cand)) break + if done is None: # a window that was cut at process exit (old tracer): recover the bounds from meta.txt + text = open(os.path.join(trace_dir, "meta.txt"), errors="replace").read() + m0 = re.search(r'"unix_ms_start":(\d+)', text) + m1 = re.search(r'"unix_ms_stop":(\d+)', text) + done = {"unix_ms_start": int(m0.group(1)) if m0 else 0, "unix_ms_stop": int(m1.group(1)) if m1 else 1 << 62} t0 = done["unix_ms_start"] / 1000.0 t1 = done["unix_ms_stop"] / 1000.0 out = [] diff --git a/scripts/profile/lct_ledger.py b/scripts/profile/lct_ledger.py index 84b09373..596a34e3 100644 --- a/scripts/profile/lct_ledger.py +++ b/scripts/profile/lct_ledger.py @@ -165,8 +165,11 @@ def main(): ap.add_argument("--chunk", type=int, default=None, help="with --p-marker/--o-marker: which chunk (0-based) to compare") a = ap.parse_args() rules = load_map(a.map) - P = L.Trace(a.port) - O = L.Trace(a.orig) + # explicit windows are applied while loading (a 180k trace has millions of records) + pw = (a.p_t0 or 0, a.p_t1) if a.chunk is None and a.p_t1 is not None else None + ow = (a.o_t0 or 0, a.o_t1) if a.chunk is None and a.o_t1 is not None else None + P = L.Trace(a.port, window_ms=pw) + O = L.Trace(a.orig, window_ms=ow) if a.chunk is not None: if a.p_marker: a.p_t0, a.p_t1 = marker_window(P, a.p_marker, a.chunk) @@ -174,8 +177,8 @@ def main(): a.o_t0, a.o_t1 = marker_window(O, a.o_marker, a.chunk) print("chunk %d: port window %.1f..%.1f ms (%.1f ms), original window %.1f..%.1f ms (%.1f ms)\n" % ( a.chunk, a.p_t0, a.p_t1, a.p_t1 - a.p_t0, a.o_t0, a.o_t1, a.o_t1 - a.o_t0)) - for tr, t0, t1 in ((P, a.p_t0, a.p_t1), (O, a.o_t0, a.o_t1)): - if t0 is not None or t1 is not None: + for tr, t0, t1, pre in ((P, a.p_t0, a.p_t1, pw), (O, a.o_t0, a.o_t1, ow)): + if pre is None and (t0 is not None or t1 is not None): lo = tr.t0 + int((t0 or 0) * 1e6) hi = tr.t0 + int(t1 * 1e6) if t1 is not None else tr.t1 tr.clip(lo, hi)