qsa_prefill_attn runs INT8 pools through int8 mma (m16n8k32): a block per (KV head, query), its 12 query heads the
rows of the fragments, 64 cells a tile. q and the probabilities go in as 24-bit fixed point, three 8-bit limbs each
(q against its row's power-of-two bound, a probability times its V scale against the tile's), so the integer sums
are exact; converting the limbs back takes magic-number adds and FMAs, not I2F. The block is warp-specialized:
4 warps score 16 cells each over all 256 dims (q's limbs in registers) and run the online softmax, 4 multiply a
64-dim group of V each (V through ldmatrix.trans, cells and dims permuted inside the fragments), 4 fetch K, V and
their scales by cp.async into rings of 2 and 3 slots, the pool rows two tiles ahead; named barriers between them.
FP16 pools keep the FP32 kernel.
On a 131K-token prompt's selections (one layer, 2048 queries, cells spread over 131K): 2.5e-6 of a head's largest
output from FP64 at worst, 2.6e-7 on average (the FP32 kernel 3.1e-6 and 4.6e-7); 16-bit fixed point for q or the
probabilities would be ~5e-4. 10.8 -> 3.5 ms a call (4.5 ms with the clocks settled; gathering the cells alone
takes 2.0 ms, the L2's limit). --prefill-profile, IQ3_XXS: QSA attention 16K 0.95 -> 0.39 s, 131K 8.6 -> 3.4 s.
Prompt time, both GPUs: 16K 8.96 -> 8.34 s (1832 -> 1970 tok/s), 131K 69.5 -> 64.1 s (1886 -> 2044 tok/s).
Not bitwise: 300 tokens of fixed text after the 16K prompt give 4 (IQ3_XXS) and 2 (UD-Q4_K_XL) different argmaxes,
all near-ties by llama.cpp's probabilities (0.39/0.36, 0.27/0.20, 0.32/0.43, 0.42/0.41; 0.36/0.52, 0.32/0.57),
llama.cpp siding with the old build at 3 and the new at 3. verify_parity: within 2.4e-6 of the decode kernel.
Claude-Session: https://claude.ai/code/session_01YDx8gSYSbts2783qXv2Nxz
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
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
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
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
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
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
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
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
The MTP draft layer read a prompt 4 cells per captured graph with a host sync after each (0.74 s of a
16K-token prompt, 1.5 s from 32K on). The prompt path now computes them after every chunk in its own
arithmetic, as for the model's layers: the input norms, fc_embedding and fc_hidden, the attention
hyper-connection read, K (normed, rotated) and V as GEMMs over 2048-token sub-chunks in the chunk's
buffers, from the window's first cell on (41 ms of GPU time for 16K tokens). embed_rows embeds token ids
from device memory in one launch (the draft layer's gather, shared).
With the previous commit: a 16K-token prompt 9.51 -> 8.90 s (IQ3_XXS) and 10.24 -> 9.39 s (UD-Q4_K_XL),
65K 38.7 -> 34.0 s. Drafts accepted on the fixed text after 16K: 0.703 -> 0.704 (IQ3_XXS), 0.725 -> 0.718
(UD-Q4_K_XL); the tokens after a 65K-token prompt are unchanged (--adapt-every 0).
Claude-Session: https://claude.ai/code/session_01YDx8gSYSbts2783qXv2Nxz
The block scores ran one warp per (query, block) and read the pooled keys once per query; the top-k ran one
256-thread block per query whose passes each re-read the scores, with shared atomics on a few hot bins and thread
0's serial scans. Now 8-lane groups score two key blocks each for every query (the queries and their step
values in shared memory), summing each score in the tree the warp butterfly used, so the scores are bit for bit
the same; the top-k holds the keys in registers (1024 threads, rows of 1024 blocks, 131K cells), counts in
per-warp histograms, and places the cells from ballots and one scan of the (row, warp) totals.
qsa_select_parity keeps the replaced kernels and checks the scores bitwise and the selections (71 cases,
decode windows and prompt batches, 0 to 200K cells, ties, zero scores, every tail length). IQ3_XXS with
--adapt-every 0: window hashes and tokens identical to the previous build after 65K and 131K-token prompts;
a 131K-token prompt 90.5 -> 70.6 s, generation at 131K 79.2 -> 85.1 t/s; 65K 38.3 -> 35.3 s, 87.6 -> 90.2 t/s.
Claude-Session: https://claude.ai/code/session_01YDx8gSYSbts2783qXv2Nxz
Where both sides did the same thing, ours stays:
- split models: shards found by name and the experts filled by tensor name, not upstream's native_experts.txt
shard column and model_shards(); iq_pack.py keeps ours and exports the model's chat template with its tokenizer
- the PLE table's span check
- README: upstream's front page (with the prompt cache under "Good to know"); the unsloth files, the second GPU
and the prompt cache moved to docs/DETAILS.md
Upstream's engine changes in our code:
- STOP between the prompt path's chunks and before every verify window of the serve loop; a prompt stopped
part-way leaves the prompt cache's live sequence at the chunks read (Prefill::processed(), ss.ple_prev
advanced to them)
- the expert cache sized once its slots are written, on the main GPU and on the second GPU (its tier drops empty
slots while short of --second-gpu-reserve-mib)
- the prompt chunk halves until its buffers fit in the lendable cache slots (the shared prompt-path setup)
- server.py: the engine reader thread with heartbeats and STOP, with our cached-token usage fields and the
engine generator closed inside the FIFO; a disconnect logs as cancel
- STRATA_TRACE and STRATA_POOL_TRACE, and the VRAM left once everything is loaded (both GPUs)
Claude-Session: https://claude.ai/code/session_01YDx8gSYSbts2783qXv2Nxz
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.
A prompt chunk uses nearly every expert, and the 3090 streamed all it did
not hold over its PCIe 4.0 x4 link. With --second-gpu the prompt path now
hands them to the second GPU (x16): per layer the 3090 copies the chunk's
MoE input (FP16) to pinned host memory while its router and shared expert
run; the second GPU computes its experts from its own cache or streamed
from the pinned arena, and returns each token's weighted sum (FP32), which
the 3090's combine adds to its cached experts' rows (prefill/offload.cpp).
Experts go through in batches of consecutive ids (up to 16 experts and 4096
rows): one staging copy per run of adjacent arena blobs, one dequant launch
(iq_dequant_experts_f16), one gather, per-expert GEMMs (cuBLAS does not group
FP16 -> FP32), one SwiGLU and one ordered per-token add (moe_gather_add,
the same sums as one moe_scatter_add per expert). --no-prompt-offload
streams them to the main GPU as before.
16K-token prompt, UD-Q4_K_XL: 21.6 -> 11.9 s.
The conv + L2 norm walked the chunk one token at a time per channel (320
warps); the prompt path now uses the verify window's gdn_conv_l2_multi over
all T tokens plus a small history update. The recurrence keeps the decode
kernels' arithmetic (four 32-row partial sums per column, added in order)
but puts a column's row groups in adjacent lanes, so the sums are shuffles;
each thread holds two columns, a head is split over four blocks, and each
token's inputs arrive through a cp.async ring 7 tokens ahead: one barrier per
token. The output norm is a separate pass. verify_parity checks the prompt
path's GDN bitwise against the verify window's kernels (1-37 tokens).
16K-token prompt: recurrence 1.36 -> 0.46 s; IQ3_XXS 15.9 -> 15.2 s,
UD-Q4_K_XL 22.4 -> 21.7 s.
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.
The PLE block ran once per prompt token (a 52 MB key GEMV each); its key and
value projections are now GEMMs over the chunk, followed by the decode path's
per-token arithmetic in one pass (native_ple_postops_tokens, bitwise n_tok
native_ple_postops + ple_history_advance calls; verify_parity checks it).
The indexer appends of a chunk are one native_qsa_indexer_append_multi launch.
16K-token prompt, IQ3_XXS: 22.8 -> 18.3 s.
--prefill-profile prints the GPU time of each section of the prompt path;
--window-hashes lines carry the window's first position.
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.
The GPU that holds the expert cache is one per-layer bottleneck and the
CPU pool, which computes the missed experts, the other. With --second-gpu
N, device N holds more experts (the profile's pairs the first cache lacks,
then empty slots its own adaptive tier fills with the conversation's) and
computes its share of each verify-window layer while the CPU pool computes
the rest. It never spins on host memory: per layer the host launches one
captured graph (the plan copied in by a kernel, the activations read from
mapped memory, the grouped expert kernels of the first GPU's hit path, the
rows written to mapped memory) before the pool and collects the rows after
it, so a GPU that also drives the display keeps its latency. A layer whose
misses are below --second-gpu-min-mb (4) stays on the CPU, which is then
quicker than the ~100 us round trip.
UD-Q4_K_XL, RTX 3090 + RTX 5070 Ti (12.6 GiB of experts): generation +9%
on a 3000-token thinking answer, +14-19% on code; IQ3_XXS, whose rounds
wait on the first GPU, gains nothing.
The expert arena is now one cudaHostAlloc block per layer instead of a
registered reservation. With a second CUDA context in the process,
Windows pins at most ~42 GiB through cudaHostRegister, and past that every
CUDA allocation fails; allocated blocks reach ~75 GiB with one GPU or two.
The layers past the budget share one locked, pageable range as before.
Streaming
- tool calls stream as they are written (OpenAI tool_calls deltas, Anthropic input_json_delta)
- keep-alives while a long prompt is read, progress in the server window, GET /status
- closing the connection or pressing stop really stops the engine (STOP)
Stalled requests (mostly image turns)
- the expert cache is sized after its slots are written (Windows only counts GPU memory once it is
touched), so the reserve really stays free instead of the card running at 0 MiB and paging
- the prompt chunk shrinks when its buffers do not fit in the cache, instead of allocating on top
- the image encoder warms up before the engine starts; images are encoded in request order
- the log shows the VRAM left once everything is loaded
setup.py now requires engine 0.1.2 (downloaded automatically on the next START-HERE.bat).
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN
- The serve loop and the speculative loop each carried the same adaptive
expert tier (ranking, refill copies, admission once landed); it is now
strata::core::AdaptiveTier.
- --stats prints the share of the routed entries the N most-routed experts
of the run take, which sizes what a larger expert cache could serve.
The draft head copies rows of the model's output head, and the copy took
rows in 16-byte units only. Q6_K rows of 2,560 values are 2,100 bytes, so
MTP exited at startup with the Q6_K heads of unsloth's UD-IQ3_XXS, UD-IQ4_XS
and UD-Q3_K_XL. Rows that are a multiple of 4 bytes are now copied in
4-byte units.
- MSVC: _CRT_SECURE_NO_WARNINGS (fopen, sscanf and getenv are standard C),
/wd4211 for the host stubs nvcc generates for kernels with internal
linkage, and C4324 off around ExpertPool, whose alignas padding is the
point.
- Unused locals, device functions, a kernel and a constant removed;
shadowed locals renamed; the router clamp bound is an if constexpr.
- qsa_layer's prologue, a single 917-character line, split into lines.
The engine now runs unsloth's Qwen3.8-Flash-Next quants (UD-IQ1_S up to
UD-Q6_K_XL and Q8_0) as native packs, besides the ISTA-DASLab files.
- Split models: --native takes the first shard and finds the others by
name (gguf_split_paths, GgufModel). The expert arena is filled from the
shards by tensor name and checked against native_experts.txt, whose
lines no longer carry shard-1 offsets. The native head and embedding are
found in any shard, and --ple-gguf defaults to the shard that holds
per_layer_token_embd.
- GPU kernels: expert dot products and dequantizers for Q4_K, Q5_K, Q6_K,
Q5_1, Q8_0, IQ1_S and IQ4_XS (llama.cpp's), one dispatch list for all
formats, and a startup check that every layer's formats have kernels.
The Q5_1 min and IQ1_S delta terms use the quantized activation sums, as
ggml-cpu does: 1.1% instead of 1.9% relative error per expert.
- PLE: the table may be IQ4_NL or Q8_0 and may share its shard with other
tensors; the native PLE key may be any native MMVQ type (Q8_0 here).
- tools/iq_pack.py: all shards of a split model, and every float tensor in
the form the engine takes. The files' F32 router, SSM gate and injection
tensors hold BF16 values (exact); their Q8_0 hyper-connection and PLE
value weights are re-rounded to BF16.
- native_expert_parity: split models, a --synthetic mode for formats with
no model file at hand, and a check of the GPU dequantizers.
- README: the unsloth files, their RAM needs and how to pack them.
UD-Q4_K_XL on an RTX 3090 (160 GB RAM): prompts 529-594 tok/s, generation
49-57 tok/s. Greedy tokens equal llama.cpp's argmax on the same GGUF at
98.2% (code) and 95.6% (thinking) of positions.
A request continues from the longest prefix of its prompt the engine still
holds: the live sequence, checkpoints of the fixed-size sequence state (GDN
recurrence and conv history, QSA indexer tail, PLE history) in host memory,
or a conversation another request replaced, stashed in RAM with its K/V
cells. Checkpoints are taken before a prompt's last <|im_start|>, at the
prompt's end and every --cache-every cells of a long prompt.
Short prompt remainders go through verify windows instead of the batched
prompt path. The decode loop no longer verifies past the output limit or a
drafted end-of-turn token, so the live state ends where the emitted text does.
The server reports reused tokens (OpenAI prompt_tokens_details.cached_tokens,
Anthropic cache_read_input_tokens) and drains the engine to DONE inside the
request lock.
New engine options: --prompt-cache N, --cache-ram MIB, --cache-every N,
--feed-max N.
The setup now asks which model first: Qwen3.8-Flash-Next (the original) or Swift 1.5. The engine reads models
whose GGUF shards split the layers; the ready-made engine v0.1.1 is on the Releases page.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN
Inference engine, OpenAI/Anthropic API on localhost, optional image input, one-file setup
(START-HERE.bat / setup.sh). Model files are downloaded from Hugging Face by the setup.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0154bwiad8gY7wRehCXy27pN