mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4854] [CLOSED] AVX1 Q2_0 Native Rows #5212
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#5212
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/4854
Author: @Keoian
Created: 10/31/2026
Status: ❌ Closed
Base:
main← Head:avx1-q2-native-rows📝 Commits (2)
43e390e[Engine] AVX-only CPUs: a native pack's Q2_0 layers on Strata's AVX1 Q2_0 rows instead of ggml-cpu's vec_dot7a68664[Engine] AVX1 Q2_0 rows: the bit-plane pair's float part on 256 bits, a branch-free scale conversion📊 Changes
2 files changed (+52 additions, -31 deletions)
View changed files
📝
include/strata/kernels/cpu/expert_layout.hpp(+5 -4)📝
src/kernels/cpu/q2_avx1.cpp(+47 -27)📄 Description
Problem and result
On a CPU with AVX but no AVX2 (the experimental older-CPU source build,
STRATA_ISA_FLOOR=avx),q2_native_kernels()admitted AVX2 only. Every native pack's Q2_0 expert therefore ran on ggml-cpu's Q2_0vec_dotand never reached Strata's AVX1 rows inq2_avx1.cpp. With this PR those layers take the AVX1 rung ofq2_rows_any/act_quant_any, and the AVX1 bit-plane row does its float work on 256 bits.On an i7-3770, a one-token Q2_0 expert goes from 0.975 to 0.297 ms per thread with
STRATA_Q2_BITPLANE=1(0.487 ms without it). End to end on 2x RX 5700 XT with Qwen3.8-Flash-Next Q2_0, decode goes from 14.97 to 22.38 tok/s (+49.6%).Related discussion
#4728. #1824 proposed the same gate change and was closed as covered by
q2_avx1.cpp; the issue shows that the gate still sends native packs to ggml-cpu. #1699 / #1701 added the AVX1 rung.Approach
q2_native_kernels()also admitscpu_avx1_ok(). A CPU without AVX keeps ggml-cpu.row_bp_acccomputes a bit-plane pair's float part (two 64-value blocks) in one 256-bit register: block 0 in the low lanes, block 1 in the high lanes. Each lane runs the same operations in the same order as the 128-bit form, so the bytes do not change.h2f_scaleconverts a normal fp16 block scale in four integer operations (h2f's normal branch, bit for bit); zero, subnormals, inf and NaN still takeh2f.Compatibility: on AVX-only CPUs the first commit changes bits against ggml-cpu's path, because the AVX1 rows sum floats in their own order (AVX2 CPUs already take Strata's rows). AVX2 and AVX-512 CPUs and the release engines (AVX2 baseline) run the same code as before.
Validation
Environment: i7-3770 (Ivy Bridge, AVX, no AVX2), 32 GB DDR3-1600, 2x RX 5700 XT 8 GB (gfx1010), Ubuntu with kernel 7.0, GCC 15.2, ROCm 7.14.0a20260612 (TheRock gfx101X-dgpu). HIP build:
-DSTRATA_ENABLE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx1010 -DSTRATA_ISA_FLOOR=avx -DSTRATA_BUILD_TESTS=ON, base870aedd9.Passed:
Build of this branch (
7a68664a):ninja strata kq_cpu_bench q2_bitplane_parity pool_tasks_test expert_layout_test native_arithmetic_parity iq_avx1_parity, 0 errors.ctest -R '^(q2_bitplane_parity|pool_tasks_test|expert_layout_test|native_arithmetic_parity.*|iq_avx1_parity)$': 12 of 12 passed (ROCm's lib directory onLD_LIBRARY_PATH;expert_layout_testlinks the HIP runtime).kq_cpu_bench --pairs q2_0/q2_0 --threads 1,4 --nt 1,3,4 --mb 1024 --reps 3, ms per expert per thread at 1 / 3 / 4 tokens:STRATA_Q2_BITPLANE=1Same bytes for commit 2: FNV hashes of both kernels' outputs on fixed random blocks at 1-8 tokens are identical before and after, with
STRATA_Q2_BITPLANE=1and with the legacy rows. The harness issrc/kernels/cpu/q2_avx1_parity.cppon https://github.com/Keoian/Strata/tree/rx-5700-xt-optimizations and is not part of this PR.Decode A/B against main (
870aedd9): 2x RX 5700 XT 8 GB (layer split 27), Qwen3.8-Flash-Next ISTA-DASLab Q2_0,--spec 4 --spec-min-p 0.8 --mtp --kv int8,STRATA_Q2_BITPLANE=1,STRATA_HC_Q8=0. 3 prompts x 2 reps, 256 tokens greedy, a fresh engine start per arm, ABBA over two starts each. Mean 14.97 -> 22.38 tok/s (+49.6%), 11 of 12 pairs faster. The branch binary was built before the comment inexpert_layout.hppwas corrected; the code is the same.Per-run decode tok/s
Failed:
none observed.
Not run:
STRATA_ISA_FLOOR=none), Sandy Bridge, Windows / MSVC.Limits
Measured on one CPU model (Ivy Bridge). Only Q2_0 changes; the i-quants keep their own AVX1 kernels.
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.