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>
11 KiB
Integrated-GPU prefill (STRA-219) — experimental
Status: experimental, off by default, not wired into the worker yet. Crates: leleka-igpu (WGSL kernels on
wgpu, Vulkan or DX12), leleka-gptoss-igpu (the layer driver, implements leleka_gptoss::PrefillAccelerator).
Production serving stays Python-free and works without a GPU; the GPU path is an optional accelerator for the
prompt-processing phase only.
What runs where
- Prefill of a long prompt: all layers on the GPU, layer after layer. One layer's weights are repacked
(threaded) and uploaded, every batch of up to 512 tokens runs through it, and the layer's keys and values are
read back as half-precision rows into the CPU decoder's cache (
State::store_kv). Only one layer of weights is on the GPU at a time; the hidden states of the prompt stay there between layers. - The output projection of the last token and all decoding stay on the CPU (decode is memory-bandwidth bound and
the iGPU shares that bandwidth: ~40 GB/s measured on both sides, see
experiments/igpu-spike). - Prompts shorter than the threshold passed to
Model::prefill_reuse_acceleratedand prefix-cache hits take the CPU path (the cached prefix is uploaded to the GPU per layer when the GPU continues a prompt).
Kernels (all tested against the CPU decoder's own functions, crates/igpu/tests)
int8 dot4I8Packed GEMM over Q8_0 and MXFP4 weights with bias and residual-accumulate epilogues, grouped MoE
GEMM with a tile table and row gather, RMSNorm+Q8_0 quantize, Q8_0 quantize, SwiGLU-OAI+quantize, RoPE (the
decoder's own rotation table), half-precision KV store, grouped-query attention with sinks (full and sliding),
router logits + top-4 + softmax, slot-ordered expert combine.
Two findings worth keeping: the compiler folds unpack2x16float(pack2x16float(x)) to x, so Q8_0 block scales
are rounded to half with an explicit bit-level round-to-nearest-even (f16_round); and dynamically indexed
private arrays spill, so the generated GEMM code uses named scalars.
Numerics and quality gate
Not bit-identical to the CPU path: activations are quantized to int8 with the same rule (scales rounded to half
exactly like ggml), but the GPU sums in other orders and its division/inverse square root are not exactly
rounded, so about 0.04% of quantized values land one step away. Teacher-forced comparison on the 383-token gate
text (benchmarks/quality/gpt-oss-20b-teacher-forced, 2026-10-15, Core Ultra 7 265U, Intel iGPU via Vulkan,
batch 512). Two GPU runs are shown because they differ only by the attention kernel (a rewrite that reorders float
sums at the 2e-5 level):
| Pair | best token agrees | mean KL (shared top-20) | NLL (ours vs reference) |
|---|---|---|---|
| GPU prefill (scalar-load attention) vs llama.cpp | 97.1% (372/383) | 0.0100 | 1.2976 vs 1.2828 (+0.0148) |
| GPU prefill (vec4 attention) vs llama.cpp | 95.3% (365/383) | 0.0121 | 1.3108 vs 1.2920 (+0.0188) |
| GPU prefill (first) vs Leleka CPU (AVX-VNNI) | 97.4% (373/383) | 0.0067 | 1.2976 vs 1.2979 |
| GPU prefill (vec4 attention) vs Leleka CPU (AVX-VNNI) | 96.6% (370/383) | 0.0080 | 1.3108 vs 1.3067 |
| the two GPU runs against each other | 96.6% (370/383) | 0.0058 | |
| CPU (AVX-VNNI) vs llama.cpp (from the gate README) | 97.1% | 0.0080 | +0.0061 |
The criteria are ≥95% agreement, mean KL ≤ 0.012 and NLL within 0.02. The second GPU run misses the KL limit
by 0.0001; this is the measure's noise on this one text, not a measured regression: the two GPU runs differ
from each other (0.0058) about as much as either differs from the CPU path (0.0067, 0.0080) and as the CPU's own
scalar and SIMD kernels do (0.0048); the divergence sits in positions 10-60 of this Harmony text, where the model
amplifies rounding differences. On a second text (the first 635 tokens of docs/cpu-runtime.md, no llama.cpp
reference) the same comparisons give: GPU vs CPU-VNNI KL 0.0019 / 97.5%, CPU-scalar vs CPU-VNNI 0.0014 / 97.3%,
GPU vs CPU-scalar 0.0018 / 96.7%, i.e. the GPU adds about as much noise as swapping the CPU kernel level does.
Conclusion: borderline against the strict llama.cpp criterion on the one reference text, equal to the CPU's noise
floor everywhere else; it stays experimental and off by default until the gate has more reference text.
Greedy continuations of a 128-token synthetic prompt were identical from both caches (8 tokens).
Speed: paired A/B (warm), 2026-10-15
crates/gptoss-igpu/examples/ab_prefill.rs, raw output in benchmarks/results/igpu-prefill-ab-2026-10-15.txt.
CPU decoder (AVX-VNNI, 14 threads) against the GPU prefill (batch 512), same random-id prompts, runs alternating
in order in one process with a fresh cache each time, one untimed warm-up of each path first. Core Ultra 7 265U,
Intel iGPU via Vulkan (driver version and power limit not recorded), model gpt-oss-20b-MXFP4 (SHA-256
65d06d31…cde53ab), commit of this document's parent (HEAD at the time: f07302b plus the example). Warm only; no
cold-cache runs; prompt tokens as listed, 0 output tokens (prefill only; both paths returned the same next token
in every run, 27).
| Prompt tokens | pairs | CPU median s (tok/s) | GPU median s (tok/s) | paired speed-up, mean (95% CI) |
|---|---|---|---|---|
| 512 | 5 | 31.6 (16.2) | 10.1 (50.8) | 2.87x (2.45-3.29) |
| 1024 | 5 | 60.4 (17.0) | 18.0 (56.8) | 3.40x (2.77-4.04) |
| 2048 | 3 | 126.6 (16.2) | 31.8 (64.3) | 3.97x (3.39-4.55) |
| 4096 | 3 | 270.0 (15.2) | 74.4 (55.1) | 3.57x (2.87-4.26) |
Limits of this result: synthetic random-id prompts (not an agent trace), three to five pairs per size (enough for a 3x effect, not for percent-level claims), the machine was otherwise idle but clocks and power were not controlled, and the GPU path's quality is the borderline gate result above. Time-to-first-token for a real request also includes the CPU's lm-head and the control plane; the end-to-end agent workload A/B is still to do.
After the A/B above, staging two shared-dimension blocks per barrier pair in the MXFP4 GEMM (bit-identical output) took a single 1024-token GPU prefill from 15.9 s to 13.6 s (75 tok/s; the A/B table was measured before this change). Other expert tiles per thread (6x6, 4x3, 3x4, 6x4, 4x6, 5x5, LELEKA_IGPU_MOE_TILE) were not faster than 4x4; the machine warmed up during that sweep, so small differences there are not meaningful.
Where the GPU time goes (earlier single runs): experts are the floor (the grouped GEMM runs at 0.6-0.85 TOPS of
integer work against 4.49 TOPS for dot4I8Packed alone, examples/dot4_peak.rs, tile sweep with
LELEKA_IGPU_TILE), and attention grows with the square of the context (one full layer over a 512-token batch
ending at position 4096: 0.52 s with the first kernel, 0.22 s with the vec4 one). Below about 256 prompt tokens
the GPU is not faster (128 tokens: CPU 7.0 s, GPU 11.3 s before the upload overlap), hence the worker's default
threshold.
Agent-shaped episode through the control plane (paired, alternating)
benchmarks/tools/Compare-PrefillWorkers.ps1, raw lines in benchmarks/results/agent-episode-ab-2026-10-15.jsonl.
Each arm starts the control plane with one worker and replays the same episode on /v1/responses: four turns, turn
k carrying k scripted (function_call, function_call_output) pairs whose outputs are about 1380 tokens of
deterministic pseudo-source each, 32 output tokens per turn. Earlier turns are an exact prefix of later ones, so
each turn after the first processes only the newest tool output (prompt tokens 1511, 2901, 4281, 5665; cached 59,
1511, 2901, 4281). Fresh worker process per arm, model file warm, one untimed request per start, three pairs with
alternating order (cpu,gpu / gpu,cpu / cpu,gpu), GPU worker threshold 256 tokens. Same machine caveats as above.
| Turn (new tokens ≈ 1380 each, except turn 1: 1452) | CPU worker wall s (3 runs) | GPU worker wall s (3 runs) |
|---|---|---|
| 1 | 79.8, 79.9, 79.5 | 25.0, 25.6, 23.7 |
| 2 | 79.3, 80.1, 81.0 | 29.0, 31.0, 30.8 |
| 3 | 83.8, 84.8, 84.0 | 32.7, 32.6, 31.0 |
| 4 | 88.4, 89.5, 89.0 | 40.7, 34.9, 38.1 |
| episode total | 331.2, 334.4, 333.5 (mean 333.0) | 127.5, 123.9, 123.6 (mean 125.0) |
Paired episode speed-up CPU/GPU: 2.60x, 2.70x, 2.70x (mean 2.67x). Wall time includes the 32 decoded tokens (about 3 s each, identical code on both sides), the control plane and the Harmony rendering; it is less than the 3-4x of the prefill-only A/B because of that fixed part and because the context (so attention) grows from turn to turn. The quality caveat of the gate section applies to the GPU arm; the answers of these requests were not compared.
Next
Long-prompt A/B (2k-8k tokens) against the CPU path with token counts and distributions as the charter requires; overlap weight upload with GPU work; optional resident weights when free RAM allows; attention scoring optimization; the worker-side switch with free-RAM admission (Phase D).
The worker (leleka-igpu-worker)
cargo build --release -p leleka-igpu-worker makes a worker with the CPU worker's protocol and decoder plus the
GPU prefill: leleka-igpu-worker --serve --model <gpt-oss.gguf> [--gpu-min-tokens 256] [--gpu-batch 512] (other
arguments as for leleka-cpu-worker). It is a separate executable so that the CPU worker keeps no GPU dependency.
Prompts with at least --gpu-min-tokens tokens to compute (after prefix reuse) are prefilled on the GPU; shorter
ones and all decoding run on the CPU. With no usable GPU it says so on standard error and serves from the CPU; if
a GPU prefill fails the request is redone on the CPU and the GPU is not used again in that session. The control
plane starts it like any worker (set the worker executable to this binary).
Memory admission: the GPU's memory is the system's memory, so before each GPU prefill the worker compares the
OS's "available" figure with an estimate (two layers of weights, batch scratch, hidden states, caches, 1 GiB
headroom: about 2 GiB for a 40-token prompt, 1.6 GiB + headroom for 1024 tokens measured against 2.0 GiB peak
private bytes) and sends the request down the CPU path, with a line on standard error, when it does not fit; the
GPU stays in use for later requests (PrefillAccelerator::admit, examples/admission_check.rs).
--speculate switches on exact prompt-lookup speculation, verified on the CPU (docs/cpu-runtime.md). The GPU is not
used for verification: one 9-token pass takes 7.3 s against 0.75 s on the CPU, because every pass uploads the weights.
Not done yet: an A/B run of a full agent workload through the control plane at the charter's required measurement detail.
Splitting one prompt between this GPU path and the NPU path at the same time (leleka-gpu-npu-worker) was built and
measured: no reliable gain over this worker on the agent episode, see docs/gpu-npu-prefill.md.