Root-only (LELEKA_VERIFY_WINDOW_GPU=yes): verify_fetch_spans_kernel and
verify_rebase_ptrs_kernel with pcie_stage's launch geometry stage five
experts' gate/up/down spans into staging slots exactly as the DMA path lays
them out and point ptr2[q] at each slot, leaving later table entries alone.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the expert tier's prompt loan, every request refilled the lent slots
(720 on the 5090 profile, ~49 ms of copies) at the end of the prompt phase
and only then assembled the verifier, whose window/commit graph capture is
~110 ms of host work. The refill is now queued once the canonical GDN image
is uploaded (assemble's after_prepare hook), runs during the capture, and is
completed (sync_queued) before the first window reads the cache, so every
window sees the same resident set as before. A decode phase that stops
before the capture refills as before. LELEKA_SERVE_REFILL_OVERLAP=off keeps
the previous order (A/B control).
The verifier itself is still assembled per request: its window resources
borrow the stack's dense/MoE caches, which the prompt path mutates, and the
QSA owners move one way into its journal (see docs/original-serve.md).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
draft_committed settled the commit first: the host waited the commit event,
took and published the twelve witnesses, and only then launched the draft,
so the commit's GPU time, the publication and the draft ran back to back.
generate.cpp enqueues the draft on the commit's stream and waits only for
its tokens.
The drafter's draft_from_verifier is now also available in two halves
(launch_from_verifier: everything up to the first graph's enqueue, with the
draft stream waiting the verifier's pending commit event on the device;
finish_from_verifier: the read-back, the chain and the ring mutation's close).
The serve port launches the draft against the branch the commit will publish
(original_origin_after, validated with the session still at the window's
origin), publishes the session while the draft runs, and finishes the draft
only once the session holds exactly that origin. The device sees commit then
draft, as before; draft_from_verifier itself is launch + finish unchanged.
LELEKA_SERVE_OVERLAP=off keeps the serialized order (A/B control).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
publish_committed took the twelve resident QSA index checkpoints one by one:
each a cuMemGetInfo, a cuMemAlloc and a resident transfer that first
synchronizes the whole context, and the superseded checkpoints were freed by
cuMemFree; publish_original_verified_rows then synchronized the context once
more. Those context synchronizes also wait for work the Original runs beside
the commit (the adaptive tier's swap copies).
After the commit event the verifier is the only writer of the twelve images,
so the checkpoints are now one fenced batch (OriginalVerifier::
checkpoint_committed_qsa_all: 48 stream-ordered copies, one stream drain),
checkpoint buffers are pooled per index (a dropped checkpoint returns its
2564 bytes instead of cuMemFree), and the rows are published with
publish_original_verified_rows_fenced. Same copies of the same bytes.
LELEKA_SERVE_PUBLISH=serial keeps the previous path (A/B control).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
generate.cpp's default --pcie-mode is the copy kernel: the plan names each PCIe
expert's device alias, flag B rises at once, and the window graph copies the
blobs into staging after wait B (fetch_blobs + rebase_ptrs), so no host CUDA
call sits inside the window. The port staged the three per-tensor spans by
DMA instead (three or more cuMemcpyHtoDAsync per expert plus a host function,
issued by the pool thread between flag A and the CPU's own share).
The port's source keeps an expert as three registered spans, so the new
verify_fetch_spans_kernel (original_verify_window_pcie.cu, fetch_blobs_kernel's
uint4 grid-stride copy over three aliases per expert; nvcc 13.2.86 sm_120 PTX,
sm_86 companion) writes gate|up|down into staging slot q exactly as the DMA
path did, and rebase_ptrs points ptr2[q] at it: the staged bytes and pointers
the PCIe expert groups read are unchanged.
LELEKA_ORIGINAL_SERVE_PCIE_MODE=auto|dma|kernel (--pcie-mode): auto takes the
kernel when the bank has device aliases (not the pageable low-RAM bank), dma
keeps the previous path. The recorded mode and the per-layer span lengths are
fixed in the verifier bank; publish_gpu_plan refuses a span of another length.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Named wall-clock spans (request reset, prefill read/refill, verifier assembly
steps, per-round window/commit/publish/draft phases, the GPU pool's split,
PCIe spans and plan publication) summed per request and printed as one
DBG profile line. Off by default; one cached boolean test per span when off.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Laptop numbers (indicative, 3 prompts x 2): Original decode 8.15 tok/s / TTFT 7.2 s (KAR PLE), port 2.70 tok/s / 28.4 s;
both bottlenecks (serial CPU expert preparation, prompt-path expert copies) are being fixed on claude/pool-zero-copy and
claude/prefill-throughput. model-format now denies (instead of forbids) unsafe code for one audited mmap owner.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/laptop-profile.md: what lives in VRAM / RAM / NVMe on the RTX 3080 Laptop 16 GB + 48 GB machine for the
Original and the port, why both GGUF shards are strictly needed, the WSL2 cgroup bug that keeps the Original's
resident modes off there, the port's gaps and what this branch adds, and the measured arms (n = 6 each):
unmodified Original 8.15 decode / 12.4 prefill tok/s / TTFT 7.2 s vs port 2.70 / 3.1 / 28.4 s on the same
token IDs and KAR PLE; traced: all port decode time is in run_window (~1.0 s per verify window).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cache off and on, same requests: the resumed chat B (reused 2297 of 2364) produced
the same 38 greedy tokens as B read from 0; TTFT 1645.6 ms vs 10330.8 ms; a new chat
sharing the system prompt resumed from the root checkpoint (reused 2286, TTFT
983.3 ms). One sample per cell; the cache stays off by default.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Job 411 ran this branch's 562f35d (= e9995d8 + 791a4fa) on the RTX 5090: the conversation
smoke passes with the cache off and on; the resumed chat B equals the full read token for
token (reused 2297/2364, TTFT 1645.6 ms vs 10330.8 ms).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With part of a file-mapped bank page-locked (`pin_resident`), an H2D copy that starts in registered pages and
runs into unregistered ones is refused by the driver (CUDA_ERROR_INVALID_VALUE, first seen on the laptop run).
`MappedExpertBank::copy_pieces` cuts a `cache_source` slice at every registered boundary and the four copy
sites (prompt copy ring, cache fill, swap fill, PCIe staging) issue one copy per piece; one piece when nothing
is locked, so the default path is unchanged. original_bench.sh: the `strata` binary takes the generate
options directly.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LELEKA_CONVERSATION_CACHE=off runs the same requests with StackConfig::conversation
None (nothing reused, the second read of B must repeat the first), so a failure can
be told apart from the cache. A failed request now prints a CONV FAILED line with
the error and the stack's health before the panic.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The second batched chunk of every multi-chunk prompt was refused with
IdentityMismatch at publication: OriginalDraftSession::prepare_publication took
the driver's per-chunk bound (CompletedDraftKv::first_materialized = cell0 + r0,
i.e. the chunk's start) as the ring's whole materialized range and checked it
against end - MTP_ORIGINAL_WINDOW, so [0, start) counted as never recorded.
A chunk that records from its own start where the ring already reaches now
continues the earlier range; a chunk that skipped rows still starts a new one.
Found by job 311 (8000-token prompt, LELEKA_BRINGUP_TRACE): chunk 2 at
first=2048 failed in pending.publish(). The refusal now traces its operands.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Result recorded in LeaseVibe: port vs Original deviation equals the Original's own deviation between its expert settings
(median max |dlogprob| 0.292 vs 0.287, top-1 differs 4/120 vs 3/120); KAR PLE rows bit-identical (1744/1744).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Results (3 prompts x 41 teacher-forced rows): port vs Original agree exactly
at the embedding and the first GDN half; relL2 of the residual then grows
smoothly with depth (1e-3 after layer 0 FFN, ~1e-2 by layers 8-13, 5-15e-2
by layers 28-44). The Original's own GPU-expert-cache vs CPU-expert arms show
the same profile and the same logprob spread (median 0.287 vs port 0.292).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`LELEKA_ORIGINAL_SERVE_RESIDENT_BUDGET_GIB=N` (VRAM tier on, low-RAM file-mapped bank): after the cache is
filled from the profile, the experts it does not hold are page-locked in RAM in profile order while their
gate/up/down bytes fit N GiB, clamped like FileExpertSource::pin_cache_complement to MemAvailable less the
4 GiB headroom and a 0.25 GiB margin. The Original copies them into a page-locked arena; here the bank's own
file pages are registered read-only in place (`MappedExpertBank::pin_resident`, merged page ranges per
mapping, CU_MEMHOSTREGISTER_READ_ONLY), so they are read once, stay out of reclaim, and their copies are
DMA. The bytes are unchanged. A budget that cannot be kept is a warning (#403) and leaves nothing registered.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* tokenizer example `chat_tokens`: one user turn per line, thinking off, to comma-separated IDs, so both
engines get exactly the same token IDs (benchmarks/laptop/prompts.txt: 3 prompts, 78-88 tokens).
* leleka-runtime ignored test `original_serve_laptop_bench`: opens the Original serve stack with the
low-RAM sources (mapped experts, read-only KAR file; resident/memfd still selectable), serves every prompt
REPEAT times greedily and prints TTFT, prompt/decode phase times, prefill/decode tok/s, memory and the
output IDs of the first pass.
* scripts/laptop: original_bench.sh drives the unmodified `strata generate --serve` (setup.py's IQ3_S
arguments, conversation cache off, one GEN at a time, TTFT to the first T line); port_bench.sh runs the
test; monitor.sh samples process RSS/anon/file/shmem/locked/pinned and GPU VRAM once a second.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`InheritedKarArchive::open_read_only_file`: the archive stays on the SSD and only the PLE rows a request
reads pass through the OS file cache, like the Original's PleTable::open_kar (kar_open with payload
verification, then a read-only mapping of the file). The sealed memfd keeps 55,295,529,472 bytes of shmem
for the life of the process. Full SHA-256 and payload CRCs are still verified at load; immutability
afterwards is the operator's (regular file, one link, owned by this user, no write bits), and the reader
is reopened through /proc/self/fd with the inode rechecked.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The serve stack's routed experts came only from `load_resident_expert_source`, a 50 GB RAM copy of the
144 shard-0 banks that `MappedExpertBank` then page-locks whole: impossible on a 32-48 GB PC.
* model-format: `ResidentTensor` storage is an owned copy or a read-only MAP_SHARED mapping of the verified
shard (`VerifiedGgufFile::map_resident_tensor`, same descriptor, bounds and size checks);
`Qwen4ExpArtifact::load_mapped_expert_source` builds the same bank catalog from mappings, no RAM
admission (generate.cpp `src.set_gguf` + `FileExpertSource::open`). The crate's lint is relaxed from
forbid to deny so exactly this mapping owner can allow its mmap/munmap/slice.
* cuda-driver: a lease of mapped banks makes `MappedExpertBank` pageable: no cuMemHostRegister; every
consumer the Original serve stack uses (`cache_source` for the prompt copy ring, VRAM tier fills/swaps,
PCIe staging) copies with cuMemcpyHtoDAsync from pageable memory; the zero-copy device aliases
(`retained_span_handle`, `copy_triplet`) are refused.
* runtime: `ModelBinding::load_mapped_expert_source`.
The bytes are the file's, so consumers see what the resident copy holds. Unit test
`mapped_tensor_is_the_files_bytes_and_a_retained_owner`; model-format --lib 128 passed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The kv-streaming merge resealed crates/cuda-driver/src/qsa_prompt_resolver.ptx (0103ee9) after the sm_86
companion set was generated, so the table had no key for the new sm_120 body: the two arch_ptx unit tests
failed and the 3080 would have been handed the sm_120 image for the streamed-KV resolver.
`sm86_assets.py build` (CUDA 13.2.86) changes only that companion, MANIFEST.json and sm86_table.rs;
`sm86_assets.py check` OK (127 companions); leleka-cuda-driver --lib --features cuda-driver,sm86: 349 passed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The stack keeps every behaviour: KV format/resident config, conversation resume
with periodic/turn/root checkpoints after each published chunk, and the expert
tier. prefill_phase waits the swaps in flight, runs the conversation-aware
chunk loop (prefill_actions), and refills every lent slot on every exit path;
prefill_chunk borrows the cache's last slots for that chunk only (so the
conversation checkpoints between chunks see the whole stack) or uses the
stack's own buffers. Backend wiring keeps kv/kv_resident/conversation and the
expert tier; the driver keeps the sm86 and expert-tier-probe features; the
smoke keeps the LELEKA_SMOKE_REPEAT timing loop and adds the tier report.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TracePort now reports the wall time of each port call (validate/checkpoint/run_window/commit/draft/wait/drain...) so a traced
real-model run shows where a decode round spends its time. Prints nothing unless LELEKA_BRINGUP_TRACE is set.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflicts resolved by keeping both features: StackConfig/OriginalServeOptions carry kv_format/kv_resident and the
conversation config; leleka-inference accepts --kv/--kv-resident and --prompt-cache/--prompt-cache-every/
--prompt-cache-root/--turn-token (fixed a lost offset increment after --kv-resident in the merged parser); the smoke file keeps
both the long-context KV test and the conversation-cache test; the ensure_resolver test follows the 5-tuple
window_kv_addresses of the KV branch. Workspace type-checks (WSL, --all-targets).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
original_serve_conversation_smoke (ignored, real model): a one-token first request,
chat A, chat B = A + reply + a new turn resumed from the cache vs the same B read
from 0 (equal greedy tokens asserted, TTFT printed), then a new chat sharing the
system prompt (root checkpoint). docs/original-serve.md describes the cache, its
limits (no parking, live continuation only with the ring in step) and the run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Adaptive swaps change which experts the GPU computes between requests and the
two paths round differently; tier-off runs keep the exact assertions.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Synthetic IQ4_XS/IQ4_NL experts in a six-slot cache, one verify-window layer
group through OriginalExpertTierProbe: the resident experts' entries become
VRAM groups in routing order, every CPU entry is bit-identical to the all-CPU
run, GPU entries are within the Original's 3e-2 relative L1 of the CPU path,
and a plan naming another expert's slot is refused. RTX 5090: passed, worst
GPU-vs-CPU relative L1 1.155e-2.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
StackConfig::expert_tier (default off) opens the Original expert cache after
every other owner (literal auto/explicit sizing, profile-sized slots, retry),
fills it from the STRP profile through the registered model bank and reads
slot 0 back. Decode windows split every layer group as
expert_pool_dispatch_multi does: resident experts are VRAM groups, the last
pcie_num/256 of the misses are staged over PCIe, the rest run on the CPU pool
(which now computes only its entries and zeroes the GPU's). The adaptive tier
swaps the most-routed misses in every adapt_every rounds and publishes them
once their copies land. With a profile the prompt path borrows the cache's
last slots and every lent slot is refilled before the decode phase.
Environment switches LELEKA_ORIGINAL_SERVE_EXPERT_* select it for the backend
and the smoke, which now prints per-request prompt/decode timing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
OriginalServeOptions gains prompt_cache (0 = off, the default until the real-model
smoke passes; the Original uses 6), prompt_cache_every, prompt_cache_root and
turn_token, mapped to StackConfig::conversation; leleka-inference parses
--prompt-cache/--prompt-cache-every/--prompt-cache-root/--turn-token. Usage
reports reused_input_tokens from the stack (generate.cpp REUSED) and the outcome
line prints it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
StackConfig gains kv_format (int8 only; fp16, q4_0, k8v4 and keyless are
refused: no sealed owners) and kv_resident (default 32768 = the window every
earlier build used; raised to 20480; 0 = the whole context). open() fixes the
process window (qsa_set_kv_resident) before any QSA owner and prints the
streamed KV footprint (leleka-context KvStreamFootprint: VRAM, prompt stage,
pinned host). leleka-inference takes --kv and --kv-resident.
original_serve_long_context_streamed_kv_smoke (ignored, env-gated): one greedy
request over a 40K-token passcode prompt with a 20480-cell window.
serving_context cross-checks resident pages against the Original kv_plan.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LELEKA_TRACE_RESIDUAL=<dir> dumps the final R of each verifier window,
LELEKA_TRACE_LADDER adds a per-hc_read R ladder (2 frames per layer),
LELEKA_TRACE_PLE prints the PLE row ids per window row. scripts/numerics
holds the patch scripts for a private copy of the Original (not applied to
engine/strata) and the comparison tools.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
generate.cpp --serve's conversation cache (ConversationManager: resume from the live
session or the deepest checkpoint that prefixes the prompt, turn/root/periodic
checkpoints, root-pinned LRU chain) now drives OriginalServeStack behind
StackConfig::conversation (off by default until the real-model smoke passes).
Device side (original_serve_conversation.rs, a child of the stack): a checkpoint is the
session's Original checkpoint (immutable GDN/PLE priors + the twelve resident QSA
witnesses) plus the draft ring snapshot, taken at a published chunk boundary; restore
re-stamps it onto the current branch generation (OriginalSessionCheckpoint::
rebased_onto_current, ResidentQsaPrior::restamped), rolls the session and resident
layers back, re-anchors the ring (OriginalDraftSession::resume_at) and runs the
drafter's kv_restore(resume). Live continuation only when the ring stands at the
session's position (then settle_state runs); parking is refused (opt-in in the Original).
run_request gains resume/finish hooks; prefill reads prompt[resume..n-1] by the plan
with the cache's turn/root options. Host tests: fake-device policy binding and the
request flow.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each corpus prompt can be served N times; every pass prints prompt/produced tokens, verify rounds, time to the first emitted
round, total wall time and decode tokens/s, so the first real-model run after a fix yields indicative numbers next to the
Original's own `prefill`/`decode` lines. Indicative only: no paired A/B, single process, cache state recorded by the caller.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kv_stream_gpu (ignored, needs a device): the prompt-path and verify-window INT8
appends against the Original host reference (experimental-ref kv_q8) byte for
byte over host copy, stage and resident slots; 64 resolve calls over 40960
cells with a 20480-cell window (forced evictions) with the sealed decode
attention bit-equal over the streamed pool, a fully resident identity pool and
the prompt path's staged copy. Resolver::counters ports kv_stream_counters;
the mapped journal exposes resident_pages and stream_counters.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The pool callback can now publish the literal GpuPlanSink block of its group
(VRAM groups over completed expert-cache slots, PCIe groups staged by DMA on
the verifier's copy stream with a cuLaunchHostFunc flag-B raise, as
Verifier::fetch_dma), checked against the doorbell's mapped ids. The expert
cache gains the residency test of host_res, the adaptive tier's slot swaps on
their own non-blocking stream with event polling (apply_pending), and a
probe-only slot fill. OriginalExpertTierProbe runs one window group's post
phase eagerly for model-free device proofs (feature expert-tier-probe).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Brings claude/sm86-assets: per-architecture PTX companions under crates/cuda-driver/ptx-sm86 behind the sm86 feature (sm_120 stays
the byte-identical default), 127 companions incl. the newly sealed MMQ-group, mapped-expert-copy and scalar-MTP assets, the
double-NUL lookup fix, and scripts/gpu-bringup/regress_3080.sh (31 items pass on the 3080 in 344 s). Conflict in
desktop-core/Cargo.toml resolved by keeping both the Linux/dev dependencies and the sm86 feature.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The resolver PTX baked 8192 resident pages (--kv-resident 32768). Port the
Original's KvStreamMap::n_slots: leleka_qsa_resolve and leleka_qsa_stream_reset
take n_slots (resealed with nvcc 13.2.86, sm_120, precise flags; digests in the
window asset, the window seal plan and the ptx_abi test). Every streamed owner
sizes its resident runs and resolver state from the process-wide window
(configure_kv_resident, default 32768 cells = the previous behaviour) and
launches with its own slot count; the verify window carries it in its KV
binding. leleka-context: resident_pages_for (layer.cpp kv_plan rule),
resident_runs, stream_map_bytes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A one-token prompt runs no prompt append, so the mapped journal's resolver was never
initialised and window_kv_addresses refused at assemble. OriginalQsaMappedJournal::
ensure_resolver initialises it without touching the epoch, coverage or end (unlike
reset), idempotently; assemble calls it for the twelve owners before they move into the
QSA journal and hands the owners back on failure. Model-free GPU test (ignored, no
model) in qsa_mapped_journal.rs; the preflight probe now uses ensure_resolver.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
qsa_native_batch.ptx is stored with its own NUL and concat!(include_str!(..), "\0") adds a second, so the image
digest never matched and the sealed sm_120 image reached the driver (INVALID_PTX, code 218) in the executor probe.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>