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_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>
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>
Brings claude/api-over-rust-engine (strata-next GrpcBackend worker, scripted engine, Codex request fields, flock flake fix) and
its base claude/m2-control-plane (delivery gap audit, non-panicking control-plane logging, leleka-seal-exec, Dockerfile fix,
run recipe docs) onto the GPU bring-up fixes. No conflicts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every bring-up eprintln in leleka-cuda-driver and leleka-runtime (arena/executor/prefill/draft-KV/serve-stack/TracePort tracing)
now goes through crate::bringup_trace!, which prints only when LELEKA_BRINGUP_TRACE is set. Production serving prints nothing
extra. The smoke test and the ignored probes keep their unconditional output. Type-checked with --tests on Linux (WSL).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Prompts under 64 rows hit the Original's literal RegionTooSmall fallback in the MMQ draft-KV recorder and then ran the scalar prefill on a
standalone owner whose scratch bank is not paired with the ring's main arena (validate_original_main -> InvalidQwenShape ->
InvalidDimension). The drafter now lends its stream to its own scalar owner (OriginalMtpDrafter/Actor::record_scalar_prefill).
Real model, RTX 5090: the 19-token and 56-token prompts of the smoke corpus now serve (16 resp. 10 tokens, the latter ending on <|im_end|>).
Structural evidence only; no numerical claim.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- backend_original_serve_smoke.rs: LELEKA_SMOKE_PROMPTS (one text prompt per line) is tokenized with the verified tokenizer,
served greedily for LELEKA_SMOKE_MAX_NEW tokens (LELEKA_SMOKE_MIN_P sets spec_min_p) and printed as ids so the Original
(strata --tokens-file ...) can be run on the same ids.
- original_serve_native.rs: LELEKA_TRACE_LOGPROBS=<k> prints the top-k head logprobs of every row of each completed verify window
through OriginalVerifier::window_logprobs_topk (same format as the Original's STRATA_LOGPOS/STRATA_LOGPOS_TOPK).
First measurements against the Original (5 prompts, 64 greedy tokens, same settings): identical on 1 prompt, divergences on the
others after 4..28 tokens; per-row top-8 logprobs differ by a median of about 0.4 (max 2.3). Not parity; investigation continues.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Findings fixed on the way (all from running the ignored original_serve_smoke against the pinned IQ3_S shards, sealed KAR memfd,
pinned MTP pack and resident expert source; CUDA 13.2.86, sm_120, driver 595.99):
- mtp_original_prefill.rs: the batched draft-KV recorder asked the ring for separately owned DeviceBuffers 0..5, but the serve ring
is built from prepared spans of the shared region (ring.buffer(i) -> ContextPoisoned). The overlap checks now compare addresses
via ring.address(i), which handles both layouts.
- session_original_draft.rs: a published speculative draft leaves the MTP ring AHEAD of the committed target (e.g. snapshot 116 vs
target 114); validate() and rebind_restored() demanded equality and refused the next round. They now require snapshot >= target.
- original_serve_stack.rs/engine: the MTP drafter is sized at the verify width (mtp_load_t = max_t = 6) like generate.cpp, while the
chain stays capped at 3 drafts (c7b5a08 from claude/serve-preflight).
- smoke: loads the resident expert source, long (114-token) first prompt so the batched draft-KV path (>= 64 rows) is taken, short
prompt (scalar draft-KV path) last and reported instead of asserted: it still fails with InvalidDimension (open item).
Bring-up instrumentation (to gate or remove before merge): DBG/PROBE eprintln lines, TracePort (logs every OriginalServePort call),
PoisonCell (backtrace of the first context poisoning with LELEKA_TRACE_POISON=1), micro_driver_error tracing.
Structural/behavioural bring-up evidence only: no parity, quality or performance claim yet.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
generate.cpp rewrites o.spec to min(spec+2, 8) (generate.cpp:1535-1537) before mtp.load(..., o.spec, ...) (:2610), so the
drafter accepts every window the verifier runs (suffix drafts reach the verify width) while its chain stays capped by
set_max_drafts(S_mtp - 1). The Rust stack loaded it at settings.mtp_max_t (4): the first T=6 window made
OriginalMtpDrafter::draft_inner refuse (rows > max_t, mtp_original_full_drafter.rs, 2 us, InvalidQwenShape -> InvalidDimension).
OriginalServeSettings::mtp_load_t() (= max_t) now sizes the executor's scalar prefill, the shared layout and the actor.
max_drafts() stays 3.
The synthetic probe now runs the serve round shape (T=1 window+commit+draft, then T=6 with accepted_row 0..5, commit, draft
anchored at the previous speculative snapshot, max_drafts 3, coupled false): PROBE_MTP_MAX_T=4 reproduces the failure, the
default 6 passes for every accepted_row. Structural only; no numerical claim.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
flock belongs to the open file description. A child that another test forks while the handle
is open keeps the description until it execs, so a lock can outlive drop() by milliseconds in a
parallel run. The journal and history tests now retry the reopen for up to 10 s; production keeps
refusing a held lock at once. 12 of 12 consecutive parallel runs of the desktop-core lib suite
pass (3 of 5 failed before). Also: documented runtime config example, validated by a test.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
text.format becomes optional so a text object may carry only a verbosity. concise/detailed
summaries, max_tool_calls and other include values stay refused. New HTTP tests run a Codex-shaped
two-turn exchange with stateless replay and the tool_choice / parallel_tool_calls enforcement
through the runtime stack.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
fake_runtime is a leleka.runtime.v1 server (the real RuntimeServer) whose engine is the same
engine.sh the smokes already use; fixture.runtime_stack() swaps strata-next's engine child for
it when STRATA_TEST_FAKE_RUNTIME is set, otherwise nothing changes. scripts/test-api-over-runtime.py
runs the ten smokes whose assertions do not depend on strata-next owning the engine process.
The HTTP layer clamps reasoning_tokens to the engine-reported output total, which a text-level
engine's re-tokenized pieces can otherwise exceed.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Six chain tests: streaming and JSON Responses, length/tool-call/stop-marker, client
disconnect cancelling through gRPC, engine failure and a dying engine ending with
response.failed, a restarted runtime flipping readiness and being reattached, and a test
that records the runtime's 256-generations-per-epoch limit.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
runtime.{address,token_env,tokenizer_dir,model,mode,max_context} are validated at load
(loopback only, credential from the environment and never printed, exclusive with
engine/native_model/mtp_pack/vision/gpu). serve spawns backend_worker over GrpcBackend.
The worker carries the runtime's output-token cap in WorkerStatus; a default budget never
exceeds it, an explicit request above it is refused. Request ids are UUIDs, as the
runtime contract requires.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
proto/runtime.proto, the wire conversions and the validated RuntimeClient move out of
strata-desktop-core so strata-next can use them; strata-desktop-core re-exports them
unchanged. GrpcBackend implements the Backend contract by attaching to a runtime an
operator already loaded (no Load/Unload RPC), re-reading epoch and handle before every
generation, and ending a generation without a terminal event on any transport or frame
error. 9 loopback HTTP/2 tests with a scripted runtime server.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>