Brings the Rust/CUDA port of the Strata mode17 serve path together with the
CPU/iGPU/NPU gpt-oss runtime that main gained meanwhile.
Control plane: the Qwen tokenizer is the implementation behind the Qwen35
variant of codec::TextCodec (qwen(), encode_prompt() widen the trait; QwenCodec
derefs to the tokenizer), so control-token marks, images, chat template, the
runtime backend and vision keep their behavior, while the gpt-oss/Harmony path
and the worker pool keep main's. Config carries the union of fields; extra_workers
is rejected together with runtime, lazy_load, idle_unload_s and vision; the
gpt-oss family refuses top_k/min_p/penalties (its GEN line has no such keys).
leleka-kar-codec takes f16_bits_to_f32 from leleka-quant-core (identical code).
Workspace members and default-members are the union of both sides.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The gpt-oss template writes "Current date: <UTC today>" into the system message, which is part of
the prefix a worker's KV cache is matched on, so every cache missed once a day at midnight UTC.
prompt_date in the config (STRATA_PROMPT_DATE) now selects: utc (default, unchanged), a fixed
YYYY-MM-DD, or none, which leaves the line out (RenderOptions::omit_date; the blank line after it
stays) for clients that give the date as a function tool. The control plane does not host tools;
the client supplies the tool.
Teacher-forced on four 770-957 token prompts the model is not indifferent: dropping the line
moves the next-token distribution by mean KL 0.034-0.056 (best token same at 89-90%), changing
only the date value by 0.023-0.040 (92-93%), numerical noise 0.005-0.023 (93-97%). Task quality
was not measured, so none is opt-in. Checked end to end through the control plane: 68 input
tokens for "Hi" with the date, 57 without, 68 with a fixed date; a bad value is refused at start.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
GptOssEngine holds up to N conversation caches (--cache-slots N on the four workers, default 1 =
unchanged). crates/cpu-worker/src/slots.rs chooses per prompt: continue in place a slot that is
wholly a prefix of the prompt (the same agent's next turn); otherwise take the slot sharing the
longest prefix as a donor and either continue it (losing its tail) or copy the shared part into
a new/empty/least recently used slot (State::copy_prefix_from), whichever discards fewer cached
tokens, so a new agent gets the shared system prompt without destroying another agent's cache.
Results are bit-identical to a fresh prefill (synthetic test: copied prefix continues bit for
bit, donor untouched).
Measured: CPU only, 3 agents, 36 requests: 1.37x/1.46x prompt time, outputs identical.
Through the control plane, 4 agents on one iGPU worker, 3 clean alternating pairs: 986/993/995 s
with 1 slot against 569/575/575 s with 4 slots (1.73x), answers identical in all six runs. The
first run of pair 1 was disturbed by the UTC date in the system prompt changing mid-run and was
repeated. Compare-ConcurrentEpisodes.ps1 takes -Agents, -SharedInstructionTokens and the
'slots' arm and records output hashes.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
engine.extra_workers starts further supervised workers behind the one request channel
(control-plane/src/pool.rs). A dispatcher hands each request to an idle, ready worker,
preferring the one whose last prompt shares the longest prefix with it, so each conversation
keeps its cached prefix. It learns completion by relaying the result channel, so the worker
and its tests are unchanged. /ready and /status need every member ready. 4 dispatcher tests;
the 13 failing control-plane tests fail identically at 3ebcb3f (Windows).
Paired A/B, two scripted 4-turn episodes sent at once (Compare-ConcurrentEpisodes.ps1, 3
alternating pairs each), time until both are done:
- one iGPU worker, interleaved: 686-713 s; pool: 254-306 s, 2.33-2.73x. Mostly the second
KV cache: the single worker re-prefilled every turn.
- one iGPU worker running the episodes in sequence: 317-342 s; pool: 292-303 s,
1.05-1.14x. This is the second device's own share. Per-turn latency in the pool is higher.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
leleka-gpu-npu-worker (crates/gpu-npu-worker) splits a long prompt: the NPU path takes the
first share of the tokens and the GPU path the rest, on two threads. They meet only in the
KV cache, through the new leleka_gptoss::LayerCache, which both prefill paths now use instead
of &mut State (same behaviour). The GPU part's cache waits for each layer the NPU part
stores, so the GPU runs layer l while the NPU runs l+1. The last-token distribution matches
the GPU alone (KL <= 1e-4).
Measured: 2048 tokens 0.89-1.13x against the GPU alone, depending on share; agent episode
(4 turns of ~2,060 new tokens, 6 alternating pairs) 0.81-1.16x per pair, a net loss. Both
paths stream all weights whatever their token share and share the 15 W budget, and the NPU
part's CPU attention over the growing context is the slow side. Not adopted; stays
experimental. Also: NpuPrefill::with_cpu_threads, and -ArmA/-ArmB/-LogDir in
Compare-PrefillWorkers.ps1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The KAR codec moves unchanged from control-plane/src/kar_codec.rs into crates/kar-codec
(re-exported there, so the control plane's KAR tests are unchanged and pass). Probes, off
unless set: LELEKA_EXPERIMENTAL_KAR_LEVELS / _KAR_TENSORS for attention and output weights,
and LELEKA_EXPERIMENTAL_KAR_EXPERT_LEVELS / _KAR_EXPERT_LAYERS for the MXFP4 experts
(level 0 is a storage-only control). Teacher-forced against llama.cpp, baseline KL 0.016:
attention+output at 6.5/5.5/4.5 bits give KL 0.063/0.095/0.213 (uniform rounding was
0.071/0.112/0.270), and every tensor group fails alone; experts of 6 of 24 layers at 3.5
bits give KL 0.081 (control 0.018). No KAR rate passes the gate on this model. Corrects the
earlier doc claim that a KAR layout is the same as uniform rounding.
iGPU and NPU prefill run at the same time give 93-98 tok/s in total against 73-77 for the
faster device alone (2048 tokens each, two rounds).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LELEKA_SPECULATION_LOG=1 now also prints, per request and with or without --speculate, where the decode time went:
passes by number of tokens (count and mean), sampling, output lines, drafting, cache cuts and the rest.
Measured with it (ab_speculation, 2 pairs, quiet machine, outputs identical in all 16 runs; paired speed-ups 1.55,
1.12, 1.01, 0.97): everything outside the model passes is under 0.5% of decode time (sampling 40-64 ms per request,
the rest a few ms), and single steps cost the same in both arms (81-93 ms). Verifying passes in the worker cost
1.57, 2.04, 2.50, 2.99, 3.66, 4.04, 4.32, 4.80 single steps for 2-9 tokens, 3% above batch_cost's random-id passes at
2-3 tokens and 8-22% above from 4 tokens on, which accounts for the rewrite's 1.55 against the replay's 1.59.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The ab_speculation run recorded in 87637c2 overlapped another session's GPU prefill probe (not in the busy check),
so it is now marked disturbed and kept only for the record. Rerun on a quiet machine with the other session holding
all heavy work (processes checked before, between and after; machine state before and after in the results file):
- batch_cost ab, 9 rounds: identical logits in all 90 paired passes; time ratio with/without 1.02, 1.05, 0.94, 0.87,
0.83, 0.81, 0.80, 0.76, 0.76 for 1-9 tokens, confirming the first paired run.
- ab_speculation, 3 pairs, outputs identical in all 24 runs: rewrite 1.54 (1.49, 1.61, 1.52; 1.25 before the change),
diff 1.06, json 0.97, explain 0.97. The drafter replay predicted 1.59 / 1.15 / 1.00 / 0.99, so there is no hidden
serving-loop cost; the rewrite drafts longer runs (39-41 verified batches instead of 43-56).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Profiling the speculative verification pass (batch_cost, position 900) showed its extra cost is compute in the
int8 weight products, not expert bytes: distinct experts per layer rise only from 4 to 9.5 at 9 tokens, while the
Q8_0 projections, whose weights every token shares, cost 3.6-4x a single step. Each (row, token) dot redid the
MXFP4 decode and scale work.
cpu-sys gains multi-activation kernels (portable, AVX2, AVX-VNNI) for MXFP4 and Q8_0 rows: the row is decoded once
per 64-block segment and up to 16 activations run over it with exactly the one-token kernel's accumulators and
final reduction, so every output is bit for bit the one-token kernel's (tests/multi.rs: every level, 1-16
activations, 13 row lengths). run_region uses them for jobs with two or more activations (speculative batches and
prefill chunks); one-token decode keeps its kernel. A new synthetic test checks a 20-token batch at every level
against feeding tokens one at a time. Model::set_multi_activation(false) restores the per-token path for paired
measurements; Profile counts the expert sets read.
batch_cost gains a per-size phase breakdown and an `ab` mode that runs every pass without and with the new kernels
back to back and checks the logits are identical. Paired, 9 rounds, real model: identical logits in all 90 paired
passes; time ratio with/without 1.01 (1 token), 0.98, 0.92, 0.90, 0.83, 0.81, 0.77, 0.79, 0.76 (2..9 tokens).
MEASURED_COST becomes 0.737 + 0.421 n (was 0.30 + 0.631 n). ab_speculation (3 pairs, outputs identical in all 24
runs) gave 1.34 / 1.04 / 0.97 / 0.94, within the pair-to-pair spread of the run before the change; replaying the
outputs through the drafter predicts 1.59 / 1.15 / 1.00 / 0.99, so the serving loop loses time the pass-cost model
does not see. Prefill also uses the kernels (bit-identical); its speed was not measured.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ab_speculation: four agent-style prompts, 3 alternating pairs, greedy, identical
outputs in all 96 runs; copy-heavy output 1.10-1.36x decode, new text within noise
of 1.0. batch_cost: a CPU pass over n >= 4 tokens costs about 0.65 n single steps, so
CPU speculation is capped near 1.5x. One 9-token pass takes 7.3 s on the iGPU and
6.3 s through the NPU service against 0.75-0.93 s on the CPU, so neither is used for
verification.
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>
- gptoss-npu: a prefill accelerator that sends the matrix products to the NPU service and keeps norms, RoPE,
attention, router, activation and combine on the CPU; debugging shadow device; examples for comparison, the
quality dump, a numerics probe and a paired A/B
- npu-worker: separate executable with the CPU worker's protocol, CPU-only fallback, --openvino-root/--npu-*
- the NPU flushes half-precision subnormals to zero, which erased every Q8_0 block with scale < 2^-14
(error 11% on attn_output); the service now boosts such rows' scales by a power of two and reports the
per-column shifts the client divides out (relative rms error back to 3e-4 on all shapes)
- Smoke-GptOssStack.ps1 takes -Worker leleka-npu-worker -OpenVinoRoot; passes through the control plane
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Four turns of ~1380 new tool-output tokens each on a growing cached prefix, three alternating pairs:
episode wall time 333.0 s (CPU worker) vs 125.0 s (GPU worker), paired 2.60x / 2.70x / 2.70x. Scripted
episode, not real agent traffic; the answers were not compared.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Warm, alternating order, same prompts, same process: paired speed-up 2.87x (512 tokens), 3.40x (1024),
3.97x (2048), 3.57x (4096) with 95% CIs in docs/igpu-prefill.md; GPU 50-64 tok/s against 15-17 tok/s on the
CPU. Synthetic prompts, 3-5 pairs, clocks/power not controlled.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Smoke-GptOssStack.ps1 takes -Worker leleka-igpu-worker -GpuMinTokens N. With every prompt forced through the
GPU (N=1): plain answer, function call, tool-result round trip with prefix reuse (134 of 181 tokens cached)
and streaming all pass through the control plane. dot4_peak measures 4.49 TOPS of dot4I8Packed with no memory
traffic on this iGPU, against 0.67-0.86 TOPS for the GEMM kernels (tile sweep in docs/igpu-prefill.md).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
One full layer over a 512-token batch ending at position 4096: 0.52 s -> 0.22 s (8192: 1.07 s -> 0.44 s).
4096-token synthetic prompt, single unpaired run: 91.9 s -> 67.5 s (60.7 tok/s; CPU 247 s earlier). Same
tests against the CPU attention. Teacher-forced vs llama.cpp on the gate text: 95.3% / KL 0.0121 (the
earlier kernel gave 97.1% / 0.0100): the two GPU runs differ from each other by KL 0.0058, as much as GPU vs
CPU (0.0067-0.0080) and the CPU's own scalar vs SIMD (0.0048); a second text shows GPU-vs-CPU noise equal
to CPU-scalar-vs-SIMD noise (docs/igpu-prefill.md). Reported as borderline against the strict KL limit.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- gptoss: PrefillAccelerator hook, Model::prefill_reuse_accelerated, layer/weight views, embed,
next_from_hidden (shared with the CPU forward pass), State KV export/import
- igpu: threaded weight repacking (131 s -> 6 s of upload for 24 layers), explicit half rounding of block
scales (the compiler folds the pack/unpack round trip away), matmul_rows, buffer reads/writes at offsets
- teacher-forced gate with GPU prefill: best token 97.1% vs llama.cpp, mean KL 0.0100, NLL +0.0148;
vs the CPU decoder KL 0.0067 (see docs/igpu-prefill.md). Experimental, not wired into the worker.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
benchmarks/tools/Smoke-GptOssStack.ps1 starts strata-next with leleka-cpu-worker for a GGUF and checks a
plain question, a function call, a tool-result round trip that must reuse the cached prefix, and a
streaming request, then stops what it started. Run on the reference laptop with gpt-oss-20b: all pass
(second-turn prefix reuse 134 of 181 prompt tokens; 5.3 s for a short answer, 6-8 s for tool turns).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
dump_logprobs writes the top-20 next-token log-probabilities after every position of a fixed token
sequence; compare_logprobs compares two such dumps (best-token agreement, log-probability differences, KL
on the shared top tokens, next-token NLL, statistics by position). The committed reference holds
llama.cpp's numbers for a 383-token Harmony exchange.
Result: Leleka (AVX-VNNI) vs llama.cpp agrees on the best token at 97.1% of positions, mean KL 0.0080,
next-token NLL 1.2859 vs 1.2798. Leleka's own scalar and SIMD kernel levels, which differ only in float
summation order, differ from each other by mean KL 0.0048 with the same early-position pattern, so the
earlier first-step discrepancy is numerical noise amplified by the 8-bit activation quantization, not a
systematic error. The README records the procedure and the pass criteria for later changes.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The first decoder spawned OS threads for each of about 385 matrix-vector products
per token, which made it slower with more threads (257 ms per token at 5 threads,
538 ms at 12). It now keeps a pool of parked workers; the products of a layer
are grouped into four regions (QKV, output projection, expert gate+up, expert
down) and participants claim row chunks from a shared counter, which suits the
mixed fast and slow cores. Weights are referenced through shared handles into the
mapped file so jobs are 'static. Adds a per-phase profile, a page pre-touch for the
mapping, and a real-model runner option for it.
Measured on the reference laptop (quiet machine, single runs, short context, NOT
paired; indicative only): 120 to 160 ms per token at 5 to 10 threads cold, 115 ms
(8.7 tokens/s) at 10 threads with pre-touched pages. Same 16 greedy tokens as
llama.cpp. The synthetic end-to-end tests still match the independent f64
reference and give identical logits at every thread count.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
leleka-gptoss reads the model hyper-parameters from the GGUF header and views
the weights in place in the memory-mapped file; only norms, biases, router and
sinks are copied. One-token forward pass: RMSNorm (f64 sum), attention with
grouped KV heads, learned sinks and alternating sliding/full layers, YaRN RoPE
in NeoX pairing, router with softmax over the selected logits, MXFP4 experts with
the clamped gated activation, Q8_0 attention and output head. Row-parallel
matrix-vector products; f32 KV cache. Greedy generation.
Tests: unit tests of each operation against f64 formulas, and an end-to-end test
on a tiny synthetic gpt-oss (ggml-quantized random weights) against an
independent f64 implementation: worst relative logit difference about 1e-7 over
three seeds, identical logits at every instruction-set level and thread count.
Whether the maths equals the real model's is NOT yet tested: that needs the
llama.cpp oracle (STRA-212 acceptance criteria).
leleka-cpu-sys gains a safe read-only file mapping (Windows and Linux). The
benchmark script now reproduces Bionic's server flags, supports concurrent
requests and reports aggregate speed. No speed claim is made.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
leleka-gguf reads the header of a GGUF file with bounded allocation (limits plus
the file size), validates tensor shapes against block geometry from the pinned
ggml, offsets against alignment, overlap and the end of the file, and builds an
inventory of which bytes one decoded token reads in a mixture-of-experts model
(experts scaled by used/total, one embedding row, full attention, router, norms
and output head). No dependencies, no unsafe. 13 tests on synthetic files, including
hostile headers and truncation at every length.
benchmarks/tools adds Capture-MachineState.ps1 (drift fields of the reference
laptop record, quiet-machine gate) and Measure-LlamaServer.ps1 (rotating-round
measurement of llama.cpp-style servers with the machine state before and after).
Tested only against a fake local server; no real model has been measured yet.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>