[PR #4858] [Engine] cpu: finish the AVX1 lane - the rest of the expert row forms, gains and declines all measured (no-AVX2 CPUs) #5219

Open
opened 2026-11-07 16:33:33 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4858
Author: @nashcap
Created: 10/31/2026
Status: 🔄 Open

Base: main ← Head: avx1-lane


📝 Commits (3)

  • 140962d cpu: iq_avx1 grows to three lanes - the gate/up rows, the down rows and the Q8_K quantizer - with the Q4_K x IQ4_NL fused pairs measured side by side in parity and dispatch taking the winner; the IQ4_XS gu decline from #1697 stays declined (0.7-1.0x against the auto-vectorized generic on an E5-2470 v2), built and parity-tested
  • a06e582 cpu: kq_avx1 gains the Q4_K gu pair for nt tokens at once, 8 token slots in registers, and the AVX1 router dot covers several tokens; the fixtures measure the path the engine dispatches (the kq_min gate joined the nt>=6 rule)
  • b5ee618 cpu: dispatch the AVX1 lanes for the expert row forms the packs carry; q2_avx1's Q8_1 quantizer converts fp16 scales to fp32 branchlessly on the normal-exponent case, the exact fp32 bits, full converter kept for zero/subnormal/inf/nan

📊 Changes

10 files changed (+2524 additions, -101 deletions)

View changed files

📝 CMakeLists.txt (+4 -0)
📝 include/strata/kernels/cpu/iq_avx1.hpp (+9 -0)
📝 include/strata/kernels/cpu/kq_avx1.hpp (+9 -0)
📝 src/kernels/cpu/iq_avx1.cpp (+1562 -78)
📝 src/kernels/cpu/iq_avx1_parity.cpp (+669 -6)
📝 src/kernels/cpu/kq_avx1.cpp (+190 -7)
📝 src/kernels/cpu/kq_cpu_bench.cpp (+21 -0)
📝 src/kernels/cpu/native_expert.cpp (+31 -1)
📝 src/kernels/cpu/q2_avx1.cpp (+10 -0)
📝 src/kernels/cpu/router_dot_parity.cpp (+19 -9)

📄 Description

An Ivy Bridge Xeon (E5-2470 v2) has AVX but no AVX2 and no FMA. Since #1697 and the
q2_avx1 kernel that followed, the AVX1 128-bit lane covered the i-quant gate/up rows;
the K-quant rows and the rest of the expert row forms still fell back to ggml's
generic dots, and the engine spent a lot of its decode time there. This finishes the
lane: every expert row form this box's packs carry now has an AVX1 kernel, a measured
decline, or a measured reason to keep the generic rung.

Work done:

  • iq_avx1 gains the down rows and the Q8_K activation quantizer beside the gate/up
    rows it already had - three lanes where it used to be one set of kernels.

  • The Q4_K x IQ4_NL pair, which is the form the AP packs ship: the down rows are on
    the new kernel (1.2-1.34x). For gate/up I measured against ggml's AVX1 rung at every
    nt: the rung wins below nt=6 and keeps those calls; from nt=6 the fused pair kernel
    takes them, 1.07-1.09x on the dispatch path's own CI (bootstrap 95 %, 7 alternating
    reps).

  • kq_gu_rows_avx1 is that fused pair kernel: the Q4_K gu pair for nt tokens at once,
    8 token slots in registers.

  • bf16_rows_dot_multi_avx1: the router's dot for several tokens, AVX1.

  • The IQ4_XS gu decline from #1697 stays declined: measured 0.7-1.0x against the
    auto-vectorized generic on this CPU; the kernel stays built and parity-tested.

Bit-identity:
Every kernel replaces a ggml generic dot bit for bit: the fixed-seed rungs and rows
print 111 fingerprints in iq_avx1_parity and all match the generic dots, denormals
from the quantizer included. On the box the engine's output fingerprints were
bit-identical across the swap, and the same 111 fingerprints are unchanged across
three engine bumps (0.1.53 to 0.1.55).

Measured 2026-10-31 on the E5-2470 v2 (iq_avx1_parity --bench, ggml rung vs the lane,
ms/expert, min of alternating runs; nt = tokens per call):

  • i-quant gate/up x IQ4_NL down (IQ3_XXS, IQ3_S, IQ2_S, IQ4_XS): whole expert
    1.1-2.4x, best at nt=4 (IQ3_XXS gu alone 2.8x)

  • i-quant gate/up x Q2_0 down: whole expert 2.3-4.6x - the strongest family

  • Q4_K x IQ4_NL (the AP pack's form): whole expert 1.0-1.1x - dn 1.20-1.34x is the
    win, gu stays on the rung where measurement says (above), so its gu ratio here is a
    declined lane, not a shipped slowdown

  • IQ4_XS gu: declined, 0.7-1.0x against the auto-vectorized generic, as upstream
    declined it in #1697's follow-up

End to end: Qwen3.8-Flash-Next AP-Q4_K_XL on this box (V100S, 94 GB RAM) decodes at
48-50 tok/s with the lane (live metrics, same day). Prefill did not move: sampled on
the live engine, it is GPU-driver-bound, not lane-bound.

Not for every CPU:
Nothing changes for machines with AVX-512 or AVX2: every new call sits behind the
same no-AVX2 gate as #1697. The iq128_*_mode exports exist for the parity A/B harness
to pick a lane and compare; production never calls them.

How to test:
cmake --build . --target iq_avx1_parity kq_cpu_bench
./iq_avx1_parity # 111 fingerprints, "all rows match"

Scope: 10 files, +2524/-101, applies to main @ c62d5e3a with git apply --check.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4858 **Author:** [@nashcap](https://github.com/nashcap) **Created:** 10/31/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `avx1-lane` --- ### 📝 Commits (3) - [`140962d`](https://github.com/Niko1221/Strata/commit/140962dcea1b06965e9eca8596e1ec257eb2c6b3) cpu: iq_avx1 grows to three lanes - the gate/up rows, the down rows and the Q8_K quantizer - with the Q4_K x IQ4_NL fused pairs measured side by side in parity and dispatch taking the winner; the IQ4_XS gu decline from #1697 stays declined (0.7-1.0x against the auto-vectorized generic on an E5-2470 v2), built and parity-tested - [`a06e582`](https://github.com/Niko1221/Strata/commit/a06e582e1e0264344c3e8c530da287e31c7921d0) cpu: kq_avx1 gains the Q4_K gu pair for nt tokens at once, 8 token slots in registers, and the AVX1 router dot covers several tokens; the fixtures measure the path the engine dispatches (the kq_min gate joined the nt>=6 rule) - [`b5ee618`](https://github.com/Niko1221/Strata/commit/b5ee6185991b41cf19ec33397736a36fe8786bff) cpu: dispatch the AVX1 lanes for the expert row forms the packs carry; q2_avx1's Q8_1 quantizer converts fp16 scales to fp32 branchlessly on the normal-exponent case, the exact fp32 bits, full converter kept for zero/subnormal/inf/nan ### 📊 Changes **10 files changed** (+2524 additions, -101 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+4 -0) 📝 `include/strata/kernels/cpu/iq_avx1.hpp` (+9 -0) 📝 `include/strata/kernels/cpu/kq_avx1.hpp` (+9 -0) 📝 `src/kernels/cpu/iq_avx1.cpp` (+1562 -78) 📝 `src/kernels/cpu/iq_avx1_parity.cpp` (+669 -6) 📝 `src/kernels/cpu/kq_avx1.cpp` (+190 -7) 📝 `src/kernels/cpu/kq_cpu_bench.cpp` (+21 -0) 📝 `src/kernels/cpu/native_expert.cpp` (+31 -1) 📝 `src/kernels/cpu/q2_avx1.cpp` (+10 -0) 📝 `src/kernels/cpu/router_dot_parity.cpp` (+19 -9) </details> ### 📄 Description An Ivy Bridge Xeon (E5-2470 v2) has AVX but no AVX2 and no FMA. Since #1697 and the q2_avx1 kernel that followed, the AVX1 128-bit lane covered the i-quant gate/up rows; the K-quant rows and the rest of the expert row forms still fell back to ggml's generic dots, and the engine spent a lot of its decode time there. This finishes the lane: every expert row form this box's packs carry now has an AVX1 kernel, a measured decline, or a measured reason to keep the generic rung. Work done: - iq_avx1 gains the down rows and the Q8_K activation quantizer beside the gate/up rows it already had - three lanes where it used to be one set of kernels. - The Q4_K x IQ4_NL pair, which is the form the AP packs ship: the down rows are on the new kernel (1.2-1.34x). For gate/up I measured against ggml's AVX1 rung at every nt: the rung wins below nt=6 and keeps those calls; from nt=6 the fused pair kernel takes them, 1.07-1.09x on the dispatch path's own CI (bootstrap 95 %, 7 alternating reps). - kq_gu_rows_avx1 is that fused pair kernel: the Q4_K gu pair for nt tokens at once, 8 token slots in registers. - bf16_rows_dot_multi_avx1: the router's dot for several tokens, AVX1. - The IQ4_XS gu decline from #1697 stays declined: measured 0.7-1.0x against the auto-vectorized generic on this CPU; the kernel stays built and parity-tested. Bit-identity: Every kernel replaces a ggml generic dot bit for bit: the fixed-seed rungs and rows print 111 fingerprints in iq_avx1_parity and all match the generic dots, denormals from the quantizer included. On the box the engine's output fingerprints were bit-identical across the swap, and the same 111 fingerprints are unchanged across three engine bumps (0.1.53 to 0.1.55). Measured 2026-10-31 on the E5-2470 v2 (iq_avx1_parity --bench, ggml rung vs the lane, ms/expert, min of alternating runs; nt = tokens per call): - i-quant gate/up x IQ4_NL down (IQ3_XXS, IQ3_S, IQ2_S, IQ4_XS): whole expert 1.1-2.4x, best at nt=4 (IQ3_XXS gu alone 2.8x) - i-quant gate/up x Q2_0 down: whole expert 2.3-4.6x - the strongest family - Q4_K x IQ4_NL (the AP pack's form): whole expert 1.0-1.1x - dn 1.20-1.34x is the win, gu stays on the rung where measurement says (above), so its gu ratio here is a declined lane, not a shipped slowdown - IQ4_XS gu: declined, 0.7-1.0x against the auto-vectorized generic, as upstream declined it in #1697's follow-up End to end: Qwen3.8-Flash-Next AP-Q4_K_XL on this box (V100S, 94 GB RAM) decodes at 48-50 tok/s with the lane (live metrics, same day). Prefill did not move: sampled on the live engine, it is GPU-driver-bound, not lane-bound. Not for every CPU: Nothing changes for machines with AVX-512 or AVX2: every new call sits behind the same no-AVX2 gate as #1697. The iq128_*_mode exports exist for the parity A/B harness to pick a lane and compare; production never calls them. How to test: cmake --build . --target iq_avx1_parity kq_cpu_bench ./iq_avx1_parity # 111 fingerprints, "all rows match" Scope: 10 files, +2524/-101, applies to main @ c62d5e3a with git apply --check. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#5219
No description provided.