Commit Graph
5 Commits
Author SHA1 Message Date
Pavlo RatushnyiandClaude Opus 5.5 87637c2b0b perf: multi-activation kernels make the CPU small-batch pass cheaper, bit-identical (STRA-220)
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>
2026-10-16 13:07:38 +02:00
Pavlo RatushnyiandClaude Sonnet 5.5 253967f713 feat: add prompt-prefix reuse to the gpt-oss decoder; AVX-VNNI tile kernel without sign instructions (STRA-217)
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>
2026-10-14 18:55:12 +02:00
Pavlo RatushnyiandClaude Sonnet 5.5 4916aa867b feat: add chunked prefill to the gpt-oss decoder and register-tiled kernels (STRA-217)
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>
2026-10-14 18:47:12 +02:00
Pavlo RatushnyiandClaude Sonnet 5.5 efd4018a46 feat: add experimental pre-converted activation layout, topology helper and paired benchmarks (STRA-211)
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>
2026-10-14 15:32:30 +02:00
Pavlo RatushnyiandClaude Sonnet 5.5 164bfa60b8 feat: add MXFP4 x Q8_0 dot kernels at scalar, AVX2 and AVX-VNNI (STRA-211)
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>
2026-10-14 15:17:52 +02:00