prefill: empty-request probe (pf_probe.py, pf_van_probe.sh), pf_ab_job.sh PF_PKG/PF_CLIENT and the chain-pipeline variants, step-ledger rows of the host/prefill part

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Pavlo Ratushnyi
2026-11-09 15:22:31 +01:00
co-authored by Claude Sonnet 5.5
parent 1ab37e4082
commit c2f7d033dc
4 changed files with 194 additions and 4 deletions
@@ -0,0 +1,38 @@
# Step ledger, rows of the host/draft/prefill part (`hex-finish`)
The register itself is `docs/experiments/step-ledger.md` (branch `claude/speed-vs-strata-08143a`, owner session `hexagonal-44f3f4`); this file holds the rows of the part this branch (`claude/prefill-latency`) works, with the same
row ids, statuses and closing rule: a row is `fixed` only with a measured *section* delta of that very step, identity, and the end-to-end paired A/B. Owner rule 2026-11-09: no row is dropped as "below noise".
Work order: linear along the request, A (request into the engine), B (prefill), then the host rows of C (draft C1, accept C3, commit C4, publication C5).
Tools (server `/data/leleka-e2e/prefill-latency/tools`, repo `scripts/e2e/codex/prefill`): `pf_ab_job.sh` (paired A/B and identity on the replay, `PF_PKG`, `PF_CLIENT`), `pf_probe.py` (empty-request probe), `pf_van_probe.sh` (vanilla, holder-free window),
`replay_hash.py` (output hash per request).
## A. Request into the engine
Section measurement: the empty-request probe (`pf_probe.py`): two tiny prompts, one cold request of the recorded 67k body (one output token), five cached repeats of it, five tiny prompts, on our stack (`runs/probe/LEL`, plain `A` and profiled `AP`)
and on vanilla 0.2.6 (`runs/probe/VANL`, lossy off). Client wall and first-event time per request; our per-request host spans from `LELEKA_SERVE_PROFILE`. Jobs `pr-lel`, `pr-van` (queued behind `pf-ab4`).
| id | step | LEL | VANL | difference | source | status |
| --- | --- | ---: | ---: | ---: | --- | --- |
| A1 | HTTP, gateway and proxy time per request | probe pending | probe pending | | `runs/probe` | fixing (probe queued) |
| A2 | tokenizer and prompt assembly | probe pending (long cached prompt minus tiny) | probe pending | | `runs/probe` | fixing (probe queued) |
| A3 | prefix-cache lookup and import | `request.resume` 2.53 + `ctrl.begin_request` 0.60 + `prefix.import_session` 0.80 + `prefix.draft_resume_at` 1.05 + `prefix.mtp_kv_restore` 0.61 + `prefix.layer_index` 0.38 = 5.97 ms per request | not separable | | PROFILE `runs/dc1` (60 requests) | fixing (VANL by the probe) |
## B. Prefill
PROFILE of the 60 requests of `runs/dc1` (two boots, 30 requests of VANL nestng-crm-r2 each), mean per request: `prefill.read` 1582 ms, `prefill.refill` 139.9, `decode.assemble` 101.5 (`record_all` 85.2: capture 34.1, instantiate 21.1),
`decode.disassemble` 11.7, prefix-cache parking in the request path `prefix.export_kv` 19.0 + `export_index` 2.3 + `park_tail` 14.7 + `park_block` 6.5 + `after_prefill` 9.4 + `after_chunk` 0.7 + `after_decode` 12.5 = 65.1 ms, `cpu.admit` 43.2 ms (819 calls).
| id | step | LEL | VANL | difference | status |
| --- | --- | ---: | ---: | ---: | --- |
| Q1-Q3 | prefill per request, by size class, throughput | see the ledger | | the loan ladder (`LELEKA_PREFILL_LOAN_TIERS=1`) paired on the sparse holder, n=5 blocks per arm: **-3.1 s per 30-request session, +-0.5**; requests with at most 2048 new tokens -151 ms (faster in 19 of 19); more than 2048 new tokens -22 ms (not significant) | fixing (n=10 `pf-ab4`; profile switch `rtx5090-32g*.json` ready, not committed) |
| Q4, Q5 | `prefill.read` fixed part 485-581 ms; `moe.ring` 355 ms in a small tail | | vanilla reads tails of at most 64 tokens through verify windows (width 4) | **root cause**: `original_serve_stack_prefill_phase.rs` `prompt_options` sets `force_batched: true` ("the verify-window read of short prompts needs the verifier during the prompt phase"); the planner (`engine-core/src/prompt/prompt_options.rs`) already emits `PromptPath::Verify` actions and the executor has a `verify_window` hook (`original_prompt_executor_drop.rs:63`) that is not implemented. Design and implementation pending |
| Q6 | `prefill.refill` | 139.9 ms mean per request | none | the ladder refills 512/2048 rows instead of 8192: 20 ms against 137 ms for chunks that fit (ab3); `LELEKA_REFILL_DEFER` earlier: end-to-end +0.56 % (CI -0.15..+1.27) | fixing |
| Q7 | `decode.assemble` | 101.5 ms | none (vanilla keeps its graphs) | open |
## C1. Draft (host part)
| id | step | LEL | VANL | difference | status |
| --- | --- | ---: | ---: | ---: | --- |
| O9 | draft chain steps and idle between them | 0.272 ms per round (2.38 boundaries x 114 us, CUPTI `CL.1`) | idle inside the draft 0.52 ms (4.5 streams) | S1 `LELEKA_DRAFT_CHAIN_PIPELINE` (code `1ab37e408`, opt-in): all chain steps of a greedy draft with min_p 0 enqueued back to back, one drain, flags read once; step graphs `MtpChain` recorded without the flag resets | fixing (package `pkg-s1`, identity and profile pair `s1-id1`, paired A/B `s1-ab1`) |
| O8 | draft finite and q8 guard checks | 0.162 ms | none | S2' not started | open |
+12 -4
View File
@@ -9,6 +9,8 @@
# PF_OUT result directory (default $PL/runs/main)
# PF_MAX requests per cell (default all)
# PF_ROOT the task directory (default /data/leleka-e2e/prefill-latency): pkg/bin (binaries under test), state/, prefix/, tools/
# PF_CLIENT the client script in the tools directory (default replay_hash.py; pf_probe.py = the empty-request probe of ledger rows A1-A3)
# PF_PKG the package directory (default $PF_ROOT/pkg): bin/ and SHA256SUMS; lets a second build run next to the first
# Variants (engine environment of the `leleka up` process):
# A shipped (the prompt loan is the full 8192-row loan for every chunk)
# L the prompt loan ladder: LELEKA_PREFILL_LOAN_TIERS=1 (a chunk of at most 512 / 2048 rows borrows and refills a smaller loan)
@@ -17,6 +19,8 @@
# P as A with the step profile (LELEKA_SERVE_PROFILE=1: one `DBG profile request` line of host spans per request)
# LP as L with the step profile
# LT as L with the bring-up trace (LELEKA_BRINGUP_TRACE=1: the driver error behind a failed chunk)
# C as A with the draft chain pipeline (LELEKA_DRAFT_CHAIN_PIPELINE=1: the chain steps enqueued back to back, one drain)
# CP as C with the step profile AP as A with the step profile (the pair for the host spans of the draft)
set -uo pipefail
PL=${PF_ROOT:-/data/leleka-e2e/prefill-latency}
CMP=/data/leleka-e2e/codex-compare
@@ -34,9 +38,10 @@ log() { echo "[pf $(date -u +%T)] $*"; }
note() { echo "[$(date -u +%FT%TZ)] [DEV prefill-latency] $*" >>/data/leleka-e2e/decode/notes.md; }
readlink "/proc/self/fd/$FD" 2>/dev/null | grep -q '^/memfd:' || { echo "needs the holder's sealed memfd"; exit 3; }
[ -d "$G/MODEL.lock" ] || { echo "MODEL.lock is not held"; exit 3; }
AS=$CMP/ours-assets; ST=$PL/state; PFX=$PL/prefix; BIN=$PL/pkg/bin
PKG=${PF_PKG:-$PL/pkg}
AS=$CMP/ours-assets; ST=$PL/state; PFX=$PL/prefix; BIN=$PKG/bin
[ -x "$BIN/leleka" ] && [ -f "$ST/leleka.json" ] || { echo "the prefill-latency package or state is not prepared"; exit 3; }
(cd "$PL/pkg/bin" && sha256sum -c ../SHA256SUMS >/dev/null 2>&1) || { echo "the package binaries do not match $PL/pkg/SHA256SUMS"; exit 3; }
(cd "$BIN" && sha256sum -c ../SHA256SUMS >/dev/null 2>&1) || { echo "the package binaries do not match $PKG/SHA256SUMS"; exit 3; }
got=0; for _ in $(seq 1 4320); do if mkdir "$LOCK" 2>/dev/null; then echo "prefill-latency $(date -u +%FT%TZ) $RUN" >"$LOCK/owner"; got=1; break; fi; sleep 5; done
[ $got = 1 ] || { echo "GPU lock held by: $(cat $LOCK/owner 2>/dev/null)"; exit 3; }
SUP_PID=; MON_PID=
@@ -50,7 +55,7 @@ COMMON="--assets $AS --state-dir $ST --prefix $PFX --bin-src $BIN --cublas-dir $
for v in $VARS; do
D=$RUN/$v; mkdir -p "$D"; vb=${v%%.*}
[ -f "$D/replay.jsonl" ] && { log "variant $v already done: skipped"; continue; }
unset LELEKA_PREFILL_LOAN_TIERS LELEKA_TRACE_PREFILL_R LELEKA_SERVE_PROFILE STRATA_VERIFY_PROFILE LELEKA_REFILL_DEFER LELEKA_BRINGUP_TRACE
unset LELEKA_PREFILL_LOAN_TIERS LELEKA_TRACE_PREFILL_R LELEKA_SERVE_PROFILE STRATA_VERIFY_PROFILE LELEKA_REFILL_DEFER LELEKA_BRINGUP_TRACE LELEKA_DRAFT_CHAIN_PIPELINE
case $vb in
A) ;;
L) export LELEKA_PREFILL_LOAN_TIERS=1;;
@@ -59,6 +64,9 @@ for v in $VARS; do
P) export LELEKA_SERVE_PROFILE=1;;
LP) export LELEKA_PREFILL_LOAN_TIERS=1 LELEKA_SERVE_PROFILE=1;;
LT) export LELEKA_PREFILL_LOAN_TIERS=1 LELEKA_BRINGUP_TRACE=1;;
C) export LELEKA_DRAFT_CHAIN_PIPELINE=1;;
CP) export LELEKA_DRAFT_CHAIN_PIPELINE=1 LELEKA_SERVE_PROFILE=1;;
AP) export LELEKA_SERVE_PROFILE=1;;
*) echo "unknown variant $v"; continue;;
esac
export LELEKA_SPEC_STATS=1
@@ -74,7 +82,7 @@ for v in $VARS; do
log "ready after $(( $(date +%s) - t0 )) s"
"$PFX/bin/leleka" status --state-dir "$ST" --json >"$D/status.json" 2>&1
args=(); for c in $CELLS; do args+=(--cell "$c"); done
python3 -I "$PL/tools/replay_hash.py" "${args[@]}" --url http://127.0.0.1:8081 --model qwen-iq3 --key-file "$ST/api-key" --out "$D/replay.jsonl" --max-requests "$MAXR" >"$D/replay.out" 2>&1
python3 -I "$PL/tools/${PF_CLIENT:-replay_hash.py}" "${args[@]}" --url http://127.0.0.1:8081 --model qwen-iq3 --key-file "$ST/api-key" --out "$D/replay.jsonl" --max-requests "$MAXR" >"$D/replay.out" 2>&1
log "replay rc=$? $(wc -l <"$D/replay.jsonl") requests"
cp "$ST/logs/engine.log" "$D/engine.log" 2>/dev/null; cp "$ST/logs/requests.log" "$D/requests.log" 2>/dev/null
stop_stack; kill "$MON_PID" 2>/dev/null; MON_PID=
+105
View File
@@ -0,0 +1,105 @@
#!/usr/bin/env python3
"""Prefill fixed-latency program, step-ledger rows A1-A3 and B2: the "empty request" probe (test tooling, stdlib only).
A stack under test answers requests that do almost no model work, so what is left is the path of a request INTO the engine (HTTP and gateway, tokenizer and
prompt assembly, prefix-cache lookup and import) and the first token:
tiny a one-line prompt, one output token -> floor of HTTP + gateway + tokenizer + first token
cold request SEQ of a recorded cell as recorded, one output token (the prompt is read, not cached; not a probe of the intake, a reference)
cached the same body again, REPS times, one output token -> intake + tokenizer of a long prompt + prefix-cache lookup/import + first token
tiny again, REPS times
Same body and same client for every stack (the recorded forward bodies of a codex-compare cell, like replay_hash.py), so the differences are the stacks'.
One JSON line per request: probe, i, wall and first-event seconds, input/cached/output tokens. Usage:
pf_probe.py --cell DIR --url http://127.0.0.1:8081 --model qwen-iq3 --key-file FILE --out probe.jsonl [--seq 29] [--reps 5]
"""
import argparse
import gzip
import json
import os
import sys
import time
import urllib.error
import urllib.request
def send(url, hdr, body, timeout):
data = json.dumps(body).encode()
t0 = time.time()
rec = {"req_bytes": len(data)}
try:
req = urllib.request.Request(url.rstrip("/") + "/v1/responses", data=data, headers=hdr, method="POST")
with urllib.request.urlopen(req, timeout=timeout) as r:
rec["status"] = r.status
first = None
last = b""
for line in r:
if first is None:
first = time.time() - t0
if line.startswith(b"data:") and b"response.completed" in line:
last = line
rec["t_first_s"] = round(first or 0, 4)
if last:
u = json.loads(last[5:]).get("response", {}).get("usage", {})
rec["input_tokens"] = u.get("input_tokens")
rec["output_tokens"] = u.get("output_tokens")
rec["cached_tokens"] = (u.get("input_tokens_details") or {}).get("cached_tokens")
except urllib.error.HTTPError as e:
rec["error"] = "HTTP %d %s" % (e.code, e.read()[:300].decode("utf-8", "replace"))
except Exception as e: # recorded, the probe goes on
rec["error"] = repr(e)[:200]
rec["wall_s"] = round(time.time() - t0, 4)
return rec
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--cell", action="append", required=True)
ap.add_argument("--url", required=True)
ap.add_argument("--model", required=True)
ap.add_argument("--key-file", default="")
ap.add_argument("--out", required=True)
ap.add_argument("--max-requests", type=int, default=0, help="accepted for the replay_hash.py command line; unused")
ap.add_argument("--seq", type=int, default=29, help="1-based number of the recorded request used as the long prompt")
ap.add_argument("--reps", type=int, default=5)
ap.add_argument("--timeout", type=int, default=900)
a = ap.parse_args()
key = open(a.key_file).read().strip() if a.key_file else ""
rounds = os.path.join(a.cell[0], "proxy", "rounds")
names = sorted(n for n in os.listdir(rounds) if n.endswith(".fwd.json.gz"))
body = json.loads(gzip.open(os.path.join(rounds, names[a.seq - 1])).read())
body["model"] = a.model
body["temperature"] = 0.0
body["max_output_tokens"] = 1
# a vanilla session's reasoning blob is refused by Leleka (HTTP 400); its own sessions keep None there
for it in body.get("input") or []:
if isinstance(it, dict) and it.get("type") == "reasoning" and it.get("encrypted_content"):
it["encrypted_content"] = None
sid = body.get("prompt_cache_key") or ""
hdr = {"Content-Type": "application/json", "Accept": "text/event-stream", "session-id": sid, "thread-id": sid, "x-codex-window-id": sid + ":0"}
if key:
hdr["Authorization"] = "Bearer " + key
tiny = {
"model": a.model,
"input": [{"type": "message", "role": "user", "content": [{"type": "input_text", "text": "Say ok."}]}],
"stream": True,
"temperature": 0.0,
"max_output_tokens": 1,
}
plan = [("tiny", tiny)] * 2 + [("cold", body)] + [("cached", body)] * a.reps + [("tiny", tiny)] * a.reps
out = open(a.out, "a", encoding="utf-8")
seen = {}
for label, b in plan:
seen[label] = seen.get(label, 0) + 1
rec = {"probe": label, "i": seen[label], "seq": a.seq}
rec.update(send(a.url, hdr, b, a.timeout))
out.write(json.dumps(rec) + "\n")
out.flush()
print(json.dumps(rec), flush=True)
time.sleep(0.5)
return 0
if __name__ == "__main__":
sys.exit(main())
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# Prefill fixed-latency program (step ledger A1-A3): vanilla Strata 0.2.6 answering the empty-request probe (pf_probe.py) instead of the replay; a copy of spd-gap/tools/spd_van_job2.sh without
# the engine-side profile. Holder-free window payload (started by spd_window.sh). Test tooling, never in serving.
set -uo pipefail
SPD=/data/leleka-e2e/spd-gap
PL=/data/leleka-e2e/prefill-latency
CMP=/data/leleka-e2e/codex-compare
A=/home/para/work/leleka/models/leleka-gates/assets
G=$HOME/work/gpu-runs
LOCK=/data/leleka-e2e/gpu.lock
LOSSY=${SPD_LOSSY:-0}
RUN=${SPD_RUN:-$PL/runs/probe/VANL}
CELLS=${SPD_CELLS:-"$CMP/runs/main/VANL/nestng-crm-r2"}
MAXR=${SPD_MAX:-30}
mkdir -p "$RUN"
exec > >(tee -a "$RUN/job.log") 2>&1
log() { echo "[spd-van $(date -u +%T)] $*"; }
mkdir "$G/MODEL.lock" 2>/dev/null || { echo "MODEL.lock is held (holder still up?)"; exit 3; }
got=0; for _ in $(seq 1 4320); do if mkdir "$LOCK" 2>/dev/null; then echo "spd-gap vanilla $(date -u +%FT%TZ) $RUN" >"$LOCK/owner"; got=1; break; fi; sleep 5; done
[ $got = 1 ] || { echo "GPU lock held by: $(cat $LOCK/owner 2>/dev/null)"; rmdir "$G/MODEL.lock"; exit 3; }
S=$HOME/work/vanilla-strata/control/bin/strata
cleanup() { ( cd "$HOME/work/vanilla-strata/control" && "$S" launch --stop >/dev/null 2>&1 ); sleep 5; rm -f "$LOCK/owner"; rmdir "$LOCK" 2>/dev/null; rmdir "$G/MODEL.lock" 2>/dev/null; }
trap cleanup EXIT
[ -z "$(nvidia-smi --query-compute-apps=pid --format=csv,noheader 2>/dev/null)" ] || { echo "something uses the GPU"; exit 3; }
export XDG_CONFIG_HOME=$RUN/xdg-config XDG_STATE_HOME=$RUN/xdg-state
mkdir -p "$XDG_CONFIG_HOME/strata" "$XDG_STATE_HOME"; cp ~/.config/strata/settings.json "$XDG_CONFIG_HOME/strata/"
if [ "$LOSSY" = 1 ]; then unset STRATA_ROUTE_TAIL_SKIP STRATA_PREFILL_CPU_SHARE; else export STRATA_ROUTE_TAIL_SKIP=0 STRATA_PREFILL_CPU_SHARE=0; fi
export LD_LIBRARY_PATH=$HOME/cuda-toolkits/cublas-12.9.1.4/lib:$HOME/cuda-toolkits/13.2.2/lib64:${LD_LIBRARY_PATH:-}
cd "$HOME/work/vanilla-strata/control"
t0=$(date +%s)
timeout 2400 "$S" launch --model iq3_s --family qwen --model-path "$A/model" --context 256k --kv int8 --vision off --parallel 1 --tune skip --access local --port 8090 --no-api-key --no-tui --yes >"$RUN/launch.out" 2>&1
log "launch rc=$? ready after $(( $(date +%s) - t0 )) s"
curl -fs http://127.0.0.1:8090/v1/models >"$RUN/models.json" || { log "vanilla did not become ready"; exit 4; }
MODEL=$(python3 -c "import json;print(json.load(open('$RUN/models.json'))['data'][0]['id'])")
args=(); for c in $CELLS; do args+=(--cell "$c"); done
python3 -I "$PL/tools/pf_probe.py" "${args[@]}" --url http://127.0.0.1:8090 --model "$MODEL" --out "$RUN/replay.jsonl" --max-requests "$MAXR" >"$RUN/replay.out" 2>&1
log "replay rc=$? $(wc -l <"$RUN/replay.jsonl") requests"
cp "$XDG_STATE_HOME/strata/launch/iq3_s-256k.engine.log" "$RUN/engine.log" 2>/dev/null
log "done"