- deploy/Dockerfile.windows-build cross-compiles the six executables (mingw, no Visual Studio needed)
- control-plane/build.rs: the ggml link stubs are used for every Windows target, not only MSVC
- scripts/windows/Start-Leleka.ps1 (igpu | cpu | npu modes, speculation and cache slots on by default) and Package-Windows.ps1
- docs/windows-runtime.md; stale statements in docs/cpu-runtime.md corrected
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>
--speculate on leleka-cpu-worker, leleka-igpu-worker and leleka-npu-worker drafts from
prompt lookup, verifies the sampled token plus the draft in one batch
(Model::logits_after_each, bit-identical to one-at-a-time feeding), samples every
emitted token from the real logits and truncates rejected positions from the cache,
so output equals plain decoding. The drafter estimates acceptance per matched-context
length and drafts only the length whose expected tokens per pass beat the pass cost
(measured ratios, then observed pass times). Drafts are clipped to the output budget.
speculate::replay runs a policy over a recorded output without a model.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- service: BATCH n lets it see each product's successor and expand the next weights on a thread
while the device runs the current one; buckets up to 4096; OpenVINO CACHE_DIR compile cache
- client: batched expert products, layout sized by batch, default batch 2048
- cpu-sys/cpu-kernels: AVX2 F16C f16_to_f32 kernel, exact for every half bit pattern
- npu-worker: memory admission before an NPU prefill (falls back to the CPU when RAM is short)
Co-Authored-By: Claude Sonnet 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>
Decision (owner, 2026-10-15): the NPU is used through a separate service process so that the CPU runtime never
loads OpenVINO (STRA-199 v2 D1, E8).
- leleka-shm: read-only file mapping and a read-write region two processes map (recorded unsafe exception)
- leleka-openvino: OpenVINO C API loaded at run time (recorded unsafe exception, NPU runtime only)
- leleka-npu-service: reads the GGUF itself, expands Q8_0/MXFP4 blocks to int8 + half group scales, runs
y = x . W^T on the device with the weights as run-time inputs, activations through the shared region
- tested against an f64 reference with real weights on CPU and NPU devices: relative rms error 2e-4 to 3e-4
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Loads openvino_c.dll dynamically and times MatMul graphs written as IR on the NPU, iGPU and CPU: f16 or
int8-compressed constant weights, int8 weights as runtime inputs, group-scaled int8 runtime weights.
Intel AI Boost: ~2 TOPS (f16 compute) for [M x 2880] x [2880 x 2880] at M >= 256, 1.3-2.5 TOPS with runtime
weights; native f4e2m1 weights are rejected by the NPU compiler. Not part of the workspace.
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>
No tile beat 4x4 for the experts; the hook (LELEKA_IGPU_MOE_TILE) stays for later experiments.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
MXFP4 products (the experts): 0.60 -> 0.72 TOPS at m=256, n=2880 in the same session; Q8_0 halved with two
blocks (0.69 -> 0.38, likely register pressure) so it keeps one. The teacher-forced dumps are identical to
the previous kernel (same integer sums, same order): 95.3% / KL 0.0121 vs llama.cpp, 96.6% / 0.0080 vs CPU.
1024-token GPU prefill, single unpaired run: 15.9 s -> 13.6 s (75 tok/s), experts 11.2 s -> 9.1 s.
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>
PrefillAccelerator::admit lets an accelerator refuse a prompt without being disabled. The GPU prefill
estimates its footprint (two layers of weights, scratch, hidden states, caches, 1 GiB headroom; 1.6 GiB
estimated vs 2.0 GiB peak private bytes measured for 1024 tokens before the headroom was raised) and
compares it with a probe; the worker's probe is the OS's available memory (sysinfo). admission_check
exercises both outcomes on the real model. 1024-token prefill with the vec4 attention: 15.9 s (64.5 tok/s),
single unpaired run.
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>
- cpu-worker: GptOssEngine can take a PrefillAccelerator (falls back to the CPU and drops it on failure)
- igpu-worker: separate executable, same protocol, --gpu-min-tokens/--gpu-batch; CPU-only with a message when
no GPU is usable
- real-model worker tests no longer assert llama.cpp's later greedy tokens (near-ties that moved with the
attention/KV/router changes of STRA-214; the first token and the reuse/determinism checks stay); the
teacher-forced gate is the comparison with llama.cpp
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A second thread builds the next layer's GPU weights while the first drives the GPU (rendezvous channel, at
most two layers resident). 1024-token synthetic prompt, single unpaired run: GPU prefill 23.3 s -> 20.9 s
(upload stall 5.3 s -> 0.4 s; the GPU phases slow down a little because the iGPU shares memory with the
repacking cores); CPU prefill of the same prompt 54.0 s.
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>
Every piece of a gpt-oss prefill layer now exists as a GPU kernel tested against the CPU decoder: the grouped
products take a tile table (expert, first compact row, row count) built from the router's choices, gather
activation rows, add per-expert bias, and write a compact output that the combine kernel folds into the
residual in slot order.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
RoPE uses the decoder's own rotation table; attention folds the softmax online over 32-key blocks for the
8 query heads of a KV head. Tested against the CPU decoder functions on full and sliding layers; one layer
over a 512-token batch ending at position 4096 takes about 0.52 s (0.02 s sliding) on the reference iGPU.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- Buf, Recorder: device-resident arrays and batched kernel launches in one submission
- gemm epilogue: optional bias and accumulate into the existing output (residual add)
- rmsnorm_quant kernel: RMSNorm plus Q8_0 quantization per row; matches the CPU decoder's
rms_norm to 1e-5 relative and the CPU quantizer exactly on the tested shapes
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
New pure-Rust crate on wgpu 26 with generated WGSL kernels: C[m][n] = sum over 32-element blocks of the
exact int8 block sum (packed dot-product built-in) times the activation and weight block scales. Weights
are repacked at upload (ggml's unaligned 34- and 17-byte blocks become int8 or nibble words plus separate
half-float or E8M0 scale words); MXFP4 values are decoded in the shader from a nibble-packed magnitude table.
Every accumulator and operand is a named scalar (dynamically indexed private arrays spill on this GPU).
Checked against the CPU kernels: random Q8_0 and MXFP4 weights on awkward shapes (single block, ragged
tiles, 1 to 130 rows) and, with LELEKA_GPTOSS_GGUF set, real tensors of gpt-oss-20b (blk.3.attn_q Q8_0
4096 x 2880; blk.5 gate expert 11 and blk.23 down expert 31, MXFP4 2880 x 2880): all outputs within the
float32 accumulation bound, worst error 0.01-0.02 of it.
Speed (gemm_bench, reference iGPU, one run each): a 4x4-outputs-per-thread tile is best, about 0.7 TOPS
int8 including the block scales (MXFP4 2880x2880: 0.58 TOPS at 32 tokens, 0.68 at 64, 0.72 at 256;
Q8_0 4096x2880 at 256 tokens: 0.79); 8x8 spills registers (0.45). The CPU decoder's equivalent is about
0.25 TOPS. Small products use only ~45 workgroups; batching experts will fill the chip.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The iGPU streams a 1 GiB buffer at about 40 GB/s (CPU: about 36 GB/s) and accepted 14 GiB of storage
buffers, so the whole model fits in device memory. The README records both results and the decision to build
a phased iGPU prefill backend with the CPU keeping decode.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
experiments/igpu-spike is a standalone program (own workspace, wgpu 26, WGSL generated as text) that
multiplies int8 matrices with the packed dot-product built-in on the reference laptop's Intel iGPU. The
instruction ceiling is 2.74 TOPS; a naive kernel reached 0.2-0.3 TOPS because private arrays were spilled,
and with named scalars the 8x8-per-thread kernel reaches 0.8-1.3 TOPS on prefill-like shapes (0.5-0.64 at
32 tokens), against about 0.25 TOPS for the CPU's decoder. Only the integer product is measured; the README
lists what is not shown (MXFP4 decoding, block scales, attention, weight upload, memory strategy) and the
decision needed from the owner.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The router's 32 single-precision dot products (2,880 elements each) and the expert activation (a scalar exp
per element) were the largest serial pieces left outside the matrix products. cpu-sys gains a vector
swiglu-oai kernel (portable and AVX2 + FMA, using the same vector exp as the softmax, relative error below
3e-6 in the tests, including gates far beyond the clamps), and the router reuses the strided dot kernel.
Measured on gpt-oss-20b, 10 threads, one run each on a noisy machine (not paired): router 3.0 -> 1.3 ms
and activation 3.0 -> 1.3 ms per decoded token; in prefill (chunk 64) router 2.5 -> 0.6 ms and activation
2.5 -> 1.6 ms per token. Decode 86 ms per token (11.6 tokens/s) over 19 tokens. Teacher-forced gate against
llama.cpp: best token 97.4%, mean KL 0.0088 (criterion <= 0.012; the previous build gave 0.0077, the
difference between the two builds is 0.0050, at the noise floor).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Keys and values are stored as IEEE half floats (49 KB per token instead of 98 KB, llama.cpp's default
cache type). New cpu-sys kernels read them directly: attention scores and weighted value sums over half
floats (portable and AVX2 + FMA + F16C, blocked over positions like the f32 ones) and a vector
float-to-half conversion that is bit-identical to the portable one. The decoder writes rotated keys and
values through Dispatch::f32_to_f16; the synthetic f64 reference rounds K and V the same way.
Teacher-forced gate against llama.cpp (same 383 tokens): best token 97.4% (unchanged), mean KL 0.0077
(was 0.0082 with f32 cache), next-token NLL 1.2852 vs 1.2798. The conversions cost a little attention time
(2,000-token context, one noisy run: decode attention 9.9 ms against 7.7 ms with f32), which is the price
of halving the cache. The worker's default context rises to 32,768 tokens (1.6 GB).
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>
Setting engine.gptoss_gguf (or STRATA_GPTOSS_GGUF) selects the gpt-oss family and takes the tokenizer from
that GGUF. Prompts: a Responses request (instructions, input items with reasoning, function calls and
outputs, tools, tool_choice, parallel_tool_calls, text.format, reasoning effort) is rendered as the Harmony
conversation by leleka-harmony; the same replay validation as the Qwen path, one call per assistant message
with its output, no custom tools. Output: a stateful HarmonyDecoder turns the generated tokens into the
reasoning / answer / <tool_call> markup that the existing code parses, so tool-name and argument
validation, history and the streaming events are reused; gpt-oss always reasons, the end-of-generation
markers <|return|> and <|call|> are the terminal tokens, and an open tool call is closed when the
generation ends.
Safety: the renderer can write its special markers as private-use sentinel characters (and replaces those
characters in caller text); the codec turns exactly those into special tokens. Marker-looking text from a
client, in messages, tool descriptions or tool output, stays ordinary text.
Side effect, deliberate: serde_json preserve_order is now on workspace-wide (the renderer needs the client's
property order), so tool-call argument objects keep the model's key order instead of alphabetical; one test
expectation changed accordingly. 52 responses tests and the new family tests pass; the 13 other
control-plane test failures on Windows predate this change.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The Responses code used the Qwen tokenizer directly. A TextCodec trait now carries what differs between
model families: encode, a stateful per-generation TokenDecoder, the terminal token ids and the family.
QwenCodec wraps the existing tokenizer with identical behaviour; the buffered and streaming paths decode
through a decoder created per generation, and reasoning_enabled takes the family so a family that always
reasons can say so. All 46 responses tests pass unchanged apart from the test helper.
Also fixes the Windows (MSVC) link of the control plane's test binary: ggml-quants.c references four
helpers from ggml.c that are not vendored; GNU linkers drop the unused code, MSVC does not. Abort-on-use
stubs are compiled for MSVC targets only. 13 other control-plane unit tests fail on Windows for
Linux-path reasons (absolute paths such as /private/api.key, disk-space and service-unit assumptions) and
are unrelated to this change.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Attention was scalar and latency bound. New kernels in cpu-sys (portable and AVX2 + FMA): scores for a
group of query heads against strided keys, weighted value sums for the group, and a vector exp for the
softmax (relative error below 3e-7). The 8 query heads that share a KV head are processed together over
blocks of 16 positions, so each key and value row is read into L1 once per group instead of once per head.
ops::attend_group_with_sink uses them through Dispatch; a group is bit-identical to its heads run one at a
time (test), and the kernels are checked against f64 references for odd widths, strides and block sizes.
Measured on gpt-oss-20b, 10 threads, 2,000 tokens of context (one run each, noisy machine): decode
attention 27.4 -> 14.5 -> 7.7 ms per token (per-head SIMD, then grouped), decode 116 -> 95 ms per token
(10.5 tokens/s, the same as at short context); prefill attention 8.9 -> 2.1 ms per token. Teacher-forced
quality gate against llama.cpp: best token 97.4% (was 97.1%), mean KL 0.0082 (was 0.0080).
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>
New crate leleka-cpu-worker (executable leleka-cpu-worker --serve --model <gguf>): loads the GGUF through
the read-only mapping, runs the gpt-oss decoder on the AVX2 / AVX-VNNI kernels, and speaks the stdin/stdout
protocol of Strata's --serve mode (READY, GEN with temperature, top_p and seed, STOP, QUIT, PP, REUSED, T,
DONE, ERR). Prefix reuse across requests, cancellation between prefill chunks and between tokens, a stale
STOP while idle is ignored, the end-of-generation marker is emitted as the last token.
leleka-gptoss gains sampling (greedy, or temperature and top-p over the 1,024 best logits, with a seeded
generator) and prefill_reuse_with (progress and cancellation). A stray NUL byte left in a doc comment by an
earlier shell edit is removed.
Tests: protocol parsing, the request loop against a mock decoder (stop token, length, reuse, STOP, QUIT,
engine failure, broken pipe), and an end-to-end run on the real model (needs LELEKA_GPTOSS_GGUF) that gets
llama.cpp's 16 greedy tokens for "The capital of France is" and reuses the prefix of a longer prompt.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
leleka-tokenizer gains gguf_bpe: a byte-level BPE tokenizer built from the vocabulary in the GGUF file
(gpt2 model, gpt-4o pre-tokenizer), with special-token parsing that is off by default so user text cannot
forge markers, and a UTF-8-safe streaming decoder. Checked against llama.cpp's /tokenize on 67 strings: same
ids except the two documented differences (llama.cpp forges some Harmony markers from text; it splits
words at combining marks, which the o200k expression keeps together).
New leleka-harmony crate: render() reproduces the gpt-oss chat template (including its whitespace) and is
byte-identical to llama.cpp's /apply-template on ten conversations with many tool-schema shapes;
HarmonyParser turns generated tokens into reasoning, answer and tool-call events.
The oracle fixtures are test strings, token ids and rendered prompts only. The tokenizer oracle test needs
LELEKA_GPTOSS_GGUF and reports "skipped" without it.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
State now records which tokens its KV cache holds. Model::prefill_reuse keeps the longest common prefix
with a new prompt (always recomputing the last token, whose logits are needed) and prefills only the
rest. A position that would leave a gap after the cached tokens is refused. Tests check that the result
equals a fresh prefill bit for bit for identical, extended, diverging and unrelated prompts.
The experimental AVX-VNNI tile kernels now use unsigned weights (w + 128, no sign instruction), start
each block's accumulation from -128 * sum(x) in lane 0, and read pre-broadcast activation scales
(PreparedAct / ActRef in cpu-sys). Tests bound the difference to the portable reference by
(blocks + 16) * 2^-23 * sum of |terms| computed with absolute weights and activations. In bench_tiles
this is not measurably faster than the sign-based tile (4x4 tile for 8 activations: 1.30x the one-row
kernel at 10 threads, against 1.35x before; run-to-run noise on this laptop is about 10%), so the tiles
stay unused by the decoder.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The decoder now runs decode and prefill through one chunked forward pass. Prefill feeds up to 64 tokens
at once: each weight row is read once per chunk and used against every token, MoE tokens are grouped
by expert, and attention runs as a pool region with one work item per (token, KV head). The result is
bit for bit what feeding the tokens one at a time gives (tests: every chunk size, 1 and 3 threads, and
resuming after an earlier prefix). The KV cache sits behind a read-write lock per layer so pool threads
can read it.
cpu-sys gains experimental tile kernels (1-4 MXFP4 or Q8_0 rows against 1-4 activations in the q8r
layout) at the portable, AVX2 and AVX-VNNI levels, with tests that every tile shape equals the 1x1 tile
bit for bit and stays within the float tolerance of the portable reference. They are not wired into the
decoder: in bench_tiles the 4x4 tile is 1.3-1.5x the one-row kernel for 8 activations, and slower for one
activation, where the one-row kernel already reads 31 of about 36 GB/s.
Measured on gpt-oss-20b, 10 threads, 256 synthetic tokens: prefill 51 ms per token (19.6 tokens/s) at
chunk 64, 13 tokens/s per token at chunk 1; decode unchanged (85-92 ms per token, same tokens and log-probs).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The MXFP4, Q8_0, int8 and int4 kernels, the Q8_0 quantizer and the half conversions are now Rust
(cpu-sys/src/simd.rs), written operation for operation after the C versions. The C code stays only behind
the test-only feature c-reference, and tests/rust_vs_c.rs checks bit-identical results at the portable,
AVX2 and AVX-VNNI levels. A runtime build compiles no C.
Paired decode on gpt-oss-20b (40 tokens, 10 threads, 5 alternating rounds): median 98 ms per token for
both builds, identical tokens and first-step log-probabilities.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The expert products (62 percent of a decoded token) now read the activation as f32
scales plus contiguous int8 quants, summed with four accumulators per iteration.
Adds the portable reference and the AVX-VNNI kernel for that layout; the AVX2 and
AVX-VNNI kernels are tested bit-identical to each other, and every level is within
the stated tolerance of the ggml-derived f64 reference. The decoder keeps both the
Q8_0 blocks (for the Q8_0 attention and output head) and the converted layout.
Measured on the real model with pre-touched pages, 10 threads, 40 tokens, alternating
old and new binaries (5 repeats; indicative, one burst-state outlier excluded): paired
old/new ratios 1.09, 1.14, 1.08, 1.06, i.e. about 8 percent less time per token (118 to
111 ms median), expert gate+up 41.6 to 37.6 ms. Greedy tokens are identical to
llama.cpp for the first 16 and to the previous build for the first 18; they diverge at
position 18 where the top-two logit gap is 0.009 (a numerical tie).
Also adds a per-step top-two logit margin print to the real-model runner.
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>
Prints metadata keys with summarised arrays and the tensor shapes of the
global tensors and block 0. Used to read the architecture and tokenizer facts
of gpt-oss-20b from the header of the file that LM Studio (Bionic) is
downloading.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Limits::check_data_range = false and the example's --partial flag read the header of a file that is still downloading. The report says nothing about the tensor data. Used to read the real tensor inventory of gpt-oss-20b-MXFP4 while it was downloading.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Completes the Q8_0 side of the CPU runtime's kernel set: a float-to-Q8_0
quantizer (scale = amax / 127 as a half, quants rounded to nearest even and
clamped to [-127, 127]) and the Q8_0 x Q8_0 dot, each at scalar, AVX2 and AVX-VNNI
(the quantizer shares the AVX2 code). Tests: the quantizer is bit-identical across
levels and equal to the vendored ggml reference except on exact .5 ties; per-block
integer sums are exact; float results are within the stated tolerance of an f64
reference built from ggml's dequantizer; the portable half conversion equals the
F16C instruction on over a million values. Windows MSVC and Linux GCC, debug and
release. Replaces _cvtss_sh (not available in MSVC) with the packed conversion.
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>
Adds two EXPERIMENTAL AVX2 MXFP4 kernels that take the activation as f32
scales plus contiguous int8 quants (q8r, q8r4). q8r is tested bit-identical to
the ggml-layout kernel; q8r4 against the stated tolerance. Adds Windows core
topology and thread pinning (cpu-sys topology module) and three kernel-level
benchmarks that interleave variants and report paired ratios.
Findings, recorded in docs/experiments/2026-10-14-cpu-kernel-layout-and-pinning.md:
the chip has 2 fast cores and 10 slower ones; the new layout was faster for a
single thread (paired median 1.32x, 15 pairs) and inconclusive with many
threads; thread pinning did not beat the OS default. The machine was not in a
controlled state, so these are not accepted performance results.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The gpt-oss-20b experts are MXFP4, so the CPU runtime needs this dot product.
Blocks use ggml's byte layout, so GGUF tensors can be read in place. Per-block
integer sums are exact at every level; the float combination is checked against
an f64 reference built from the vendored ggml dequantizers (test-only
ggml-oracle feature) within a tolerance written before the run. Scale
conversion is compared exactly with ggml for every E8M0 code and every finite
half. AVX2 level now means AVX2 + FMA + F16C. ABI version 2.
Adds a kernel-level throughput example (bench_mxfp4); it is not an inference
benchmark and no end-to-end speed claim is made. Records the ggml upstream use
in docs/upstream-ggml.md.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
leleka-cpu-sys holds the C kernels (one translation unit per ISA level, built
by build.rs with cc) behind a checked FFI; it is the only unsafe code of the CPU
runtime and opts out of the workspace unsafe_code lint with a recorded exception.
leleka-cpu-kernels does safe run-time dispatch with a LELEKA_CPU_ISA override
that fails rather than silently changing level.
Ports the int8xint8 and int4xint8 dot products from Colibri c/idot.h at scalar,
AVX2 and AVX-VNNI. Tests compare every level with the C scalar kernel and an
independent i64 oracle (13 tests; Windows MSVC and Linux GCC 14.2). Activations
must be in [-127, 127]: -128 is outside the contract and a test pins that. No
performance claim: nothing was timed.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Colibri (JustVugg/colibri, Apache-2.0) is an upstream source for the CPU
runtime, not a dependency. Record the pinned commit, archive and licence
digests, the porting rules, and a per-file ledger with adopt/adapt/reject
decisions. docs/upstream.md (Strata pin) is unchanged.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>