- 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>
20 KiB
Leleka CPU runtime (AVX2 / AVX-VNNI)
Status on 2026-10-14: runs gpt-oss-20b (MXFP4 GGUF, the lmstudio-community file with SHA-256
65d06d31a3977d553cb3af137b5c26b5f1e9297a6aaa29ae7caa98788cde53ab) end to end through the control plane's
worker protocol. Not wired into the control plane's request path yet (see "Not done").
Crates (a separate runtime; shares only crates/backend-api with others)
| Crate | Role |
|---|---|
leleka-cpu-sys |
The only unsafe code of this runtime: SIMD kernels (std::arch, AVX2 and AVX-VNNI plus a portable level), read-only file mapping, core topology. Every public function is safe and checks lengths and CPU support. Optional test features: c-reference (the first, C implementation, compared bit for bit) and ggml-oracle (llama.cpp's quantizers). |
leleka-cpu-kernels |
Runtime dispatch by CPUID (LELEKA_CPU_ISA overrides and fails rather than silently switching). |
leleka-gguf |
Bounded GGUF reader and per-token byte inventory. |
leleka-gptoss |
The decoder: persistent thread pool, chunked prefill, prefix reuse, f32 KV cache, sampling. |
leleka-tokenizer |
gguf_bpe: gpt-oss tokenizer from the GGUF vocabulary. |
leleka-harmony |
Prompt rendering and output parsing of the Harmony chat format. |
leleka-cpu-worker |
The executable: leleka-cpu-worker --serve --model <gguf> [--threads N] [--ctx N] [--no-warm] [--seed N]. |
Worker protocol
Same lines as Strata's --serve mode (control-plane/src/wire.rs). The worker prints READY <ctx> stop
after loading (and, unless --no-warm, reading every page of the model once), then per request:
PP <done> <total> after every prefill chunk, REUSED <n>, T <id> per generated token, and one
DONE <generated> <prompt_tokens> <prompt_ms> <decode_ms> stop|length|cancel 0 0 <reused> 0 0 (or ERR).
Input: GEN <max_new> [temperature=] [top_p=] [seed=] <ids>, STOP, QUIT. The end-of-generation marker
(<|return|>, <|call|> or <|endoftext|>) is emitted as the last T so the caller can tell an answer
from a tool call. A STOP while no request runs is ignored. Tokenization and Harmony rendering/parsing
belong to the caller (the crates above are the pieces for it).
What was measured (Core Ultra 7 265U, 15 W, 32 GB class laptop; one noisy machine, no quiet gate for
every number; see the work results on STRA-214 and STRA-217 for the paired runs)
- Decode, 10 threads, warm pages: 85-100 ms per token (10-11.7 tokens/s). Bionic's llama.cpp measured 7.6-8.7 tokens/s on the same prompt on this machine (STRA-209, partial baseline).
- Decode at 2,000 tokens of context: 95 ms per token (10.5 tokens/s); attention costs 7.7 ms of it (27.4 ms with scalar attention loops). Attention reads each KV head's keys and values once for its 8 query heads (blocked in L1) with AVX2/FMA kernels and a vector exp.
- Prefill, 10 threads, chunk 64: about 51 ms per token (19.6 tokens/s) on 256 random-id tokens. Bionic's iGPU engine measured about 90 tokens/s; its CPU engine about 14.8 tokens/s. Prefix reuse makes the second and later requests of a conversation cheap.
- Correctness: first 16 greedy tokens equal llama.cpp's for "The capital of France is"; chunked prefill and prefix reuse are bit-identical to feeding tokens one at a time; kernels at every instruction-set level are tested against exact integer references and against llama.cpp's quantizers.
Serving through the control plane
The control plane (strata-next serve) serves /v1/responses for gpt-oss with this worker. Configuration
(JSON file, or STRATA_GPTOSS_GGUF):
{
"bind": "127.0.0.1:8081",
"model": "gpt-oss-20b",
"engine": {
"executable": "target\\release\\leleka-cpu-worker.exe",
"args": ["--model", "<gpt-oss-20b-MXFP4.gguf>", "--ctx", "8192", "--threads", "10"],
"gptoss_gguf": "<gpt-oss-20b-MXFP4.gguf>",
"startup_timeout_s": 300
}
}
gptoss_gguf selects the gpt-oss family and takes the tokenizer from that file. The control plane renders
the Harmony prompt from the Responses request (instructions, input items, tools, tool_choice, reasoning
effort), sends the token ids to the worker, and turns the generated Harmony stream into reasoning,
message and function_call items (buffered and streaming). The special markers of the template are written
as private-use sentinel characters and only those become special tokens, so text from a client cannot
forge a marker. Run benchmarks/tools/Smoke-GptOssStack.ps1 -Model <gguf> to check the whole stack:
plain question, function call, tool-result round trip with prefix reuse (about 130 of 180 prompt tokens
were cached on the second turn), and a streaming request. Not supported for this family: custom tools.
Tool-call arguments arrive in one piece when the call ends (the stream decoder buffers them).
Known limits / not done
- The first-step log-probabilities differ slightly from llama.cpp's (0.4 vs 0.45 for the top token); the teacher-forced logit comparison that would explain it is still to be done. Greedy tokens agreed on the prompts tried, but near-ties can flip.
- The KV cache holds half-precision keys and values (about 49 KB per token, as llama.cpp's default): the worker's default context is 32,768 tokens (1.6 GB). A 131,072-token context would take 6.4 GB; RAM planning for it with the 12 GB model (STRA-204/205/210) and cold-expert streaming (KAR) are not done.
- One decode at a time per worker (several conversations can share it through
--cache-slots); sampling is temperature and top-p over the 1,024 best logits. - iGPU and NPU prefill helpers exist as opt-in workers (
docs/igpu-prefill.md,docs/npu-service.md); the packaged Windows runtime is described indocs/windows-runtime.md.
Decode speed limit on the reference laptop (2026-10-15)
The reference laptop has one 32 GB DDR5-5600 module (single channel, 44.8 GB/s peak). One decoded token of gpt-oss-20b
reads about 2.56 GB (experts 1.27, attention Q8_0 0.68, output layer 0.62), so decode is capped near 14-15 tokens/s at
the measured 36-40 GB/s, for this runtime and for llama.cpp alike. The CPU and the integrated GPU share that channel:
streaming from both at once gave about 37 GB/s in total (GPU 28 GB/s alone, about 21 GB/s while the CPU decoded), so
splitting decode across them does not add bandwidth. Verifying several tokens in one CPU pass is compute-bound (about
0.42 single steps per token since the multi-activation kernels, 0.65 before), which caps CPU-side speculative decoding
near 2x; see the --speculate section below.
Prompt-lookup drafting accepted only 1.03-1.2 tokens per step on the four set2 texts. A second memory module (dual
channel) is the lossless way past the cap.
Experimental lossy mode: fewer experts per token
LELEKA_EXPERIMENTAL_EXPERTS_USED=N routes each token to N experts instead of 4 (off unless set; logs a warning; no quality
gate allows it). Decode and teacher-forced quality against llama.cpp on table-igpu / docs-cpu (set2), one noisy run:
| experts | decode tok/s | best-token agreement | mean KL |
|---|---|---|---|
| 4 (model) | 8.7 | 93.4% / 92.7% | 0.016 / 0.023 |
| 3 | 10.2 | 70.4% / 72.8% | 0.161 / 0.185 |
| 2 | 12.8 | 51.0% / 52.4% | 0.460 / 0.477 |
Removing expert bytes costs far more quality than it buys speed; not recommended.
Experimental quality probe: attention and output weights at fewer bits
LELEKA_EXPERIMENTAL_FAKE_BITS=N re-rounds the attention and output Q8_0 weights to an N-bit symmetric grid per block of
32 (absmax scale in half precision), stored in Q8_0 so there is no speed change; it only measures what an N-bit format
would cost. Teacher-forced against llama.cpp on table-igpu (set2; baseline 8-bit: mean KL 0.016, 93.4% agreement):
| bits per weight (scale not counted) | best-token agreement | mean KL |
|---|---|---|
| 7 | 84.9% | 0.053 |
| 6 | 81.4% | 0.071 |
| 5 | 76.4% | 0.112 |
| 4 | 63.5% | 0.270 |
Plain block rounding of the attention and output layers is not usable below 8 bits on this model. (An earlier version of this note called a KAR layout "the same rounding"; it is not: KAR fits a non-uniform codebook per tensor. The real codec was measured afterwards, see the next section.) The first run of this probe had a half-precision conversion bug (small scales flushed to zero); the numbers above are from the fixed code.
Experimental quality probe: the real KAR codec on attention, output and expert weights (2026-10-16)
The KAR codec of the control plane (koference KAR-2: f16 absmax scale per group of 32, then an N-level nested codebook
fitted to each tensor by optimal top-down splits) moved unchanged into crates/kar-codec, which both the control plane
and the CPU runtime use. LELEKA_EXPERIMENTAL_KAR_LEVELS=N encodes and decodes the attention and output Q8_0 weights
with it (codebook fitted to 65,536 values sampled evenly per tensor) and stores the reconstruction in Q8_0
(LELEKA_EXPERIMENTAL_KAR_TENSORS selects tensors by name); LELEKA_EXPERIMENTAL_KAR_EXPERT_LEVELS=N with
LELEKA_EXPERIMENTAL_KAR_EXPERT_LAYERS=a-b does the same for the MXFP4 experts of those layers and stores them in Q8_0.
Both are probes only: no speed-up, no serving use. Teacher-forced against llama.cpp on table-igpu (set2, 770
positions; baseline 8-bit: 93.4% best-token agreement, mean KL 0.016):
| KAR levels (bits per weight with scale) | attention + output: agreement / mean KL | uniform rounding at the same bits |
|---|---|---|
| 6 (6.5) | 83.9% / 0.063 | 81.4% / 0.071 |
| 5 (5.5) | 79.4% / 0.095 | 76.4% / 0.112 |
| 4 (4.5) | 68.1% / 0.213 | 63.5% / 0.270 |
| 3 (3.5) | 39.9% / 0.557 |
At 4 levels, one group at a time: output layer alone 79.9% / 0.062, attn_q+attn_k 75.6% / 0.120, attn_v+attn_output
72.6% / 0.172. KAR's codebook is worth about half a bit over uniform rounding, but every group is sensitive on its own,
so no mixed-precision split brings attention or the output layer below 8 bits within the gate. (A rebuild in a clean
worktree reproduced the 4-level all-tensor run exactly.)
Experts (already MXFP4, 4.25 bits), layers 0-5 only (a quarter of the model; all 24 in Q8_0 would need about 21 GB):
| expert format in layers 0-5 | agreement / mean KL |
|---|---|
| Q8_0 copy of the MXFP4 values (control) | 92.5% / 0.018 |
| KAR 3 levels (3.5 bits) | 85.8% / 0.081 |
| KAR 2 levels (2.5 bits) | 72.9% / 0.166 |
Four levels cannot be fitted (MXFP4 blocks hold too few distinct values for 16 cells), and they would not save bytes. Even a quarter of the experts at 3.5 bits costs five times the baseline KL, so KAR below MXFP4 is not usable either. With these results no KAR rate saves bytes on gpt-oss-20b within the quality gate; decode stays at 2.56 GB per token.
iGPU and NPU prefill at the same time (2026-10-16)
The two accelerators are separate compute units, and prefill is compute-bound, so running them together adds
throughput where decode cannot (benchmarks/results/igpu-npu-concurrent-prefill-2026-10-16.txt; gpu_prefill and
npu_prefill examples in separate processes, 2048 synthetic tokens each, two rounds, otherwise idle machine):
| iGPU tok/s | NPU tok/s | |
|---|---|---|
| alone | 72.7, 76.5 | 69.8, 74.6 |
| both at once | 59.4, 59.0 | 49.3, 46.7 |
Together they prefilled 4096 tokens in 41.6 and 43.9 s (98 and 93 tok/s), 1.25-1.3x the faster device alone; each slows by a fifth to a third (shared memory and the 15 W power budget). Two requests prefilling at once (one per device) could use this directly; one prompt would need its batches or its expert products split between the devices, which is not built. The figures are an upper bound for such a split: no synchronization between the devices was needed here.
Prompt-lookup speculation: measured acceptance on agent-style output (2026-10-15)
The model (greedy, run_real) generated 320 tokens for four agent-style prompts over about 800 tokens of context (a Rust
file, or the first 2,200 characters of this document); the draft is the continuation of the latest earlier match of the
last N tokens in prompt plus output, up to K tokens, and a step accepts the longest prefix equal to what the model produced.
| task | tokens per step (N=2..4, K=4 / K=8) |
|---|---|
| rewrite the code with renamed functions (copies the input) | 3.3-3.7 / 5.4-5.8 |
| list function names as JSON and repeat the first function | 1.7-2.0 / 1.8-2.1 |
| reproduce a section of the notes as bullets | 1.4-1.6 / 1.4-1.7 |
| explain what the code does (new text) | 1.05-1.2 / 1.05-1.2 |
Four prompts, one run each: an indication of the spread, not a workload estimate. Verification cost decides whether this pays: on the CPU a chunk of 4-8 tokens costs 65-78 ms per token on the noisy machine (about 50 ms quiet), against about 110 ms for a decode step, so with 3.5-5.7 tokens per step the CPU gain is at most about 1.3x; the integrated GPU (compute about 3-4x the CPU, but expert reads grow with the number of distinct experts in the batch) could reach about 20 tokens/s on copy-heavy output by the estimate in STRA-220, and about nothing on free-form text.
Exact speculative decoding in the worker (--speculate, experimental, off by default; 2026-10-16)
leleka-cpu-worker, leleka-igpu-worker and leleka-npu-worker accept --speculate. Decoding then drafts from
prompt lookup (leleka_gptoss::speculate), feeds the sampled token plus the draft as one batch
(Model::logits_after_each, bit-identical to feeding the tokens one at a time; tests/synthetic_model.rs), samples
every emitted token from the real logits in order, and cuts rejected positions out of the cache. The output is
therefore exactly that of plain decoding for any sampling settings (tests/serve_loop.rs; greedy outputs identical in
all 96 real-model runs below). Drafts never run past the output budget, so a batch stays inside the context margin.
LELEKA_SPECULATION_LOG=1 prints drafted and accepted counts per request and where the decode time went (passes by size,
sampling, output, drafting, cache cuts), with or without --speculate.
On the CPU a verifying batch is compute-bound, so it is not free (examples/batch_cost.rs, position 900, medians).
The batch pass first ran the one-token kernel once per (weight row, token), redoing the MXFP4 decode and scale work for
every token: profiled, the extra cost was compute, 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). The
multi-activation kernels (leleka-cpu-sys, portable, AVX2 and AVX-VNNI) decode a weight row once per 64-block segment
and run up to 16 activations over it with exactly the one-token kernel's accumulators, so every value is bit for bit
the one-token kernel's (tests/multi.rs; on the real model all 90 paired passes below gave identical logits). Pass
times with them divided by without them, paired back to back in one process (batch_cost ... 14 ab, 9 rounds, median
ratio; the machine was busier than for the first row, single step 108 ms):
| tokens in the pass | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|
| ms before (quiet run, 93 ms single step) | 93 | 145 | 201 | 264 | 313 | 373 | 443 | 485 | 556 |
| cost in single steps before | 1.00 | 1.56 | 2.16 | 2.84 | 3.37 | 4.01 | 4.76 | 5.22 | 5.98 |
| paired time ratio, after / before | 1.01 | 0.98 | 0.92 | 0.90 | 0.83 | 0.81 | 0.77 | 0.79 | 0.76 |
| cost in single steps after (line used by the drafter) | 1.00 | 1.58 | 2.00 | 2.42 | 2.84 | 3.27 | 3.69 | 4.11 | 4.53 |
The gain grows with the batch because a token shares a weight row with more others: the Q8_0 projections see every
token, an expert only the tokens routed to it (about 2 at 4 tokens, 4 at 9). Plain decode (one token) is unchanged. A
rerun on a quiet machine (single step 87-92 ms, identical logits in all 90 passes) gave ratios 1.02, 1.05, 0.94, 0.87,
0.83, 0.81, 0.80, 0.76, 0.76 for 1-9 tokens, and passes of 1.52, 1.99, 2.31, 2.65, 3.01, 3.47, 3.92, 4.33 single steps
for 2-9 tokens, slightly below the drafter's line.
A pass over n tokens now costs about 0.74 + 0.42 n single steps, so even a perfect 8-token draft gains at most about 2x,
and a draft accepted 60% of the time still gains almost nothing. The drafter therefore estimates the acceptance of a drafted position
separately by matched-context length (3, 4-7, 8-15, 16+ tokens; decaying counts), drafts the length whose expected
tokens per pass (1 + p + ... + p^k) divided by its cost is largest, and only if that ratio is at least 1.03; the costs
start from the line fitted to the table and then follow the pass times the loop observes. After 16 tokens without a
draft worth making it probes with one token. The defaults were picked by replaying a policy grid over the recorded
outputs (ab_speculation with LELEKA_AB_REPLAY).
Paired A/B in one worker process (crates/cpu-worker/examples/ab_speculation.rs, raw lines and machine state in
benchmarks/results/speculation-ab-2026-10-16.txt): four agent-style Harmony prompts (856-878 tokens) over a Rust
source file, greedy, 320 output tokens at most, 3 alternating pairs per prompt, warm model, decode time only. Paired
speed-up of decode (mean of the three pair ratios):
| task (output tokens) | inherited fixed-length drafter | cost-aware, noisy machine | same, quieter machine | default policy, noisy | with multi-activation kernels |
|---|---|---|---|---|---|
| rewrite the file with two names changed (320) | 1.36 | 1.26 | 1.34 | 1.25 | 1.54 (1.49, 1.61, 1.52) |
| unified diff adding an attribute (303) | 0.94 | 1.00 | 1.15 | 1.10 | 1.06 (1.11, 1.06, 1.00) |
| functions as JSON (195) | 0.97 | 0.98 | 1.04 | 0.97 | 0.97 (0.97, 1.02, 0.92) |
| explain the file (162) | 0.96 | 0.96 | 1.01 | 0.98 | 0.97 (0.99, 0.97, 0.97) |
Plain decode ran at 8-9 tok/s on the noisy machine and 11-12 on the quieter one; pair-to-pair spread is about 5%, so the last two rows are within noise of 1.0. Copying output (rewrites, patches) gains 1.1-1.35x; new text neither gains nor clearly loses. Three pairs per prompt are not enough for percent-level claims, and these are four prompts, not an agent trace: the switch stays experimental and off by default.
The last column was run after the multi-activation kernels on a quiet machine (no other model or compiler process;
benchmarks/results/batch-pass-multi-2026-10-16.txt; plain decode 8.9-11.6 tok/s, outputs identical in all 24 runs). The
rewrite now reaches 16-17 tok/s against 10.5-11.6 plain (1.54x, every pair above the 1.23-1.28 of the run before the
change); it drafts longer runs, 222-224 of 227-230 drafted tokens accepted in 39-41 verified batches (43-56
before). The other prompts are unchanged within the spread. Replaying the recorded outputs through the drafter
predicts 1.59, 1.15, 1.00 and 0.99, close to what was measured. An earlier run of the same binary overlapped another
session's GPU prefill probe and gave 1.34, 1.04, 0.97 and 0.94; it is kept in the results file as disturbed.
Where the decode time goes (LELEKA_SPECULATION_LOG=1, 2 pairs on a quiet machine, outputs identical in all 16 runs;
paired speed-ups 1.55, 1.12, 1.01 and 0.97): everything outside the model passes, that is sampling (40-64 ms per
request), output lines, drafting and cache cuts, is under 0.5% of decode time, and single steps in the speculating arm
cost the same as in the plain arm (81-93 ms). The serving loop has no hidden cost; the gain is set by acceptance and
pass cost. Verifying passes in the worker cost 1.57, 2.04, 2.50, 2.99, 3.66, 4.04, 4.32 and 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 (real drafts,
positions 900-1200; only 10-11 passes each of 6 and 7 tokens), which is why the rewrite measured 1.55 against the 1.59
the replay predicts. The drafter follows these observed times after three passes of a size.
Verifying drafts on the integrated GPU or the NPU does not pay: both run a pass layer by layer with weights uploaded (GPU) or expanded and prefetched (NPU) every time, a fixed cost of seconds. One 9-token pass from position 0 took 7.3 s on the GPU (upload 1.2, attention 2.0, experts 3.0, readback 0.7) and 6.3 s through the NPU service, against 0.75-0.93 s on the CPU; neither is bit-identical to the CPU decoder (KL 1e-4 and 3e-4), so exactness would be lost as well. Keeping the weights resident on the GPU would need a second ~12 GB copy, which does not fit beside the CPU's mapping on this 32 GB machine (13-15 GB available during these runs). With this, CPU speculation can lift copy-heavy decode from about 10-12 to 13-17 tok/s; the 20+ tok/s goal of STRA-220 is not reachable this way on the single-channel laptop.