Characterization test, no code change: A, B, A (restored, K/V retained), C (resume 0) and back to A, B, C, each restore checked cell by cell by the harness. The production serve stack binds no parking (NO_PARKING in original_serve_conversation.rs), so retain() is unreachable there; the library path clears the retained image with limit_reuse(read_from) at every request start.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The failed-read path of the reader itself already releases every ticket (upstream ebe3383a does not apply: the worker keeps running, issue after a failure queues nothing, collect reports the error), now pinned by tests with several tickets in flight at io_threads 0/1/2/default. The one remaining way to leave a ticket pending was a panic in PageSource::read_at: the worker thread died with the job's ticket still counted and the caller's collect blocked for ever. run() now turns a panic into the same sticky read error.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
cuGraphInstantiateWithFlags answering out of memory used to poison the whole CUDA context (every call after it failed, so the engine was lost; upstream a8c1d4b7 / 2a9a67c1). The refusal is not sticky and changes no state, so now:
- the instantiate step does not poison the context on that one code (every other failure still does), the half-built graph is destroyed, and a line is logged;
- a failed cuGraphUpload (a warm-up) is skipped with a line;
- OriginalVerifier::record_all names the graph that did not fit (Error::GraphOutOfMemory { window }, 0 = commit graph);
- the serve stack repeats the assembly with the windows that fit (assemble_with_window_fallback; owners come back from each failure), logs each step, and narrows the settings, controllers and MTP draft cap of every arm to the window it ended with, for the later requests too. No cap below T=2: a failure with nothing left is returned as before, but with the context intact.
Test hook for a card with room: LELEKA_TEST_WINDOW_INSTANTIATE_OOM_AT=N fails the N-th window instantiation once.
CPU tests: poison decision, error classification, cap computation, retry loop (terminates, stops at the floor, no retry on other errors), settings cap. Not verified on a GPU.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Read-only analysis of the sealed PTX (sm_120 and sm_86): the fused kernel and swiglu_entries_kernel + quantize_q8_1_kernel of mtp_original_full_head_iq (the window's routed-expert path) all use div.rn.f32; the fast-math quantizer copies (native_head_iq / native_head_native, div.approx.ftz.f32) are not used for this pair. CPU tests compare the numeric instruction multiset, flavour for flavour, and check a fast-math quantizer would be flagged. No kernel changed.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
CUDA 13.2.0/13.2.1 miscompile some sm_120 kernels (IQ2_S/IQ3_S products wrong). validate_ptx (used by compile_assets and seal_pins) now reads the nvcc build from the PTX header and rejects those builds. A tree-wide test checks that every sealed PTX names a good build (today: none bad).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Above 1 the usage counts grow without end (inf after a few hundred adaptations) and swap gains turn NaN, which breaks the swap sort; below 0 the counts flip sign (upstream 4a7e373d). Experiment knob only; the default is unchanged.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A removed unowned folder turned the 245k corpus into a ~300-token session
without any error; inputs are now frozen, hashed and checked at run start.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Needed for the slot gain: the slabs save physical bytes the Context never charged, so the
budget must rise by about that much. Smoke with this budget: ~11,568 slots, lowest free VRAM
1,035 MiB. Also the systemd unit template, the config and reconfigure tests, and the docs.
Preflight now needs 31,299 MiB free at start (was 30,720; idle 5090 reports 32,110).
Revert by restoring 32212254720. Owner confirmation required before merge.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The reserve cut was not the cause (the budget was) but it is unproven on the card; per the conservative rule only the slab ships by default. The job runs
both arms with E2E_GPU_BUDGET 31,300 MiB (the slab's savings need budget headroom; the base is card-bound at either value) and RUN_TAG lets a rerun sit beside the
earlier run directories.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
First slots-footprint A/B (7823672f): every request failed in layer 27 with BudgetExceeded. The Context charges requested bytes against its budget (30 GiB);
the dense slabs saved 540 MiB of driver rounding that the budget never counted, and the planner sized the cache from the card's free VRAM alone, so the
cache (22,765 MiB) left only 305 MiB of budget for the lazily allocated first-chunk buffers and the verifier. usable_room() = min(card free, budget -
allocated) now feeds the auto count, the per-layer and profile caps and the post-open shrink loop; the reserve is subtracted from it. Base behaviour is
unchanged (card and budget coincided to 1 MiB). Tests pin the arithmetic with the failed run's numbers.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
drafttail-ab.sh is speedtrain-ab.sh with the two ours arms speedtrain-noseed / drafttail-noseed (optional drafttail-ac-noseed =
LELEKA_SERVE_DRAFT_AFTER_COMMIT=on for attribution, v-def for vanilla in the same session), alternating, and a summary that prints the
adjacent-pair differences and the per-round ms budget from the DBG profile lines. drafttail-id.sh is dt-id2.sh with rt-speedtrain
against rt-drafttail (+ the same binary with the draft waiting for the commit): bitwise q_pair identity of the teacher-forced top-16 logprobs.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
`KarPleCache::gather` (one decode token: 16 rows) allocated a device buffer for the update records of its misses, copied into it, ran
the scatter and freed the buffer on every call. cuMemFree also waits for the whole device. With ple.device at 0.046 ms per call and
2.5 calls per round (speedtrain-ab spans) the allocation pair is a measurable part of a 0.116 ms per round span that runs before every
window launch. The cache now owns sixteen buffers, `scratch[k - 1]` of `k * 56` bytes, because the scatter's layout names the exact
byte length of its update block (a single 16-record buffer would be refused for fewer misses).
Output identity argument: the same bytes are copied into a device buffer of the same length before the same kernel call with the same
count; the kernel and the decode that follows are unchanged, and every `kar_ple_*` launch is followed by a context synchronize
(`execute`), so a reused buffer is never overwritten while the scatter reads it. The decoded rows depend only on the packets.
Test: the staging sizes are the record sizes the layout and `gather` use (CPU). Not run on a GPU: covered by the replay identity job.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
docs/experiments/vram-footprint-5090.md: stage-by-stage account from the speedtrain-ab logs (882 MiB of the 2.27 GiB gap is driver rounding, 324 MiB a second token
table, ~1 GiB the prompt/MoE/MTP side), the three reductions with estimated slots, the candidates not done, what is not verified.
slots-footprint-ab.sh: base-noseed vs slots-noseed (and the alias arm, and a short ledger arm), 100 ms card sampler, FOOTPRINT.txt per run.
slots-id.sh: replay with a static tier and an equal fixed slot count; the footprint changes must not move a logit.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
OriginalPromptEmbedding::load and OriginalNativeOutput::load(.., true) both stream the GGUF TokenEmbedding tensor (IQ4_XS, 248,320 rows of 1,360 B):
the first uploads a 324 MiB copy to VRAM for the prompt path and the MTP prefill, the second keeps the same bytes in a pinned host mapping that the
decode gather reads over PCIe. Vanilla keeps one (mapped). With the switch on, OriginalNativeEmbed::table_alias() hands the prompt path a borrowed
DeviceBuffer over that mapping (not charged, frees nothing), the native head and embedding open first, and the stack closes the prompt table before
the native embedding it aliases.
Off by default: the drafter gathers a row per draft step over PCIe beside the expert staging traffic and the effect on decode is unmeasured; the
A/B job has an arm for it and slots-id.sh a bitwise-identity arm. Tests: the switch is opt-in; a CUDA test of a borrowed alias over a cuMemHostAlloc
block (reads the host bytes, costs no device memory, survives drop; passes on the RTX 3080 laptop); an sm_120-only test of table_alias itself
(ignored, for the server).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
`VerifiedKarPleArtifact::read_rows` (one token's 16 rows, 48 positional reads) started and joined eight scoped threads on every call.
The speedtrain-ab spans show ple.read_rows at 0.119 ms per call and 2.1 calls per round (0.25 ms of a 15.0 ms round, before the window
launches), while a memory-served pread of 10-20 bytes takes about a microsecond. The call now reads the first row itself and times
it: at 20 us or less (a row is three reads) the other fifteen rows are read on the same thread; slower means the file waits for a
device, and the previous eight-thread read runs, with the next 256 calls skipping the probe so a cold archive pays one probe per 256
tokens at most. The prefill's batch and read-ahead paths are untouched.
Output identity argument: the same `read_rows_chunk` reads the same offsets into the same packet slots in every path, with the same
bounds, length and non-finite-scale refusals; only the number of threads differs. The test reads random rows of a two-partition
synthetic file through the probing, the post-cold-verdict parallel and the non-probing paths and compares every packet with the
single-thread reference, plus the refusals (row outside the table, changed archive length, row beyond the partitions).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Five passes over up to 262,144 i32 ran on the host every round: the controller's validate_current and the ledger's begin_window each
compared `committed` with `consumed`, with_sampling authenticated them twice more and range-checked the whole tail, after_verified
range-checked `consumed` once more. In the speedtrain-ab spans the host work outside the GPU grows linearly with the context:
window.sampling_setup 0.021 ms at 45k to 0.112 ms at 247k, the un-spanned part of verify_commit 0.038 to 0.098 ms, of finish_round
0.024 to 0.068 ms (about 0.19 ms per round at 247k, 1.3 % of a round, all of it before a launch or after a read-back).
`token_memo::PrefixMemo` remembers (address, length, first/middle/last token, criterion) of the buffer a check last passed over; the
next check starts at that length, and every 32nd use examines everything again. `consumed` (reserved at the request's start) and
`committed` only ever grow within a request, so a pass over the first n tokens stays true for them. Ledger, penalty history and
controller each own a memo; a request has its own ledger and controller request, so nothing carries across requests.
Output identity argument: these are assertions between two host copies of the same tokens. A passing check is the same answer as
before; a new token that differs, a different length, another buffer or a rewritten first/middle/last token fails exactly as before;
a rewrite of any other old token, which no owner can do (both vectors are append-only inside their owner), would be reported up to
32 rounds later instead of at once. Nothing the GPU runs reads these results.
Tests: token_memo (tail-only examination, address/length/criterion/probe reset, periodic full pass, random growth against the slice
comparison), ledger (100 rounds of growth, newest-token mismatch, length mismatch, rewritten old token found within FULL_EVERY, copy
at another address), the existing controller/engine suites (99 tests) pass.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Upstream enqueues the commit graph on the verifier's stream and launches the draft round graph on the drafter's own stream with no
dependency between them (core/verify.cpp set_commit_async: "the drafter (its own stream) reads only this window's final rows and its
own K/V"). The port made the draft stream wait the commit event on the device, so the commit graph (36 GDN layers, 12 QSA appends, the
PLE history; the host sees ~0.36 ms from enqueue to event) ran in front of every draft's first graph. With the 5090 spans of
speedtrain-ab (draft_committed 1.66 ms = launch 0.03 + deferred adapt 0.08 + commit.wait 0.25 + publish 0.12 + finish 1.18) the commit
is on the critical path of every round; running it beside the draft is worth up to its length per round (estimate 0.2-0.35 ms of a
15.0 ms round, not measured).
Output identity argument: the draft reads the completed window's final residual rows (verifier arena span "R"), the head ids staged in
its own mapped block, its own MTP ring and weights; it writes its own scratch, ring and mapped outputs. The commit graph reads the
window intermediates (qkv_L, h_L, gate_L, beta_L, z), writes the canonical GDN state, the QSA index images, the PLE history and the
"commit" span (verify_gdn_conv_commit_kernel, verify_gdn_step_norm_multi_kernel, verify_qsa_append_*, verify_copy_*). No span is
written by one graph and read or written by the other; neither module declares a device global. Host-side publication already ran
beside the draft's first graph, and the next window still starts only after both the commit event and the draft read-back.
The decoded ids cannot depend on which of two independent graphs ends first.
Not run on a GPU. Gate: replay logprob identity (rt-speedtrain against rt-draft-tail) and the paired A/B of scripts/e2e/decode/drafttail-ab.sh.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
5090, 5 x 245k session (runs/speedtrain-ab): the per-request verifier assembly takes 514 MiB (1,077 MiB free after the expert cache, 563 after),
and nvidia-smi at 10 s shows the card never had less than 563 MiB free in any turn, while vanilla Strata 0.2.6 starts with 389 MiB and
captures its windows down to 315 MiB. 700 + 130 - 514 = 316 MiB keeps the same floor. ExpertTierConfig::decode_headroom_mib() states that
arithmetic, a startup warning fires when an auto-sized configuration leaves less, and the default is pinned by a test. Laptop profiles
set their own DECODE_RESERVE_MIB (1024) and are untouched.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The driver rounds every cuMemAlloc above 1 MiB up to a multiple of 2 MiB (laptop probe: 3 MiB takes 4 MiB, 2.5 MiB takes 4 MiB; the 5090
token table: 322.1 MiB takes 324 MiB). The dense-weights stage of the 5090 load ledger asked for 3,890 MiB and the driver took 4,578: 688 MiB
of rounding across ~700 matrices of 0.5-10 MiB (the 48 routers of 2.5 MiB alone lose 72 MiB). The parity audit listed it as "unaccounted".
SlabAllocator packs requests of up to 16 MiB first-fit into 64 MiB slabs (a multiple of the granule), 512-byte aligned (cuMemAlloc
guarantees 256); larger ones keep their own allocation. A DeviceSlice derefs to the ordinary &DeviceBuffer every kernel entry point takes, so
no kernel code, byte, or arithmetic changes: only buffer addresses move. DeviceBuffer gets a `borrowed` flag (an alias frees nothing and is
not charged) which the view uses; the new id-less tests pin the placement (aligned, non-overlapping, in-slab, hole filling, direct limit),
the dense mix saves the rounding in a model, and a CUDA test (ignored by default, passes on the RTX 3080 laptop) reads every view back and
checks neighbours stay intact and the context is charged only the slab.
LELEKA_DENSE_SLAB=0 restores one allocation per weight (A/B arm, rollback). The dense stage prints one summary line.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The fixed VRAM footprint of ours is 2.1-2.3 GiB above vanilla's and the load ledger could not say where: the dense-weights stage shows
4,578 MiB taken for 3,890 MiB accounted. LELEKA_VRAM_LEDGER=1 records every Context::allocate by call site (innermost workspace frames of a
backtrace), removes it on free, and prints at each `vram_note` the sites that changed since the previous note, with the bytes the driver is
estimated to reserve (allocations above 1 MiB rounded up to 2 MiB, packed below, as probed on the WDDM laptop and as the 5090 token table
shows: 322.1 MiB takes 324 MiB). Off by default; the off cost is one cached bool per allocation.
`DBG vram` lines now carry the lowest free VRAM seen so far, and a new note "decode end before disassemble" reads the card after the graph
pools and every window are captured: the real low-water mark of a request, for sizing the reserve.
scripts/dev/alloc-granularity-probe.py is the offline ctypes probe of the driver's rounding.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Seed OFF is a profile setting only: the engine default (seed on) and the laptop profile are unchanged. Placement-class change, NOT bit-identical; it does not fit the strict Original
envelope (p99 <= 0.22, max <= 0.43) and neither does the control; it meets the relative criterion on 1,717 teacher-forced rows (p99 0.2500 vs control 0.2278, max 0.7567 vs 0.6751,
flips 2.10 % vs 2.59 %; limits 1.5x control and 2.8 %). Gain: 108.1 -> 137.2 tok/s decode over turns 1-4 of the frozen 245k session (3 runs per arm). Revert: remove the key or set
LELEKA_ORIGINAL_SERVE_SEED=on in the operator environment. Test: only_the_server_profile_turns_the_prompt_routing_seed_off; leleka-deploy tests 125 passed in WSL.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Once the 1,048,576-slot device row cache is full, KarPleCache::gather picked the victim of every missed row with a scan of all
entries (filter + min_by_key), and assign_slots collected every entry into a Vec per prompt chunk. A decode token with a new trigram
misses its 8 trigram-head rows (input_hash::rows), so it cost 8 full scans: ~53 ms per such token in window.ple at turn 5 of the
245k session (the cache fills only then), against 0.14 ms before.
Residents keeps the row map plus a queue of (age, row) items, pushed at every age change and valid while the map still holds the
row at that age. oldest() reads the front of the queue: O(victims + skipped), with the full scan only as the fallback when the
queue gives fewer rows than asked (the caller then refuses the chunk, as before). The planning and publishing of a gather are now
the pure functions plan_gather/publish_gather so the tests drive the production code.
The cache only decides which slot holds which row, so the decoded values are unchanged. Tests: gather victims, slots and final state
equal to the scan implementation on random sequences (4 cache sizes, 6000 gathers each, every gathered row is its own row); chunks
and gathers interleaved keep every row in its own slot and every victim among the oldest untouched rows; eviction in a full cache of
200,000 rows examines <= 40 items per miss (the scan: 200,000); the queue stays bounded.
Measured (laptop, release, full 1,048,576-row cache): old scan 7.3 ms per missed row, queue 61 ns (ignored timing probe).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The draft step attends over the 32,768-cell MTP window (512 chunks, one query): with the opt-in, the Original chunk kernel and chain_qsa_decode_merge_n of that
step become sm120_attn_daily.ptx's leleka_qsa_decode_chunk_daily / leleka_qsa_decode_merge_v2 (module slot 22 after the chain slot; the window_ids pre-launch
keys on the new chunk entry too). sm120_probe `attn512` byte-compares the pair against the Original on the draft shape and times them; it has not been run
yet (no GPU slot), so the switch stays default off.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>