mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1697] [CLOSED] cpu: AVX1 128-bit expert kernels (iq_avx1) - the i-quant rows on CPUs with no AVX2 #3616
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#3616
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/1697
Author: @nashcap
Created: 10/9/2026
Status: ❌ Closed
Base:
main← Head:avx1-iq-kernels📝 Commits (6)
c7db61bcpu: AVX1 128-bit expert kernels (iq_avx1) - the i-quant rows on CPUs with no AVX20e11122cpu: iq_avx1 - IQ4_XS gate/up stays on ggml's generic dot (the 128-bit grid kernel measures 0.7-1.0x against its auto-vectorized generic on an E5-2470 v2; the kernel stays built and parity-tested, only the dispatch declines it)cd72eaecpu: q2_avx1 - the Q2_0 rows and the Q8_1 quantizer for CPUs with AVX but no AVX2 (fixes #1699)2220528cpu: AVX1 kernel micro-optimizations, all bit-exact (parity re-verified)ab034c2cpu: AVX1 - decline IQ4_NL down rows, two-block iq4_nl kernel, fused cvt, split benchc4a3634cpu: AVX1 kernel audit - row-pair only at NT=1, drop dead dot_rows📊 Changes
12 files changed (+1399 additions, -19 deletions)
View changed files
📝
CMakeLists.txt(+21 -1)📝
include/strata/kernels/cpu/expert.hpp(+8 -0)📝
include/strata/kernels/cpu/expert_layout.hpp(+3 -0)➕
include/strata/kernels/cpu/iq_avx1.hpp(+37 -0)📝
src/kernels/cpu/expert_layout.cpp(+11 -2)➕
src/kernels/cpu/iq_avx1.cpp(+650 -0)➕
src/kernels/cpu/iq_avx1_parity.cpp(+303 -0)📝
src/kernels/cpu/native_expert.cpp(+27 -0)➕
src/kernels/cpu/q2_avx1.cpp(+304 -0)📝
src/kernels/cpu/q2_bitplane_parity.cpp(+23 -11)📝
src/kernels/cpu/q8k_quant_parity.cpp(+8 -4)📝
src/program/generate.cpp(+4 -1)📄 Description
What
Completes the AVX1 floor for native packs. Since #394 an AVX-only CPU (Sandy Bridge through Ivy Bridge Xeons) starts and runs a native pack, but every i-quant dot in ggml-cpu is
#if defined(__AVX2__)and falls to the scalar_genericpath, and the fork's Q2_0 has no vectorized dot either - so the CPU-computed experts of a native pack run scalar there. This adds the missing sibling ofkq_avx1.cppfor the expert rows:src/kernels/cpu/iq_avx1.cpp(+ header): gate/up for IQ3_XXS, IQ3_S, IQ2_S and down for Q2_0, multi-token (nt=1..8), in the same separate-TU pattern askq_avx1.cpp: compiled-msse4.2 -mavx -mno-avx2 -mno-fma -mno-f16c(a#errorguards against FMA/F16C leaking into the object), gated at run time behindcpu_avx1_ok()and only when AVX2 is absent - no AVX2/AVX-512 kernel is touched, so no mainstream path changes rounding or speed.pshufb/sign_epi8/maddubsare SSSE3), 256-bit float accumulation, software half-to-float (no F16C), no gathers (the non-gather path;vpgatherddis AVX2).q8k_quant_avx1: the byte-identical Q8_K activation quantizer in SSE4.2/AVX1 (the AVX-2 copy's 256-bit packs become SSE2 packs, which need no lane-crossing fixup at 128-bit). 2.0x over ggml's scalar reference.native_expert.cpp: gate/up rows behind the samemt_minpolicy as the AVX-2 kernels (STRATA_IQ_MT_MIN, default 1 on the AVX1 tier - measured below), down rows always; kill switchSTRATA_NO_IQ128=1.Two formats are built, tested, and deliberately NOT dispatched
Both are measured negative results, kept in the tree (built + parity-tested) so the question does not need re-answering:
__AVX__dot for IQ4_NL (two blocks per iteration, 256-bit float accumulation) - not the scalar generic. It beats the 128-bit kernel 1.15-1.2x even after matching its two-block shape and sharing the decode across tokens.Every live path is the measured-best of {iq_avx1, ggml's best available path} on AVX1 hardware.
Tests
iq_avx1_parity(new, registered in CTest): all formats, nt=1..8 - every row bit-identical across widths (#152) and within the repo's 1e-5 aggregate bar against ggml's dots. It calls the kernels directly, so it exercises them on AVX2/AVX-512 CI as-is. The bench mode prints gate/up and down ratios separately (a combined ratio once hid a 0.78x down path inside a 2.1x line - see the commit history).q8k_quant_parityextended: the AVX1 copy is byte-identical toquantize_row_q8_K_refover all 16 degenerate/NaN/inf cases x 4 sizes; registered with aSTRATA_FORCE_ISA=avxvariant.iq_multi_parity,router_top10_parity,router_dot_parity,dequant_s2_parity,dequant_q5_1_test,expert_layout_testpass on this machine.strata serveon the hardware below runs with the kernels active (the startup line reportsthe expert kernels run on AVX1 128-bit (iq_avx1, the older-CPU build)), the start's GPU-vs-CPU expert check (slot 0 verified) passes, and it has served real traffic since.Measured on the hardware this exists for
Intel Xeon E5-2470 v2 (Ivy Bridge, AVX1 only, 10c/20t), 78 GB DDR3 (5 of 6 DIMM slots), RTX 5060 Ti 16 GB, Qwen3.8-Flash-Next IQ3_S native pack, engine 0.1.41.
Per expert, weights streamed from DRAM, one thread (
iq_avx1_parity --bench), gate/up and down measured separately (ours / ggml's best path on this CPU):At nt=1 the gate/up rows run two rows per pass (independent decode chains in the same registers; the decode is latency-bound at one token), and the float stage uses a single fused
cvtepi32of the exact int32 sum.STRATA_IQ_MT_MIN=1on the AVX1 tier: unlike the AVX-2 policy (#152), the AVX1 gate/up kernel beats ggml's generic even at one token (1.1-1.4x), so the draft window is not needed to amortize the decode.Serve, same 5276-token synthetic prompt, greedy, 150 tokens, before -> after: cold prefill 430 -> 581-607 tok/s, warm-reuse decode 22-25 -> 35-46 tok/s (37-38 steady after the follow-up commits); real interactive traffic 22-23 -> 25-26.5 tok/s. Decode wall-time on this rig is GPU/PCIe-bound (about a third of decode CPU time is pool workers waiting on the GPU), so the kernel wins land mostly in prefill and in freeing CPU for the GPU feed path.
Found while testing (pre-existing)
pool_tasks_testdies with SIGILL on non-AVX-512 machines even on a clean tree (v0.1.41, this hardware): it predates the ISA floor and reaches an AVX-512 path unconditionally. Filed as #1699, fixed in #1701 (adds the missing AVX1 rungs for the q2 bitplane paths).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.