mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2638] [CLOSED] cpu: decline IQ4_NL down rows for the AVX1 kernels; two cleanups #4181
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#4181
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/2638
Author: @nashcap
Created: 10/15/2026
Status: ❌ Closed
Base:
main← Head:avx1-on-1441📝 Commits (3)
aea3968cpu: AVX1 kernel micro-optimizations, all bit-exact (parity re-verified)3b5f018cpu: AVX1 - decline IQ4_NL down rows, two-block iq4_nl kernel, fused cvt, split bench6aa11afcpu: AVX1 kernel audit - row-pair only at NT=1, drop dead dot_rows📊 Changes
3 files changed (+226 additions, -65 deletions)
View changed files
📝
src/kernels/cpu/iq_avx1.cpp(+200 -61)📝
src/kernels/cpu/iq_avx1_parity.cpp(+16 -4)📝
src/kernels/cpu/q2_avx1.cpp(+10 -0)📄 Description
On CPUs that have AVX but not AVX2, IQ4_NL down rows should be computed by ggml's own dot, not by our 128-bit kernel. ggml is faster there, and always has been. That is the point of this PR: one line in the dispatch. Two small cleanups follow.
Why these commits exist
#1697 and #1701 landed in v0.1.42 (you ported them with my authorship). I kept working on the same files after that and pushed three more commits to the #1697 thread, and they were never ported. This PR is those three, rebased onto v0.1.44.1. The diff touches only
iq_avx1.cpp,q2_avx1.cppandiq_avx1_parity.cpp.1. IQ4_NL down rows: decline them (the fix)
The other formats this file serves have no hand-written x86 dot in ggml-cpu, which is why the 128-bit kernel wins them. IQ4_NL is the exception: ggml-cpu has a hand-written
__AVX__dot for it (ggml_vec_dot_iq4_nl_q8_0, two blocks per iteration, 256-bit float accumulation). That one beats our kernel on this CPU, and I could not close the gap - I matched its two-block shape and shared the decode across tokens, and it still came out behind.So the dispatch stops choosing our kernel for that format:
The kernel stays built and parity-tested; only the dispatch declines it.
Why it is worth a PR: on the IQ3_S pack, 24 of the 33 down layers are IQ4_NL. Today an AVX1 CPU runs the slower of the two kernels for all 24 of them.
Measured as
ms/expertwith./iq_avx1_parity --bench --mb 96 --nt 1,4 --cpu 12, two runs of one binary:The bench now prints gate/up and down separately because of this finding. The combined line had been hiding a 0.78x down path inside a 2.1x result.
2. Micro-optimizations, all bit-exact
sum(q)does not depend on the row, so it is computed once per call instead of once per row.cvtepi32instead of two for the int32 pair sums.madd) is about 20 cycles of pure latency with nothing to overlap, so the kernel runs latency-bound at roughly a quarter of its issue rate. A second row gives the scheduler something independent to do in the meantime.(NT is the number of tokens in one verify window that route to the same expert, set by the router. Live decode is almost entirely NT=1.)
Net effect: gate/up rows measure 1.18-1.41x against ggml at NT=1, and 2.0-2.8x at NT=4.
3. The two-row form only at NT=1
That pairing pays only at NT=1. At NT >= 2 the row pair plus two token accumulators does not fit in 16 XMM registers and spills: neutral-to-noisy at NT=2, and going further is actively bad - R=3 measured a wash, R=4 measured -42.6% at NT=1 on IQ3_S. So the policy is R=2 at NT=1 and R=1 otherwise.
dot_rowshad no callers left once that path existed, so it is removed.Answers do not change
Every change here is either bit-exact by construction (the fp16 identity, the shared
sum(q), the fused conversion) or a dispatch decline. Nothing touches the pack format or the converter.Verification
Xeon E5-2470 v2 (AVX, no AVX2 / FMA / F16C / AVX-512), RTX 5060 Ti 16 GB, v0.1.44.1 source build with
-DSTRATA_ISA_FLOOR=avx:A live profile of the running engine shows the dispatch doing what the code says:
row_dot_r<18,1,2>and friends at NT=1,row_dot_r<18,2,1>at NT>=2, andggml_vec_dot_iq4_nl_q8_0carrying the IQ4_NL down rows at 7.2% of samples whileiq128_down_rowssits at 2.6% - which is the 24/9 split.One honest caveat about the numbers: single-format gate/up ratios at NT=1 are noisy (iq3_xxs measured 1.19x on one run and 0.90x on the next). The down-row numbers, which are the argument of this PR, were stable across runs.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.