Commit Graph
53 Commits
Author SHA1 Message Date
Eddoursul fbb8bfa3e2 The argmax and the draft's top probability over many blocks a row
The verify window's head ended with sampler_greedy_kernel, one 1024-thread block a token over the 248,320 logits,
and each draft pass with it and row_top_prob over the 40,525-token draft head, one block each.  argmax_rows scans a
row in up to 128 blocks (4,096 logits each), the row's last block merging their picks (the larger value, on equality
the lower index: the one-block kernel's order); row_top_prob_split computes row_top_prob's 32 warps' sums in 8 blocks,
the row's last block adding them in order.  Both keep their counters and partials in per-row slots of one scratch,
whatever a launch's row count.  Bitwise: verify_parity (ties, NaN, -inf, 1-8 rows on one scratch), and the window
hashes on fixed text equal the previous build's (IQ3_S, UD-Q4_K_XL; thinking and code text).

CUPTI, IQ3_S thinking text: the head's argmax 84-86 -> 9.7 us a window, a draft pass's argmax and top probability
15.1 + 10.1 -> 5.6 + 4.3 us; ~105 us a round (~0.7%).

Claude-Session: https://claude.ai/code/session_019XxRxQQNyk7Ycdr4ComSs1
2026-09-30 06:09:02 +02:00
Eddoursul b02ed634f7 Merge upstream main (a790805, engine 0.1.27): sampling, the web app, server fixes
Upstream's 236 commits since 6da1f66, with this branch's engine kept wherever both sides do the same
thing (the prompt cache, prompt lookup, the verify window's batched kernels, the second GPU tier, the
prompt path, the CPU pool's phase protocol).

Taken:
- serve/: upstream's server (web app with chat, monitor and MCP tools, Claude Code's /v1/messages?beta=true,
  llama.cpp's discovery endpoints and timings, --fit-max-tokens, LAN access with an API key, an engine that
  dies is restarted by the next request); the wait loop sleeps so Ctrl+C stops it on Windows.
- Sampling: temperature, top_p, top_k, min_p, seed and the penalties per request, on the GEN line.  The
  verify window samples its head after the graph (Philox(seed, position)), with one penalty-history row per
  window row; windows that read a prompt skip it.  spec_min_p sets a request's draft floor.
- The serve protocol: INFO before READY, PP lines per prompt chunk, DONE with the drafts accepted and
  offered, the reused tokens and the expert-cache hits of either GPU.
- CPU experts: the AVX-2 multi-token i-quant kernels for CPUs without AVX-512, IQ4_NL down rows of 2+
  tokens decoded once for all of them (STRATA_NO_IQ4NL), the i-quant rows prefetched 2 KB ahead
  (STRATA_IQ_PREFETCH).
- --prefill auto (setup writes it): 16384-token chunks, halved until their buffers fit the lendable slots.
- setup.py and its tools, tools/needle_bench.py, draft_vocab.py, make_profile.py, calibrate.py; docs.

Kept from this branch: data/expert-profile.bin (the 8,000-slot cap; upstream's full ranking would give
IQ3_XXS's 3090 cache ~1.3 GiB more, measured no faster).  Not taken: upstream's conversation cache and
prompt lookup, the helper-GPU caches and layer split, KV streaming and the q4/k8v4 KV, control vectors,
the low-RAM mode, pruned expert counts, the HIP and Turing builds (their files are in the tree, not built).

Window hashes on fixed text (--adapt-every 0) equal the previous build's on both models (IQ3_XXS with
STRATA_NO_IQ4NL=1: the IQ4_NL kernel sums in another order).

Claude-Session: https://claude.ai/code/session_019XxRxQQNyk7Ycdr4ComSs1
2026-09-30 05:24:01 +02:00
Niko1221 470a28364c Merge the AMD HIP backend (PR #121 by Konstantinos Korres, rebased onto 0.1.24) and its setup support 2026-09-29 18:09:50 +02:00
orangeandClaude Code 2aa8f72c96 Hybrid K8V4 KV cache: INT8 K + Hadamard-rotated Q4_0 V (--kv k8v4)
K stays INT8 (unrotated - the attention scores stay exactly int8's), V uses the
rotated q4_0 of kv_q4.hpp: 816 B per cell vs int8's 1,056. The K/V quantization
asymmetry is the point: K enters through the softmax scores, V only through a
softmax-weighted average (llama.cpp's q8_K/q4_V hybrids reason the same way).

No new kernels: the append/gather entry points already select K/V by blockIdx.z
and take separate K/V pointers, so the hybrid composes the existing validated
q8/q4 kernels with the unused half's lanes folded onto the used pool (a
bit-identical duplicate write). The fused attention gets KV_MODE 3 (K-side int8
loader, V-side q4); 0.1.22's tensor-core prompt path (qsa_prompt_attn) refuses
the hybrid pools through its !v_q check and the old kernel runs - covered by
the parity test. The MTP drafter stays INT8 (mtp.cpp toggles the format globals
around its state creation, any ring shape); qsa_kv_format exits on a hybrid
state rather than misreporting a layout (the kernels' own unsupported-geometry convention); the hybrid appends pass nullptr for
the host mirror (mode 0 has none). setup.py excludes k8v4 from the whole
auto-streaming decision (the engine refuses --kv-resident with it).

kv_hybrid_parity: bitwise append/gather through a non-identity page table,
step and batched mode-3 attention vs host references (<= 1.1e-07), and the
qsa_prompt_attn refusal - all at machine precision; kv_q8/kv_q4 parity unchanged.

Measured on a RTX 3090, Coder IQ1_M, 118.75k-token prompts, temp 0: decode
82-97 t/s (int8: 75; the band is draft-acceptance variance), prefill unchanged
~1,130-1,170 t/s, 26-needle seed 42 identical to int8's tokens, KV 1.39 GB at
131k (int8: 1.80). At --max-context 204800 on 24 GB: 1,024 t/s prefill,
82-91 t/s decode, 25/26 needles at 197.9k.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-09-29 18:09:42 +02:00
Niko1221 3ab8321013 HIP: build main's post-0.1.21 code (trap, device attribute, window-graph listing and GPU stamp); Windows NOMINMAX 2026-09-29 15:05:55 +02:00
Niko1221andClaude Opus 5.5 9a19f57ab3 Merge PR #109 (q8atnight): batch the verify window's per-token kernels
Resolved against 0.1.22: E-6's device-plan waits and copies kept (the row copy of the CPU share is used when the
device plan is off - bit-identical, +0.0 on the GPU rows as the pool leaves them); the multi-GPU per-device
shared-memory opt-in and stage pool callback kept. Left out: the session-wide --pcie-frac 0 skip of the PCIe path,
because a request can ask for a PCIe share (pcie_frac=, used by --calibrate) and the window graph is captured once.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN
2026-09-29 11:41:04 +02:00
Eddoursul 7105fccbe3 The 3090 tier's copies in pieces while its link carries nothing else
An update of the 3090's adaptive tier copied its moves at once (UD-Q4_K_XL 142-301 MB, 5-50 ms at 6 GB/s over the
x4 link), and a copy in flight there slowed every transfer of the verify window over that link: the router kernel's
rows and doorbell to the host 19 -> 40 us a layer at 1 token, the combine's read of the CPU's rows 6 -> 9 us, the wait
for the CPU's rows +20-170 us (CUPTI, UD thinking); 2-5% of a fixed-text run.

Now the moves go out in pieces: once a layer's CPU rows are in (Verifier::set_rows_in, after the flag and the
prediction), as much as lands before the next layer's router writes to the host (that layer's running average of the
time from the previous layer's CPU rows to its ring, by window size, less 80 us).  AdaptiveTier stages a window's moves
before it (their residents evicted before the window's residency snapshot), sends a blob in as many pieces as it takes,
and admits a move once its batch has landed (a ring of events); an update drops the queued moves not staged yet and
skips the experts still under way.  The 3090 tier counts an expert the 5070 Ti holds at half its use (moving it only
shifts work between the GPUs), and the 5070 Ti tier yields only the experts the 3090 tier has staged.  The tier keeps
the host residency table only: a synchronous copy of its device table at every admission waited behind the pieces.
Without a second GPU the pieces cannot carry what the tier needs, so a window's start sends all the queued moves there
and an update waits for the previous one's, as before.

Fixed text, both GPUs, 6 runs of each build in both orders, t/s: IQ3_XXS code / thinking / after 16K / edit +0.2 /
+1.6 / +4.5 / -2.2%, UD-Q4_K_XL +2.3 / +7.7 / +6.7 / -0.1%.  The pieces carry less than the updates asked for (UD code
29 MB a round against 86): the 3090's hits rose on thinking text and fell on code and edits.

Claude-Session: https://claude.ai/code/session_019XxRxQQNyk7Ycdr4ComSs1
2026-09-29 10:54:14 +02:00
Niko1221andClaude Opus 5.5 0abcd5b3c7 E-6: the device plan opt-in (STRATA_VERIFY_DEVICE_PLAN=1)
Exact on RIBPC (5080 alone and 5080+3090, device plan off/on 10/10 identical), but decode and prompt speed
within noise (1 GPU story 86.7 -> 84.5, code 103.3 -> 102.0 tok/s; 2 GPUs 81.5 -> 82.4, 113.9 -> 109.9).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN
2026-09-29 09:09:00 +02:00
Niko1221andClaude Opus 5.5 efddd74880 E-6: a verify layer whose routed experts are all in VRAM needs nothing from the host
After routing, one thread checks the group's entries against the device residency table; when all
are resident it writes the plan the host pool would (same layout, same order) and marks the ring.
The layer's waits on the host (plan, PCIe share, CPU share) then return at once and the CPU rows
are zeros; the host still runs its loop, off the GPU's critical path. STRATA_VERIFY_DEVICE_PLAN=0: off.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN
2026-09-29 08:56:02 +02:00
Andy 1e4515c87b decode: batch the verify window's per-token kernels (bit-identical); skip the PCIe path with --pcie-frac 0; decode timing/profile switches 2026-09-29 05:55:18 +04:00
Eddoursul fd23d911b9 QSA decode attention: the prompt path's kernels split among blocks, their partials merged with the output gate
The decode attention ran a block per 64 selected cells and KV head, a warp a cell with each head's score a shuffle
reduction, then a merge and the output gate as kernels of their own: ~43 us a QSA layer at 1 token whatever the cell
count, and the draft layer's attention over its 32K window ~88 us (a 512-chunk merge).  Now:

- The prompt path's kernels take a split (a SPLIT template flag): a block per (KV head, query, split) walks its share
  of the query's cells and writes its unnormalized sums with each row's maximum and sum.  INT8 pools on the tensor
  cores as in the prompt path, FP16 pools in FP32.  Up to 20 splits a query, all queries' blocks in one wave, whole
  64-cell tiles.  The prompt path's outputs are bitwise unchanged.
- attn_merge_kernel adds the splits with the log-sum-exp rescale, issuing all its loads in one round, and applies the
  output gate (native_qsa_gate_apply's instructions in PTX, bitwise), so the verify window and the draft layer drop
  their gate launches and the ungated buffer.
- A query's scratch no longer grows with the capacity (the draft layer's 32K window: 12 MiB less VRAM).
- verify_parity: the decode attention (6 queries at once and each alone) within 2e-5 of the prompt path's kernels, the
  gate bitwise native_qsa_gate_apply's.

The QSA mixer 106 / 116 / 133 / 143 -> 73 / 83 / 89 / 99 us at 1-4 tokens (IQ3_XXS thinking, CUPTI): the attention
8-9 us, the merge 3-4.  Not bitwise: along llama.cpp's texts the KL to llama.cpp is within noise of b67a291 on all six
texts (UD after 16K closer), and the two builds are as far apart as one- and four-token windows.  Fixed text, both
GPUs, 6 runs of each build in both orders, ms per round: IQ3_XXS code -3.4%, thinking -3.8%, after 16K -5.5%;
UD-Q4_K_XL -0.9%, -2.7%, -3.8%.  After the 131K prompt (IQ3_XXS) 113.9 -> 125.1 t/s.

Claude-Session: https://claude.ai/code/session_019XxRxQQNyk7Ycdr4ComSs1
2026-09-28 23:47:32 +02:00
Niko1221andClaude Opus 5.5 87293712e3 Layer split v1 (step 4): the second stage on its own GPU
--split-device D (default: the second visible GPU) runs layers [K, n) on device D with
its own copy of the dense weights, session, head, drafter and an expert cache filled
from the profile's pairs of its layers. Verifier and MtpDrafter switch to the device
they were made on (OnDevice), the pool wrapper swaps the stage's cache pointers, the
penalty history lives with the head, and the s2 LUT is per device.

v1 switches off what does not cross devices yet: checkpoints, adaptive swaps, the PCIe
share and the batched prompt path (prompts read through the verify windows).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN
2026-09-28 23:37:29 +02:00
Niko1221andClaude Opus 5.5 293c51c86d Layer split v1 (step 1-2): a verify window can run a range of layers and hand its residual to the next stage
--layer-split K runs layers [0, K) and [K, n_layers) as two verify stages on the same device (sharing weights,
session and expert cache). The hand-off carries R, the last layer's pending write and inject, so the next stage
folds it in exactly as the unsplit window does. The GPU shared-memory opt-ins are now per device.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN
2026-09-28 23:11:45 +02:00
Eddoursul b67a2913f3 Verify window: the projections' rows a warp by format and tokens, the GDN qkv grid first, IQ3_S decoded once; bitwise
- native_mmvq_il picks the rows a warp (1, 2 or 4) from a table by format, token count (1-4) and row class, measured
  alone at the engine's clocks (scratch/mm1_bench.cu) and in the engine, where the kernels run beside other branches.
  It took 2 rows, 4 for Q4_K and Q6_K from 8192 rows: at 3-4 tokens those 4-row instances need 115-193 registers, and
  Q4_K's qkv took 34-39 us where 2 rows take 25-30; Q6_K runs fastest at 2-3 tokens with 1 row (its out projection at
  3 tokens 34.6 -> 20.8 us); UD's Q8_0 head at 2 tokens with 1 row (837 -> 773 us).
- One column also goes through native_mmvq_il (its kernels read the q8_1 blocks, Q81One): IQ3_S takes them at every
  token count, and the shared expert's IQ3_S gate and up projections at 2+ tokens decode their weights once for all
  tokens (shared_expert_multi quantizes with the interleaved copy, the verify window's xil_): 11.1 / 15.1 / 17.9 ->
  9.0 / 10.5 / 8.2 us at 2 / 3 / 4 tokens.  IQ3SCols loads a block's 8 activation positions before its sums: its
  3-column instance, allotted 40 registers, loaded each after the last one's use.
- The GDN mixer records qkv's grid before the gate projection's: the conv runs beside the gate's last blocks.
- The interleaved kernels keep a grid-stride loop though the grid gives each warp one group: without it ptxas gives
  several instances fewer registers, and Q6_K's at 3 tokens run 10-50% slower.
- mmvq_il_parity: 1-8 columns with each rows a warp; --bench at the engine's clocks (a one-thread spin before each
  launch: a continuous load reaches the 3090's 260 W cap).

The mixers (IQ3_XXS thinking, us at 1 / 2 / 3 / 4 tokens): GDN 64.0 / 78.0 / 90.2 / 87.3 -> 62.7 / 71.9 / 76.9 /
84.1, QSA 105.4 / 118.9 / 144.3 / 141.3 -> 106.0 / 116.2 / 133.4 / 143.1; the shared expert ends last before the
combine in 1.3 / 0.1 / 0.8 / 1.1% of the layers (1.3 / 0.4 / 16.5 / 14.6).  Window hashes identical (thinking, code
and after 16K; both models; --spec-split and --second-gpu -1).  Fixed text, both GPUs, against aa209f7, ms per round
(6 runs of each build, half of them first in their pair: a run's place moved code-text runs by 3-6%):
IQ3_XXS code -0.9%, thinking -1.0%, after 16K +0.3%; UD-Q4_K_XL code -0.9%, thinking -1.0%, after 16K -1.3%.

Claude-Session: https://claude.ai/code/session_019XxRxQQNyk7Ycdr4ComSs1
2026-09-28 20:10:06 +02:00
Niko1221andClaude Opus 5.5 a49e8103c2 Engine 0.1.19: penalties on every drafted token; the CLI samples; sampler hardening
- serve: a verify window samples T rows, but only row 0's penalty history was staged; rows 1..T-1 read
  unwritten slots (past the allocation at penalty_last_n=4096). Every row now gets its own history
  (strata::kernels::penalty_rows: the consumed tail, the fed-back token, the drafts before that row).
- prompt windows (their picks are discarded) skip the head sampling: Verifier::set_head_sampling.
- sampler: history ids outside [0, n_vocab) are ignored (they set bits past the shared bitmap); sampled
  top_k 0 or > 64 means 64 and every row is written (0 used to leave the row unwritten).
- server: a client's top_k 0 or > 64 is sent as 64 (it fell back to the default 20).
- CLI: the speculative loop gets the CLI's sampling (it was always greedy), the per-token path draws
  Philox(seed, position) like a verify window, and the effective sampling is printed.
- sampler_parity: fixtures 12-15 (per-row histories T=1..8 x H=1..4096, out-of-vocab ids, the top_k
  contract, penalty_rows); outputs are pre-filled so an unwritten row fails.
- setup requires engine 0.1.19.

Found by the engineering performance review (C1, C2).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN
2026-09-28 16:53:36 +02:00
Eddoursul aa209f7124 Verify window: the shared expert's gate in the combine, fewer QSA mixer launches, one PLE pass a window; bitwise
- The shared expert's branch ends with its down projection: its scalar gate's logits come from a branch of their own,
  and the gather-combine applies sigmoid and product in shared_expert.cu's instructions (inline PTX without flush to
  zero; shared_expert_gate_rows, which the one-token path now uses, is the reference).  Its last kernels no longer
  wait behind the routed experts' grids: on IQ3_XXS thinking text it ends last before the combine in 0.4-16% of the
  layers instead of 58-66%, and at 2+ tokens the prediction's bias update, dispatched behind them, no longer delays
  the next layer.
- The QSA mixer: the indexer's key and query projections in one launch (bf16_gemv_fp32_mmvf_multi takes a second
  matrix), the key tail's snapshot in the append, each group of heads' RMS norm and RoPE in one kernel
  (native_qsa_norm_rope_tokens; the queries read from their projection's rows, the split copy gone), the keys and
  values dispatched ahead of the queries' grid, and that grid after the indexer's projections, so the append goes
  ahead of it: 8-12 us less a QSA layer.
- The PLE block: both projections of a window's tokens in one pass each, then native_ple_postops_tokens, which now
  writes the history after each token for the commit.  bf16_gemv_fp32_mmvf_multi takes 4 rows a block from 2 tokens
  (each pair's inputs loaded once for them) and the one-row kernel at 1 token: the PLE section 110-174 us a window of
  1-4 tokens instead of 112-428 (IQ3_XXS).
- The verify window requires the native combine, shared expert gate, QSA norms and RoPE and PLE block (the --native
  preset's); their fallbacks are gone from it.
- verify_parity: the gated combine, the fused norm and RoPE, the two-matrix and 4-row projections, the append's tail
  snapshot, the history after each token.

Window hashes identical (thinking, code, after 16K; both models; --spec-split and --second-gpu -1).
Fixed text, both GPUs, against 962b99c, ms per round (2 rounds; UD-Q4_K_XL code 5): IQ3_XXS code -6.1%,
thinking -2.4%, after 16K -2.5%; UD-Q4_K_XL code +1.6% (its CPU pool's drifting RAM rate: the serial part
-0.3 ms, the pool +0.9), thinking -2.0%, after 16K -1.4%.

Claude-Session: https://claude.ai/code/session_019XxRxQQNyk7Ycdr4ComSs1
2026-09-28 16:12:09 +02:00
Eddoursul 962b99c703 Verify window: the shared expert and the prediction fork before the router, the CPU's rows awaited on a branch
The shared expert's branch and the next layer's prediction need only the FFN read.  They now fork there, recorded
after the router so its blocks are dispatched first, and run beside its routing, ring and hit plan; the prediction's
bias update waits for the router.  They forked at the doorbell before: the prediction router's 512 blocks were
dispatched ahead of the routed experts, which started 5-7 us after the router, and the shared expert's branch, whose
kernels wait while IQ3_XXS's expert kernel holds every SM's registers, ended last before the combine in 70-82% of
the layers on IQ3_XXS thinking text (a CUPTI trace of the verify graph).  The wait for the CPU's rows runs on a
branch of its own from the doorbell, joined before the combine, instead of after the routed experts.

Bitwise: window hashes identical (thinking text, both models; --spec-split, --second-gpu -1, prefetch off).
Fixed text, both GPUs, 2 rounds against 0046ba6, ms per round: IQ3_XXS code -2.8%, thinking -3.1%, after 16K -2.2%;
UD-Q4_K_XL code -0.9%, thinking -2.5%, after 16K -1.9%.

Claude-Session: https://claude.ai/code/session_019XxRxQQNyk7Ycdr4ComSs1
2026-09-28 13:21:11 +02:00
Eddoursul d9ce223164 Verify window: the router kernel writes the FFN input as the pool's Q8_K rows and the GPUs' q8_1 rows
The router kernel copied each layer's FFN input to mapped memory as floats (the router stage's long pole), and the CPU
pool quantized it to Q8_K (ggml's quantize_row_q8_K, before its workers start: 0.27-0.65 ms a round); the host copied
the floats again for the second GPU, whose graph quantized them to q8_1, and a branch beside the router quantized them
to q8_1 for the 3090's own experts.

Now the router kernel's first blocks, four superblocks of 256 values each, write the q8_1 rows (quantize_q8_1_rows'
arithmetic) to the device for the 3090's experts and to mapped memory for the second GPU, and ggml's Q8_K rows
(quantize_row_q8_K_ref) to mapped memory for the pool, bitwise: their float operations are PTX add/mul/div.rn, which
the file's fast-math flags do not change.  Everything leaves in 16-byte stores: with a block per superblock, its
292-byte Q8_K block written 4 bytes at a time, the kernel was 1.6 us slower than the float copy at 4 tokens; four
superblocks are whole 16-byte chunks.  The pool takes the Q8_K rows of the layers whose gate/up activation is Q8_K
(pool_takes_q8k: every layer of both model files), the floats otherwise; the second GPU copies the q8_1 rows in.
The kernel alone, in graphs (scratch/router_rows_bench.cu), us at 1 / 2 / 3 / 4 / 8 tokens: the float copy 13.7 /
15.2 / 17.3 / 18.3 / 31.8, the quantized rows 14.2 / 15.4 / 16.6 / 17.5 / 24.7.

Window hashes identical to the previous commit (--adapt-every 0): thinking text on both models, code text with and
without --spec-split.  verify_parity: the q8_1 rows bitwise quantize_q8_1_rows', the Q8_K rows ggml's own
(native_quant_act), with denormals, zero blocks and tied maxima.
Fixed text, both GPUs, against the previous commit, ms per round (t/s): code 4 rounds, UD-Q4_K_XL -1.9% (+1.7%;
+0.6% without the base's slow first run), IQ3_XXS -0.2% (+0.4%); thinking and after 16K 4 rounds, UD-Q4_K_XL +0.3%
(-0.1%) and -0.2% (+0.4%), IQ3_XXS +0.4% (-0.3%) and +1.2% (-0.3%, more tokens a pass).  The pool's call is shorter by
the quantization (0.27-0.65 ms a round), which reaches the round only where the CPU is the later side; where the 3090
is (IQ3_XXS thinking) the host waits that much longer for the next ring.

Claude-Session: https://claude.ai/code/session_01Ljcr81CGEb4dQcdiAZcXAs
2026-09-28 08:15:21 +02:00
Niko1221andClaude Opus 5.5 1b03bac730 verify.cpp: include <cmath> (engine 0.1.13 did not compile on Linux: std::isfinite)
MSVC brought <cmath> in through another header; GCC does not. Found by building in WSL (Ubuntu 24.04, CUDA 13.0)
through setup.sh the way a Linux user does.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN
2026-09-28 08:03:22 +02:00
Eddoursul 84c39840f7 Second GPU: its rows reach the 3090 on a branch while the CPU works; its own experts before the prefetched ones
After the CPU pool the host waited for the second GPU's graph (SecondGpu::finish), copied its rows into the pool's
mapped rows and raised the flag; the 3090's combine then read them over the x4 link with the CPU's.  A layer that took
a prefetched expert launched the whole share behind the prefetch copies.

Now the second GPU's graph writes its rows into the window's mapped rows itself, at their entries, and its last block
raises a flag of the token group's once they are visible.  A branch of the 3090's graph, forked at the doorbell, waits
for that flag and copies the rows into VRAM (fetch_listed_rows, from the entries the pool publishes), and the combine
takes them from there as they are (native_moe_gather_combine's third list).  The host raises the CPU's flag as soon as
the CPU's rows are in, and the flag of a layer without a share at once.  The share goes out in two launches: the
experts in its cache at once, the prefetched ones once their copies have landed.  The second tier's copies between
windows wait for the last share (AdaptiveTier::set_after), which may still read its slots; a failure there is seen
every ~2 ms while the host waits for a ring (Verifier::set_watch), and the window's waits are then released.
--stats: the layers whose second-GPU rows came after the CPU's, and the host time from the CPU's to theirs;
--window-profile: the combine's wait for them and their branch.

Window hashes identical to the previous commit (--adapt-every 0): thinking text on both models, code text with and
without --spec-split, and without the prefetch.  verify_parity: the gather-combine with the second GPU's rows fetched.
Fixed text, both GPUs, 2 rounds against the previous commit, ms per round (t/s): UD-Q4_K_XL code -8.6% (+10.3%; the
host's pool call 17.0 -> 14.5 ms a round, 43 -> 48 GB/s over the rows), thinking -1.8% (+1.1%), after 16K -1.0%
(+1.1%); IQ3_XXS code -0.9% (+0.9%), thinking -0.2% (+0.1%), after 16K -1.0% (-0.7%).  The second GPU's rows now come
after the CPU's in 10-20 layers a round on UD-Q4_K_XL (0.56-1.08 ms a round), 3-11 on IQ3_XXS (0.11-0.50 ms).

Claude-Session: https://claude.ai/code/session_01Ljcr81CGEb4dQcdiAZcXAs
2026-09-28 06:09:07 +02:00
Niko1221andClaude Opus 5.5 b89c989a71 prompt path: never write into the borrowable cache slots while laying out (a resident expert was corrupted)
When serving, the prompt path lays its buffers out at start in the expert-cache slots it may borrow, but those
slots hold resident experts until a request lends them. Writing the MMQ row table at layout time overwrote part
of a resident expert: decode later computed it on the GPU, and the first window that routed to it turned every
logit into NaN ("!!!!" from mid-answer, e.g. at position 138 of an 86-token prompt, even with the prompt read
through the windows). The table is written at the start of every prompt read, while the slots are lent.
STRATA_DBG_NAN=1 also reports the first verify window with non-finite logits and the state a prompt leaves.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN
2026-09-28 04:56:25 +02:00
Eddoursul 3ab7c61a7e Second GPU: the prefetch predicted from an estimate of the next layer's FFN input
Each layer's router also ran on the previous layer's FFN input to pick the experts copied ahead to the second GPU:
52% of them were used on UD-Q4_K_XL code, 34% on thinking; IQ3_XXS 44% / 18%.  With hyper-connections each layer's
FFN input is its own gated mix of the four residual streams (its own norm weights and gates), which that misses.

Now each layer's FFN read also writes the next layer's estimated FFN input: that layer's read of this state, with the
read's gates (sigmoids of two projections) replaced by their running average over the windows, computed in the up
kernel's epilogue, which holds the updated state and its streams' norms (FusedGrArgs::est).  The prediction branch
runs the next layer's router on it, each expert's logit corrected by a running average of its error
(VerifyRouterArgs::bias, verify_router_bias_update, after the prediction; the predicted logits in two buffers by
layer parity).  The FFN reads keep the gates' average (FusedGrArgs::gate_ema).  Both learn only while the tiers
adapt: with --adapt-every 0 the gates stay at one half and the bias at zero, so the prediction depends on the window
alone and a regenerated turn reproduces its output.

Share of the prefetched experts used, fixed text: UD-Q4_K_XL code 71%, thinking 57%, after 16K 69%; IQ3_XXS 61%,
34%, 53%.  Both GPUs, 3 rounds against the previous commit, ms per round (the drafts accepted differ between builds
even on fixed text; t/s in brackets): UD-Q4_K_XL code -4.0% (+5.0%; the CPU's experts 4.81 -> 4.25 a layer), thinking
-2.9% (+2.8%), after 16K -3.4% (+2.3%); IQ3_XXS code -4.7% (+5.6%), thinking -0.3% (+0.3%), after 16K -1.5% (+1.3%).
The next layer's full read on the prediction branch predicted about as well (offline 67% against the estimate's 70%
with the bias, UD-Q4_K_XL code), but its 3090 time cost more than it gained where the 3090 is the later side.
12 MiB stays: 16 was 0.2-4% slower per round.

Window hashes: identical between runs with --adapt-every 0, and to the previous commit with the prefetch off
(--second-gpu-prefetch-mb 0); with it, 29 / 39 of 1200 argmaxes differ on thinking text, all near-ties (the experts
the 5070 Ti computes change).  verify_parity: the reads keeping the average and the estimate bitwise the plain ones,
both within FP64 bounds, the biased logits and the update bitwise their host emulation.

Claude-Session: https://claude.ai/code/session_01Ljcr81CGEb4dQcdiAZcXAs
2026-09-28 03:53:28 +02:00
Niko1221andClaude Opus 5.5 928b0e0721 engine 0.1.13: about 2x faster long prompts; stall reports for issue #31
Prompt path (bench/results/2026-09-28-prefill-speed):
- `--prefill auto`: chunks up to 8192 tokens, sized to the cache slots the prompt path may borrow; a
  request borrows only what its prompt needs (Prefill::relayout). setup writes it and switches old
  `--prefill 2048` configs once the engine supports it.
- The attention and MoE halves share one scratch region (~260 KB less per token).
- Experts through llama.cpp's MMQ kernels (ggml-cuda mmq.cuh, compiled from the same checkout as ggml
  into strata_mmq; Strata Q2_0 blobs converted to GGUF blocks on the gather; IQ1_M layers keep FP16).
- Chunks >= 2048: every non-resident expert streams through a ring in a fixed order across layers, so
  the next layer's arrive during its attention half (384 slots when the arena is pinned, else 96).
- The PLE block for the whole chunk at once; the next chunk's PLE rows read on a thread; unpinned
  experts copied by stager threads (epoch-tagged claims).
- STRATA_PREFILL_TIMING=1 prints a per-phase GPU timeline.
Q2_0 32K prompt 572 -> 1290 tok/s, IQ3_S 383 -> 1208 (RTX 5070 12 GB). Needles 5/5 1K-262K.

Issue #31 / #29: the serve watchdog (now 60 s) prints a stall report - each expert-pool thread's state,
the verify window's flags, layers served during the stall, memory and page faults - and on Windows
writes a minidump with every thread's stack; Release builds keep a PDB. The engine prints its version.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN
2026-09-28 02:03:00 +02:00
Eddoursul 2130de245b Second GPU: the adaptive tier's copies between windows
The second GPU's adaptive tier moved up to four experts per layer, submitted after each layer's prefetch copies.  On
that GPU's one copy engine they started behind the prefetch and ran inside the next layer's CPU pool (UD-Q4_K_XL
code: four took ~0.4 ms and ended ~0.58 ms after the next ring), where they took the pool's RAM.  Between windows (the
last layer's CPU rows to the next window's first pool: the head, the commit, the drafts) the RAM stayed idle for
~3.5 ms.

Now its copies go there.  The verify window calls a tail hook once its last CPU rows are in; the adaptive update
starts on its thread from there, and the second tier's copies go out as far as they end before the next window's
first pool: the gap's running average at the rate of the tier's own copies (timed with events, ~47 GB/s beside the
first tier's x4 copies).  The last tail before the next update sends the rest; an update drops what is still
queued (nothing in these runs).  The first tier's copies wait for the window's graph (Verifier::window_done), which
may still read its cache when the update starts.  The tier is paced whenever the second GPU's is adaptive.

Window hashes identical with --adapt-every 0 (no tiers).  Fixed text, both GPUs, 2 rounds against the previous
commit: UD-Q4_K_XL code +5.5% (the pool 19.5 -> 17.7 ms a round, 43 -> 46 GB/s; the tier's moves unchanged at 42 a
round), thinking +1.3%, after 16K +3.0%; IQ3_XXS code +1.3%, thinking 0.0%, after 16K +0.3%.

Claude-Session: https://claude.ai/code/session_01Ljcr81CGEb4dQcdiAZcXAs
2026-09-28 00:05:35 +02:00
Niko1221andClaude Opus 5.5 06438fd6c0 engine: fix a race in the CPU expert pool, and never hang silently again (issue #29, engine 0.1.12)
On a card with most experts in VRAM (RTX 4090) generation could stop for
good after thousands of tokens: the GPU "100%" at low power, one CPU core
busy, no tokens, no error.

- The pool's workers sleep after 20 ms without work (issue #4). With most
  experts resident many layers have no CPU work, so they also slept
  mid-request, and a worker that woke late was still counted as parked: it
  could claim from the next batch while the host was writing it, run a job
  twice, or add to `done` after the reset - and `done != n` then never
  ended while the GPU waited on the pool. Every claim now carries its
  batch: `head` is one 64-bit word (epoch | njobs | index), a claim is a
  CAS that only succeeds for the epoch the worker woke for, and the host
  waits with `<` instead of `!=`. Same speed (pool_test 47.2 GB/s).
- Every pool wait is bounded (60 s: a message and the engine stops), and
  --serve runs a watchdog: a request with no progress (tokens, prompt
  chunks, verify windows) for STRATA_WATCHDOG_S (120) seconds ends the
  engine with where it was stuck (strata/core/progress.hpp). The server
  (issue #27) answers with an error, names the cause from the log, and
  starts the engine again on the next request.
- pool_stress: tiny batches with sleeping workers; STRATA_POOL_SPIN_US
  shortens the spin to make them sleep constantly.

Tested: pool_test, pool_stress; 25,000-token generation at 262K with KV
streaming and constantly sleeping workers (73.9 tok/s, unchanged); the
watchdog deliberately tripped (2 s): error, log line, restart, next answer.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN
2026-09-27 20:53:38 +02:00
Eddoursul 3d133bae68 Hyper-connection read: the down projection split by input slices, the norm folded in
The down projection (w_down's 320 rows and w_inject's 4 over the 10240 inputs) ran as 41 blocks that each read
every token's whole normalized input through the L2, after a separate norm kernel.  Now 80 blocks of 288 threads
each take a quarter of the 324 rows over a twentieth of the input (a slice lies in one stream): a block stages
its slice of R' * w_norm (R' = R plus the pending write) and the slice's sums of squares, a warp takes 9 rows so
each input chunk serves 9 rows, and the last block of each quarter (a counter in the scratch) adds the 20
partials in slice order, per stream times the stream's 1/rms, then silu.  The up projection is unchanged.  A
window above 4 tokens runs the down projection in launches of 4; every token's arithmetic is the same whatever its
place in the window and the window's size.  The scratch is fused_gr_scratch_bytes(), zeroed once (the arenas,
session_zero); the single-token path uses the same kernels.

In graphs, 1 / 4 tokens: norm + down 16.8 / 26.2 -> 12.2 / 15.1 us, the whole read 26.9 / 40.1 -> 22.7 / 29.2 us
(scratch/hc2_bench.cu); in the window 25-42 us a read, from 34-54.  Fixed text, 2 rounds against the previous
commit: IQ3_XXS code +1.1%, thinking +4.9%, after 16K +3.5%; UD-Q4_K_XL +2.5%, +0.5%, +1.7% (where the CPU is the
later side, part of the gain goes to the 5070 Ti's prefetch copies overlapping the pool).

Not bitwise.  verify_parity: each token bitwise its 1-token read, and within 1e-4 of the terms' magnitudes of an
FP64 reference.  Along llama.cpp's greedy texts (bench/parity.py): argmax agreement 99.3 / 97.8 / 98.3% on IQ3_XXS
code / thinking / after 16K (before 99.7 / 97.8 / 98.7) and 99.3 / 96.0 / 98.7% on UD-Q4_K_XL (99.6 / 95.3 / 98.3);
against a build whose hyper-connection read runs in FP64 the new and old kernels are equally close.

Claude-Session: https://claude.ai/code/session_01CSrATbDcrJX2zdNDvTYaSr
2026-09-27 18:28:37 +02:00
Niko1221andClaude Opus 5.5 9e599c076e Experimental speed projection: an optional control vector (EXPERIMENTAL, off by default)
The engine takes llama.cpp's control-vector flags (--control-vector-scaled
FILE:SCALE, --control-vector-layer-range A B, --cvec-mode add|project,
--cvec-dir per-layer|single:L) and applies the vector after each steered
layer's FFN write on every hyper-connection stream: project h -= s (h.v) v,
or add h += d - where the experimental-speed-projection package's patched
llama.cpp applies it (build_cvec after the layer's second combine).

- strata/kernels/cvec: one kernel per (stream, token); with a pending fused
  write it applies it first with the fused read's own arithmetic, so a
  loaded-but-off vector is bitwise the stock engine. cvec_parity tests it.
- Per request: cvec=0|1 on the GEN/GENI line, the API field
  "experimental_speed_projection", a switch in the web app's Sampling
  drawer; a switch drops the conversation cache once. About and the
  Monitor say which way each request ran.
- setup asks (default off; --experimental-speed-projection on|off|GGUF),
  original Qwen3.8-Flash-Next only. The vector ships in
  data/experimental-speed-projection with a README that says what it is:
  its package describes it as a refusal-direction projection.

Measured (bench/results/2026-09-27-esp): off = stock token for token; on
costs 0.2-0.4% per token; mean KL 0.063 on 2,557 teacher-forced tokens.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN
2026-09-27 16:47:45 +02:00
Eddoursul 1d492512a5 generate: --window-logits, the verify windows' top 64 tokens per emitted position
Each emitted token's line holds its index among the generated tokens, the token, and the 64 likeliest
tokens with their log-probabilities from the head's logits: Strata's next-token distributions for a
position-by-position comparison with llama.cpp (bench/parity.py in the Strata folder).  The logits are
copied after the window's graph; the window hashes are unchanged.

Claude-Session: https://claude.ai/code/session_01CSrATbDcrJX2zdNDvTYaSr
2026-09-27 14:23:38 +02:00
f81df95a63 Merge PR #21: Q4_0 KV with Hadamard rotation (--kv q4_0), integrated with KV streaming; accurate expert-cache note (#23)
PR #21 (code-martin): a 4-bit K/V format (orthonormal FWHT-256 rotation of K, V and Q, then q4_0 blocks). On merge:
- Q4 is a full third format of the KV-streaming code (host copy, block residency, prompt-path staging, MTP ring,
  STATE_HASH): with --kv-resident the PR wrote K/V through the residency map's -1 entries. kv_stream_parity now
  checks Q4 streamed vs resident, bitwise.
- The per-token path ran attention twice (once before the blocks were resident); once now.
- The q4 group maximum breaks |x| ties the same way in every lane (one scale per block).
- Dropped: the duplicate path fixes (in 0.1.7), personal .gitignore entries, the re-encoded CMakeLists.
- Measured (bench/results/2026-09-27-kv-q4): int8 matches fp16; q4_0 costs precision on long documents
  (perplexity +8-12%), needles 5/5, +3.7% decode at 128K. Opt-in: setup asks above 8K context (int8 recommended),
  START-HERE.bat --kv q4_0, or --kv q4_0 in the config.

#23: the start-up warning "the GPU hit path is NOT CORRECT" dated from a long-fixed fault. Measured teacher-forced
on 2,557 tokens (bench/results/2026-09-27-cache-parity): cache on vs off, 95-98% same top-1 and equal perplexity
(-0.005 +- 0.005 nats); the warning is now one accurate line.

Co-Authored-By: code-martin <code-martin@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN
2026-09-27 11:36:28 +02:00
code-martin be6d09bc42 feat(kv): add Q4_0 KV cache mode with FWHT-256 Walsh-Hadamard rotation
- Implement Q4_0 KV quantization and dequantization kernels with scale/offset
- Implement fast Walsh-Hadamard transform (FWHT-256) rotation for outlier suppression
- Add Q4_0 attention decode support in qsa_decode_attn
- Add kv_q4_parity parity test verifying CPU vs CUDA numerical accuracy
- Support --kv q4_0 in generate CLI and runtime layer allocation
- Update .gitignore for build and repository hygiene
2026-09-27 11:29:08 +03:00
Niko1221andClaude Opus 5.5 a9047fdb79 Prompt lookup that pays, sampling fixes, shallow-path setup fix (engine 0.1.7)
- Prompt lookup on by default: the suffix drafter's windows are taken only where a learned policy (measured
  acceptance per match length, measured window cost) expects more tokens per ms than the MTP window; lookup windows
  up to --spec + 2. Code edits +6-11%, other text unchanged, verified output identical. --suffix-draft 0 = off.
- Per-request sampling (#19) keeps greedy requests on the in-graph sampler (no extra launch per window), and draws
  row t of a window with Philox(seed, pos0 + t), so a seed replays the same text whatever the drafts were.
- tools: a shallow install (G:\Strata) no longer crashes the MTP packer and the pack tools (IndexError, #20).
- setup: says at step 1 when the PC has less RAM than the smallest model needs; requires engine 0.1.7.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN
2026-09-27 10:18:14 +02:00
Niko1221 6f7e37dbfb Merge branch 'pr-19' into integrate-017 2026-09-27 09:58:30 +02:00
Niko1221andClaude Opus 5.5 e02643e47d KV streaming for the QSA layers (engine 0.1.5)
From 64K context the KV cache lives in pinned RAM and a VRAM block cache holds the part the sparse attention reads
(--kv-resident N; setup turns it on with 32768 when RAM allows). Blocks the indexer selects are made resident on
the device inside the captured graphs (clock eviction, zero-copy reads of misses); writers write through, so the
attention reads exactly the same values. The freed VRAM goes to the expert cache: Q2_0 at 262K decodes 62.6 tok/s
instead of 50.9. The MTP drafter keeps its window in a ring. New ctest kv_stream_parity. Also wires the opt-in
suffix drafter (--suffix-draft) into the engine.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN
2026-09-27 08:29:03 +02:00
Jakub Luwierski 2072ac0917 generate: min_p and the penalties ride the GEN line
The sampled chain's last two gaps close: `min_p` and the llama.cpp
penalty set (repeat/freq/present over a history window) are live end
to end - GEN keys, per-request params, and the token history the
penalties count over.

- GEN accepts min_p=F penalty_last_n=N penalty_repeat=F penalty_freq=F
  penalty_present=F between max_new and the ids (the server's
  spelling); the engine clamps defensively (min_p to 0..1, a negative
  last_n to 0) and skips what it does not know, as before.
- min_p cuts the top_k survivors to the prefix with p >= min_p * p_max
  - in logits, sel_logit >= sel_logit[0] + logf(min_p) - before top_p,
  so the two cuts compose; 0 disables, and the head always survives,
  so the kept count never reaches zero.
- the penalties need the token history: the serve loop uploads the
  last penalty_last_n tokens - the consumed tail plus the fed-back
  head, which joins consumed_seq only after the window commits - into
  one device row before every window.  A request without penalties
  hands the sampler a null row and takes the byte-for-byte neutral
  path (no upload, nothing handed over).

Verified: sampler_parity grows a full-chain host reference (the Philox
draw transcribed host-side) and fixtures for the sampled chain with
penalties and for min_p at 0/0.5/0.9 - the kernel matches the
reference on all of them, and each fixture first asserts it can SEE
the feature before asserting the kernel matches.  On the IQ3_XXS
artifact, same seed: a request with neutral penalty keys is
token-identical to one without them; a six-copy prompt that loops
24/24 on one token clean produces 24 distinct tokens with repeat 1.5
+ present 0.5; min_p 0.9 changes the pick.
2026-09-27 07:55:19 +02:00
Jakub Luwierski 8586f94b1c verify: a persistent per-request draw counter; sampled requests default top_k=20
The sampled path requires top_k in 1..64 (the selection loop is
O(k*n_vocab) by design); with the engine-default top_k=0 it returned
without writing the token, leaking stale buffer contents as output.
Sampled requests now default to the sampler's own top_k=20.

The Philox draw counter also must persist across a request's verify
windows - it was read from a run-local variable that reset every
window, so every window redrew the same numbers (identical sampled
output on identical requests).
2026-09-27 07:31:54 +02:00
Eddoursul b063c13be2 Verify window: more of the layer on short branches
The GDN gate projection runs on the shared expert's stream beside qkv and the conv (an i-quant gate matrix is
compute-bound where qkv streams), the QSA queries' chain (projection, split, norm and rope) beside the keys and
values, and the routed experts' activations beside the router kernel; each joins before its first reader. The
branches' fork/mark/wait are three small helpers.

Fixed text against the previous commit, 2 alternating rounds: IQ3_XXS code +0.9%, thinking +0.9%; UD-Q4_K_XL
thinking +2.4%, code unchanged. Window hashes identical (both models, thinking and code; --spec-split,
--pcie-frac 0.3, --second-gpu -1).

Claude-Session: https://claude.ai/code/session_01YDx8gSYSbts2783qXv2Nxz
2026-09-27 01:01:18 +02:00
Eddoursul 34a35dbac1 Verify window: the GDN gates and the QSA indexer beside the mixer's projections
The GDN alpha/beta kernel (a few blocks, latency-bound) and the QSA indexer's chain (its key projection and append,
the query projection, norm and rope, the block scores and top-k) only need the mixer's input; they now run on a
branch of the graph beside the projections and join before the recurrence and the attention. Per layer, IQ3_XXS
(--window-profile): GDN mixer 85.6 -> 76.5 us on thinking text, 100.6 -> 85.9 on code; QSA 151.4 -> 132.9 and
163.3 -> 142.9.

Fixed text against the previous commit, 2 alternating rounds: IQ3_XXS code +2.1%, thinking +3.2%; UD-Q4_K_XL code
+1.6%, thinking +0.9%. Same kernels on another stream: window hashes identical (both models, thinking and code;
--spec-split, --pcie-frac 0.3, --second-gpu -1).

Claude-Session: https://claude.ai/code/session_01YDx8gSYSbts2783qXv2Nxz
2026-09-27 00:28:54 +02:00
Eddoursul 81e276d211 Verify window: the router, the doorbell and the hit plan in one kernel
verify_router takes a layer's router logits (bf16_gemv_fp32_mmvf_multi's block, its arithmetic now shared through
mmvf_multi.cuh), the first blocks also copying the input rows to mapped memory in 16-byte stores; the last block to
finish routes the tokens (native_router_top10's code, route_token), publishes the ids and weights, writes the ring's
number (known at capture: no read of the mapped counter) and plans the main GPU's hits (hit_plan_block, shared with
verify_hit_plan). It replaces four kernels on the main stream and three on the prediction branch. 21.0 -> 16.3 us at
1 token, 31.5 -> 21.7 at 4; verify_parity checks it bitwise against the four.

--window-profile: the router, ring and hit plan are one stage ("router, ring, hits"), followed by the experts'
activations ("expert inputs").

With the up-projection change, fixed text against the previous commit, 2 alternating rounds: IQ3_XXS code +1.6%,
thinking +2.1%; UD-Q4_K_XL thinking +1.6%, code unchanged. Window hashes identical to the build before the
interleaved projections (both models, thinking and code; --spec-split, --pcie-frac 0.3 kernel and direct,
--second-gpu -1).

Claude-Session: https://claude.ai/code/session_01YDx8gSYSbts2783qXv2Nxz
2026-09-26 23:51:36 +02:00
Eddoursul 738e16602d Verify window: the dense projections of 2+ tokens read an interleaved copy of their activations
The quantizer also writes the tokens' q8_1 values interleaved (a position of every token in one 16-byte word,
block-major for the K-quants and Q8_0, position-major for IQ4_XS and IQ3_S). A warp then takes 2-4 rows, decodes
each weight block once and applies it to every token with the single-token dot's arithmetic, walking the chunks of
the exact layout's four warps with a sum per warp (IQ3_S: row_dot's one sum) added in the same order before the
xor tree, so every value is bitwise the multi-column kernel's. Matrices of fewer than 2048 rows and single tokens
keep the old kernels. Used for the mixer's projections and the head.

Per call, 4 tokens (mmvq_il_parity --bench): IQ4_XS 2560x10240 40.7 -> 29.3 us, Q6_K 68.7 -> 47.4, Q8_0 60.9 ->
43.1, IQ3_S 2560x6144 48.8 -> 21.3; 2 tokens 10-35% faster. Fixed text, 2 alternating rounds: IQ3_XXS code +3.8%,
thinking +2.1%; UD-Q4_K_XL within noise. Window hashes identical to the previous build (both models, thinking and
code; --spec-split, --pcie-frac 0.3, --second-gpu -1).

Claude-Session: https://claude.ai/code/session_01YDx8gSYSbts2783qXv2Nxz
2026-09-26 23:16:12 +02:00
Eddoursul a3f14e4c1a --window-profile: the wait for the CPU's rows as a histogram
The average wait hides which side a layer waits on: the histogram shows the layers whose rows were in when the GPU
got there (the flag's poll alone takes 5-8 us). On IQ3_XXS thinking text that is 74% of the layers; on code, and
with UD-Q4_K_XL, the CPU side is the later one in most.

Claude-Session: https://claude.ai/code/session_01YDx8gSYSbts2783qXv2Nxz
2026-09-26 20:13:29 +02:00
Eddoursul 3f3c26deb1 Verify window: the 3090 decides its cache hits in the graph, the shared expert beside them
The window copies a snapshot of the residency table (Verifier::residency, which the pool reads too) and plans the
main GPU's hits on the device (verify_hit_plan), so its cached experts start right after the doorbell instead of
waiting for the host's plan; the host plan now carries only the PCIe share, and the combine takes both lists. The
shared expert runs on a graph branch of its own, forked at the doorbell and joined before the combine, and no
longer converts the activations to BF16 when the native gate reads them in FP32. Window hashes unchanged on both
models (also with a PCIe share, --spec-split and --second-gpu -1); verify_parity checks the plan against the
host's grouping and the combine with two lists.

Fixed text, both GPUs: IQ3_XXS code 105.4 -> 108.9 t/s, thinking 89.1 -> 93.2; UD-Q4_K_XL code 86.9 -> 88.0,
thinking 74.7 -> 77.5.

Claude-Session: https://claude.ai/code/session_01YDx8gSYSbts2783qXv2Nxz
2026-09-26 19:34:35 +02:00
Eddoursul 92d1abb6c2 Verify window: the PLE flag is raised even when a row read fails
The graph waits for it before layer 1; returning on a read error without it left the graph spinning.

Claude-Session: https://claude.ai/code/session_01YDx8gSYSbts2783qXv2Nxz
2026-09-26 16:58:24 +02:00
Eddoursul 8d8af3bfe8 --window-hashes reads the final rows from mapped memory the graph writes
The hash's per-window cudaMemcpy of the final residual rows queued behind the adaptive tier's expert copies
on the copy engine and slowed generation (UD-Q4_K_XL code 89 -> 77 t/s with the tier on).  With
--window-hashes the verify graph now copies them into mapped host memory with a kernel after the head.  Same
bytes hashed (identical files to the previous build); UD-Q4_K_XL code with hashes 88.3 t/s.

Claude-Session: https://claude.ai/code/session_01YDx8gSYSbts2783qXv2Nxz
2026-09-26 16:45:47 +02:00
Eddoursul 21ec11f84e PLE rows of a verify window read while layer 0 runs, the drafts' while the draft layer runs
The verify window's staging waited 0.4-0.7 ms a round for the SSD reads of its tokens' PLE rows.  The graph
now waits for them (a host flag) before layer 1, the first to read them: the host starts the reads before the
launch and collects them while layer 0 runs.  The next window's first token, and each draft likely to be
verified (probability >= --spec-min-p), start their reads as soon as they are known (Verifier::ple_ahead,
MtpDrafter::on_draft), in read-ahead slots of the PLE table beside its single-token issue/collect.

Window hashes unchanged (fixed text, --adapt-every 0, both models).  Host time per round 0.41-0.71 ->
0.03-0.19 ms; generation IQ3_XXS code +2.5%, thinking +1.5%; UD-Q4_K_XL code +1.3-1.6%, thinking +1.1%.

Claude-Session: https://claude.ai/code/session_01YDx8gSYSbts2783qXv2Nxz
2026-09-26 16:42:27 +02:00
Eddoursul 8b783bbfa5 Prefetch: a prediction that comes after the CPU's rows is waited for (microseconds: its branch is joined before the next layer) instead of skipped, so which experts the 5070 Ti takes, and the output, no longer depend on timing (with --adapt-every 0 two engine processes produce the same tokens); IQ3_XXS +1.3%, UD-Q4_K_XL thinking +0.5%, code unchanged; --stats counts the waits
Claude-Session: https://claude.ai/code/session_01YDx8gSYSbts2783qXv2Nxz
2026-09-26 14:16:11 +02:00
Eddoursul 282334701a Verify window: the commit graph runs beside the MTP draft (it was launched and waited for alone, 0.67 ms a round); UD-Q4_K_XL code +0.9% 2026-09-26 06:54:27 +02:00
Eddoursul f4ee9b58cb Second GPU: the next layer's likeliest experts copied to it while the RAM is idle (--second-gpu-prefetch 4), its rows out in full PCIe transactions, the second tier's moves paced behind the prefetch
Each layer's router also runs on the previous layer's FFN input on a side branch of the verify window's graph; once
the CPU's rows of a layer are in, the host copies the next layer's likeliest experts that no GPU holds into prefetch
slots on the second GPU (~0.3 ms of idle RAM per layer), and that layer's share takes them from there. The second
GPU's down kernel wrote its rows one float at a time into mapped host memory: 0.25 ms a layer, and the CPU pool read
RAM at 38 instead of 48 GB/s. UD-Q4_K_XL code, fixed text: 71.6 -> 77.4 t/s (rows) -> 86.1 (prefetch 4); thinking
70.2 -> 73.6.
2026-09-26 06:16:00 +02:00
Eddoursul af76f64ebd QSA: block scores sized to the blocks in use; the prompt path's attention in one pass per query
qsa_block_scores launched a warp for every block of the full context
(max_cells / 4, 50K blocks at 200K) for every query, nearly all of them
idle.  Its warps now go round over the blocks: the verify window and the
token path use a fixed grid of 1024 per query, the prompt path the chunk's
largest n_bid + 1.  Each score is computed as before (bitwise).

qsa_prefill_attn: the prompt path's attention, a block per (KV head, query)
walking the query's selected cells in tiles of 64 with an online softmax,
instead of the decode kernel's split-K partial sums through memory.  FP32;
int8 codes are converted without I2F.  verify_parity checks it against the
decode kernel (relative difference 3.9e-6).

16K-token prompt: IQ3_XXS 18.3 -> 15.9 s, UD-Q4_K_XL 24.8 -> 22.4 s.
2026-09-26 00:56:06 +02:00
Eddoursul 939add21bb Verify window: the QSA layer's per-token kernels batched; --window-hashes
RoPE (native_rope_apply_tokens), the int8 K/V append (kv_append_q8_steps),
the indexer append (native_qsa_indexer_append_multi), the q/gate split, the
q/k norms and the gate now run once per window instead of once per token.
Each token's arithmetic is unchanged: verify_parity checks the new kernels
bitwise against the per-token ones, and --window-hashes writes a hash of
each window's final residual rows so two builds can be compared end to end.
2026-09-25 23:32:43 +02:00
Eddoursul 22f4b8c705 Verify window: multi-token router, indexer projections and shared-expert gate (one weight read, one launch) 2026-09-25 22:29:52 +02:00