mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #415] [CLOSED] IQ4_XS expert rows on the AVX-2 path: the multi-token kernel this format never had #2629
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#2629
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/415
Author: @pipeob0
Created: 10/1/2026
Status: ❌ Closed
Base:
main← Head:gh/avx2-iq4xs-0132📝 Commits (1)
094c2d7IQ4_XS expert rows on the AVX-2 path: the multi-token kernel this format never had📊 Changes
4 files changed (+35 additions, -7 deletions)
View changed files
📝
include/strata/kernels/cpu/iq_avx2.hpp(+1 -1)📝
src/kernels/cpu/iq_avx2.cpp(+26 -2)📝
src/kernels/cpu/native_expert.cpp(+5 -3)📝
src/kernels/native_expert_parity.cpp(+3 -1)📄 Description
What
IQ4_XS (GGML type 23) was missing from
iq256_supported, so on an AVX-2-only CPU its gate/upexpert rows fell back to ggml's per-token
vec_dotwhile every other i-quant format got themulti-token kernel that decodes the weights once per verify window. This adds
Fmt32<23>andwidens the two gates that were keeping the format out.
The machine is a Ryzen 7 5700X3D (Zen 3, AVX2, no AVX-512), Windows, engine 0.1.32 built from
source. It is the CPU class the AVX-2 path exists for, and IQ4_XS is one of the formats people
actually run on it — including the low-RAM path 0.1.31 added, which makes a 61 GiB-expert model
reachable on a 64 GB PC.
How the kernel works
Fmt32<23>reuses the 16-value codebookiq4nl_rowsalready has. Each of the eight 32-valuesub-blocks carries its own 6-bit scale — two nibbles of
scales_l[p]plus two bits ofscales_h—used signed as
(ls - 32), so the scale folds into theint16operand ofmadd_epi16insteadof becoming a float multiply per sub-block. The codebook sign is carried the way
iq4nl_rowsdoesit:
|w|as the unsignedmaddubsoperand,w's sign applied to the activation withvpsignb.The arithmetic is ggml's
ggml_vec_dot_iq4_xs_q8_K; only the order of the float additions differs.The gate is the part worth reviewing
native_expert.cppentered the multi-token path withiq512_supported(f.gu_type)alone. Wideningthat to
iq512_supported || iq256_supportedwithout also guarding each call is a correctnesstrap, not just a missed optimisation: IQ4_XS has an AVX-2 kernel and no AVX-512 one, so on an
AVX-512 CPU the widened gate would enter
iq512_gu_rows, hit aswitchwith nocase 23, fallthrough it, return, and leave
ffunwritten — garbage output rather than a fallback toggml-cpu. Each call is therefore guarded by the formats its own kernel implements.
native_expert_parity.cpphad the same gate, which is why the format was never tested on any CPU:with
iq512_supportedalone the tool skips IQ4_XS on AVX-512 machines and never reaches the AVX-2check on AVX2 ones.
Evidence
Built from this branch (92/92 targets, no errors) and run against ggml's own
vec_doton the sameQ8_K activations, real tensors from
orcarouter/Qwen3.8-Flash-Next-Uncensored-GGUF(IQ4_XS),layers 0-9:
Same order as the existing IQ3_S kernel on the same machine (median 3.10e-08, max 3.41e-08), i.e.
float-addition order only.
Negative control, so the parity gate is known to bite: changing the sub-block scale from
(ls - 32)tolsgivesThroughput, one thread, weights cache-resident (the same measurement the tool prints):
The signature is the existing one: slower for a single token, ~1.5x from two tokens up, which is
what
STRATA_IQ_MT_MIN(default 2) already encodes.End-to-end in the engine
A/B with
STRATA_NO_IQ256=1, which drops the AVX-2 multi-token path. On an IQ4_XS pack that path isexactly the gate/up rows: the
downrows are IQ4_NL and have their own switch (STRATA_NO_IQ4NL),so they stayed on in both arms. IQ4_XS over
experts.binin mmap,--kv-resident 20480,STRATA_IQ_PREFETCH=16384,--spec 4, greedy, 300 tokens per run, three warmup passes and fourinterleaved rounds with the arm order rotated per round.
Compared as total time for the run (rounds × ms/round): both arms generate ~300 tokens, and the
draft acceptance moves tokens-per-round (2.63 vs 2.68) without moving the time, which is what makes
ms/round alone misleading here.
vec_dotvec_dotarm collapsed: 127 draft rounds, 20.0 GB/s)The kernel wins 4 of 4 pairs; median −3.2%, −2.6% with the outlier round dropped. The gate/up
phase is −7.6% (median), and the sustained row-read rate is 28.6 GB/s against 25.6.
Small, and the reason is the machine: both arms sit at the DDR4-2666 wall (~28 GB/s), so this is not
an ALU win. What it buys is that a verify window walks each expert row once instead of once per
token in the window.
Caveats
iq512_supportedis unchanged, so an AVX-512 CPU keeps usingggml-cpu for this format. Adding the AVX-512 variant is a separate change.
downrows of an IQ4_XS pack are IQ4_NL (type 20) and already have their AVX-2 multi-tokenkernel; this patch only covers gate/up.
share should matter more; on one with AVX-512 this format still does not reach a multi-token
kernel at all.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.