mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #394] [CLOSED] AVX1: run on a CPU with AVX but no AVX2, with an end-to-end run on Sandy Bridge-E #2618
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#2618
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/394
Author: @demetree
Created: 10/1/2026
Status: ❌ Closed
Base:
main← Head:strata-avx1-pr📝 Commits (5)
93d09b7AVX1: the Q2_0 expert kernels for CPUs that have AVX but no AVX25b9b126AVX1: the CANONICAL Q2_0 expert path, which is the one pool.cpp runsfedf409AVX1 tests: correct the AVX2 probe, and keep the /arch:AVX2 code out of the link8854151iq_avx2: build the IQ2 sign table without a variable shift0083bb7native experts: gate the AVX2 multi-token kernels on cpu_avx2_ok()📊 Changes
13 files changed (+1700 additions, -22 deletions)
View changed files
📝
CMakeLists.txt(+34 -1)📝
include/strata/kernels/cpu/expert.hpp(+22 -0)📝
include/strata/kernels/cpu/expert_layout.hpp(+28 -0)📝
src/kernels/cpu/expert_layout.cpp(+192 -3)📝
src/kernels/cpu/iq_avx2.cpp(+15 -3)📝
src/kernels/cpu/native_expert.cpp(+13 -3)📝
src/kernels/cpu/pool.cpp(+7 -7)➕
src/kernels/cpu/q2_avx1.cpp(+236 -0)➕
src/kernels/cpu/q2_avx1_parity.cpp(+382 -0)➕
src/kernels/cpu/s2_avx1_parity.cpp(+368 -0)➕
src/kernels/cpu/s2_avx512_stub.cpp(+98 -0)➕
src/kernels/cpu/s2_expert_avx1.cpp(+290 -0)📝
src/program/generate.cpp(+15 -5)📄 Description
Follow-up to #227, which was closed with four specific objections. Each is addressed below, and the
end-to-end run is on a pre-Haswell CPU.
The end-to-end run
Hardware: Xeon E5-2680 (Sandy Bridge-E) — no AVX2, no FMA3, no F16C, no BMI2, no AVX-512 — and a
GTX 1080 Ti (sm_61, Pascal), below this project's sm_75 floor, so the engine was built with
STRATA_EXPERIMENTAL_SM60=ON(#236). Model: native IQ2_XS pack, 33.02 GiB loaded, CUDA 12.6, MSVC 19.44.CPU experts 8.98 distinct / 11.58 routed per layer— the CPU path is genuinely exercised, notbypassed.
An actual answer, not just an exit code
Same machine, same build, same pack — a real prompt, 80 tokens generated. The ids were produced and
checked with the tokenizer
tools/iq_pack.pyshipped in the pack (vocab.json+merges.txt,byte-level BPE); the round-trip reproduces the prompt character-for-character, so the ids are the
model's own.
The answer is correct — Rayleigh scattering, in two sentences, as asked.
Speculative decoding accepts little here, and that is the hardware rather than the change:
The CPU pool is the bottleneck, so the draft head cannot run ahead of it. On a machine whose CPU path
runs at full speed the acceptance rate should be far higher; 2.87 tok/s is a floor set by the CPU, not
by this change.
The four objections
1. "native (IQ) packs ... aren't covered (
iq_avx2.cpphas BMI2 and would still trap on an AVX-only CPU)"Correct, and the trap was worse than described: it happened before
main().iq_avx2.cppbuilds astatic sign table with
<< (8 * k), a variable shift, which MSVC under/arch:AVX2emits as BMI2shlx.even_signsis a namespace-scope static, so the constructor runs at process start —strata.exeexited
0xC000001Dwith no output at all, not even for--help. (Submitted separately as #391, sinceit needs none of this.)
Then there was a second trap.
native_gu_rows()gated the AVX-512 kernel correctly and the AVX2 onenot at all:
so a verify window with two or more tokens reached
iq256_gu_rowsand trapped onvfmadd231ps. Thesame asymmetry guarded
native_down_rows()'s two multi-token kernels. All three now requirecpu_avx2_ok().This does not need an AVX1 kernel, and that is the useful part.
native_expert.cppalready computesnative IQ experts "through ggml-cpu", and ggml-cpu ships a
vec_dotfor every one of these types —ggml_vec_dot_iq2_xxs_q8_K,_iq2_s_q8_Kand the rest — compiled for whatever baseline the buildselected. That path sits below both multi-token kernels and loops over tokens itself, so it is
correct for any
nt. It was unreachable only because skipping the multi-token kernels required anenvironment variable. With the gate fixed, a pre-Haswell CPU falls through to it.
So the native path is covered by three one-line guards, not by 655 lines of re-derived quant
kernels — which is also why the numbers above are exact rather than approximate.
2. "the release links ggml with an AVX2 baseline anyway"
Understood and unchanged — this is a deliberate portability choice, not something to override. Two
distinct regimes, and the second is what an AVX1 build needs:
STRATA_PORTABLE=ON→GGML_NATIVE=OFF+GGML_AVX/AVX2/FMA/F16C/BMI2allON: one engine for anyAVX2 PC. Correct as it stands.
STRATA_PORTABLE=OFF(default) →GGML_NATIVE=ON, host-detected. An AVX1 baseline build then works,and configure confirms it:
Adding CPU backend variant ggml-cpu: /arch:AVX GGML_AVX, withHAS_AVX2_1 - Failed,HAS_FMA_1 - Failed,HAS_AVX512_1 - Failed.So the run above is an AVX1 ggml build. What this branch does not do is add an explicit
GGML_NATIVE=OFF+ AVX1-only option for someone who wants a portable engine and an old CPU. Thatwould be a separate, small CMake change and I would rather ask than assume.
3. "
STRATA_FORCE_AVX2=1would exit on AVX-512 machines"Real bug, and mine. Our
cpu_avx1_ok()/cpu_avx2_ok()tested the mere presence of the variable whilecpu_avx512_ok()testsf[0] == '1'. All three rungs therefore returned false at once on an AVX-512machine and the startup gate exited. Both now use
f[0] == '1', with the reason in the source.4. "no end-to-end run"
See above.
What this branch contains
q2_avx1.cppands2_expert_avx1.cpp, three-waydispatch,
cpu_avx1_ok()probing AVX + SSSE3 + SSE4.1 and deliberately not FMA3/F16C (verified byexecuting
vfmadd*andvcvtph2pson the target CPU, where each raises#UD).cpu_avx2_ok()tocpu_avx1_ok(), message updated to name the newfloor.
cpu_avx2_ok()corrected to leaf 7 EBX bit 5 — leaf 1 ECX bit 5 is plain AVX (Sandy Bridge), notAVX2 (Haswell). Our version of this was wrong and would have routed a pre-Haswell CPU into the AVX2
kernel; the test caught it as
avx2=1 avx1=1on a CPU with no AVX2.Tests
Two self-contained parity tests,
q2_avx1_parityands2_avx1_parity, both of which need neither the38 GB pack nor an AVX-512 CPU —
expert_parityskips itself on exactly the hardware this targets,so without them this kernel would ship untested.
Caveats
instruction instead of 32) and nothing in accuracy. Its purpose is to stop an illegal instruction.
pre-Haswell CPU comes from ggml-cpu's own kernels via the fixed gate, not from anything in this branch.
STRATA_EXPERIMENTAL_SM60is useful to anyone else on a card below the community-tested set, theconfiguration in the log above is a working data point for it.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
max_model_lenandcontext_length#3734