mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #257] [CLOSED] q2_avx2: two-block 256-bit unpack for the AVX2 Q2_0 expert rows (bit-exact) #2529
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#2529
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/257
Author: @hireymage
Created: 9/30/2026
Status: ❌ Closed
Base:
main← Head:cpu-b256📝 Commits (1)
8653307q2_avx2: two-block 256-bit unpack for rows of 1-2 tokens (bit-exact)📊 Changes
1 file changed (+87 additions, -1 deletions)
View changed files
📝
src/kernels/cpu/q2_avx2.cpp(+87 -1)📄 Description
Title:
q2_avx2: two-block 256-bit unpack for the AVX2 Q2_0 expert rows (bit-exact)
Body:
What this does
On CPUs without AVX-512 (Intel Core 12th–14th gen, AMD Zen 2/3 — the
machines
q2_avx2.cppis built for), the Q2_0 expert rows run a128-bit-only shuffle ladder that unpacks every 64-code weight block from
its 16 code bytes. This PR halves the ladder work for the most common
routed shape: rows that serve 1–2 activations. A 256-bit pass covers two
consecutive blocks at once, so the ladder runs once for a pair of weight
blocks instead of twice.
unpack64x2: lane 0 holds block b's 16 code bytes, lane 1 holds blockb+1's (Q2_0 blocks are 18 bytes apart, so lane 1 loads at
codes + 18);every shift/and is per-128-bit lane, i.e. numerically the SSE ladder run
twice.
order → the same
madd/maddubslane mapping → bit-identical results.Verified by
memcmpagainst the original code in a standalone harness(all of gate/up and down, tokens 1/2/4/8).
rows<1>/rows<2>). At 4+ tokensthe extra live unpack vectors spill registers and it measurably loses,
so the original ladder stays in place there. AVX-512 machines are
unaffected (they use a different path dispatch).
Measured on my machine
i7-8700K (AVX2, 6C/12T), RTX 2070 (sm_75), Qwen3.8-Flash-Next native Q2_0
pack (spec verified from the GGUF header, ~125.7B-parameter MoE), engine
0.1.27 build, temperature 0, 5 prompts × 3 warm passes per variant, and a
fresh baseline rerun in the same time block to rule out machine drift.
+5–7 % down rows at 1 token/expert; +2–4 % at 2 tokens; −5–11 % at
4 tokens (why the guard exists).
~−6 %), coming cleanly out of the CPU expert-pool stage (stage
profiler
waitCPU: GDN ~18.9 → ~13.1 ms, QSA ~4.4 → ~3.2 ms perwindow). GPU kernel stages unchanged, and generation token counts are
identical across all runs (same prompts, temperature 0).
Please test on other devices
I can only measure one machine, and both the gain and the end-to-end
visibility depend on the platform:
without AVX-512 enabled, AMD Zen 2/3): the per-row gain is expected to
be universal, but its end-to-end size depends on how much of decode is
the CPU expert pool.
tokens are more common there) — the
nt <= 2guard should keep them onthe original ladder; a check that nothing changes on that side is
welcome.
path) — a confirmation is also useful.
Greedy outputs should be identical before/after; if you see a difference,
that's a bug, please report it.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.