[PR #623] CPU lane: IQ1_M rows with folded scales and int16 sums, IQ2_XS one-token own rows (bit for bit ggml-cpu dot) #629

Open
opened 2026-10-29 21:27:39 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/623
Author: @SeriousRising
Created: 10/28/2026
Status: 🔄 Open

Base: main ← Head: cpu-iq1m-iq2xs-rows


📝 Commits (1)

  • b772203 CPU lane: IQ1_M rows with folded scales and int16 sums, IQ2_XS one-token own rows (bit for bit ggml-cpu dot)

📊 Changes

7 files changed (+186 additions, -68 deletions)

View changed files

📝 docs/SETTINGS.md (+1 -0)
📝 include/strata/kernels/cpu/iq_avx2.hpp (+1 -1)
📝 include/strata/kernels/cpu/native_expert.hpp (+2 -0)
📝 src/kernels/cpu/iq_avx2.cpp (+126 -62)
📝 src/kernels/cpu/native_expert.cpp (+4 -2)
📝 src/kernels/cpu/native_rows_exact_test.cpp (+44 -0)
📝 tests/ds4_lane_bench.cpp (+8 -3)

📄 Description

What. src/kernels/cpu/iq_avx2.cpp (row_dot_iq1m, row_dot_iq2xs, iq256_rows1_supported), on top of #452's rows:

  • IQ1_M. A microbenchmark showed #452's rows are bound by the total uop count (Broadwell: 4 a cycle, ~20 cycles per 64 weights), not by the shuffle port. Two exact integer identities cut the uops:

    1. IQ1_M grid bytes are only -1 / 0 / +1, so maddubs(|g|, sign(q8, g)) equals maddubs(scale, sign(q8, g)) with the block scale folded in, and both |g| sign ops go.
    2. Scales 2s + 1 <= 15 go into maddubs' unsigned operand. A lane is at most 2 x 15 x 128 = 3840, and 8 of them a block at most 30720, which fits int16. So the sums accumulate in int16, with one madd a block instead of 4 madd + 4 add per 64 weights.

    Grid indices come from ggml's pdep form where pdep is fast (CPUID: BMI2, and not AMD / Hygon below family 19h), elsewhere from scalar indices into a 4-entry table. The delta signs come from one broadcast of qh, with no set_epi64x. The int32 lanes per block are ggml's exact integers, and ggml's float steps are unchanged.

  • IQ2_XS. The grid by tab4 from scalar u16 loads, half-scales from a 256-entry table. Its one-token own rows are enabled (type 17 in iq256_rows1_supported / iq256_rows1); before, IQ2_XS at one token fell back to ggml's vec_dot.

  • No AVX2 code runs before main: the tables are constexpr (.rodata), and the pdep probe is a function-local static behind cpu_avx2_ok(), so a pre-AVX2 CPU still reaches the ggml fallback.

  • Tests: native_rows_exact_test gains the IQ1_M int16 worst case (every scale 15, an all +1 grid, every delta bit, q8 = -127, lanes at +-30480). ds4_lane_bench gains an iq2_xs format and prints the exactness of each format's one-token and multi-token rows.

Setting: DS4_IQ1M_PDEP=0/1 forces the index form on a BMI2 CPU, for checking the other form (both exact); unset = the CPUID choice above. A row in docs/SETTINGS.md, beside DS4_IQ1_PDEP.

Overlap with #584 (open): #584 sends one-token IQ1_M rows to ggml-cpu's own BMI2 dot where pdep is fast. This PR touches the same routing: our rows are faster than ggml's dot at one token (table below) and also cover several tokens, which #584 leaves alone. If #584 lands first, this replaces its one-token routing with these rows and would keep its cpu_pdep_slow() probe instead of ours; happy to rebase either way.

IQ1_M, one 2304 x 5120 matrix, one Broadwell core, L3-resident ms
#452's rows (v1.1.35) 2.292
ggml-cpu AVX2 + BMI2 dot (what #584 routes to) 1.269
this PR, pdep-free form (chosen on Zen 1/2, Hygon) 1.402
this PR, pdep form 1.152

Output: unchanged, bit for bit ggml-cpu's dot:

  • the engine's start gate is unchanged (rows_match_ggml: 306 one-token rows and nt 2/5/11, with the subnormal shifts; any mismatch falls back to ggml); both forms pass it for IQ1_M and IQ2_XS;
  • native_rows_exact_test: "all identical" with DS4_IQ1M_PDEP unset, =0 and =1;
  • ds4_iq1_rows_test (DS4_IQ1_PDEP=0 and =1, its two CMake tests): 36 cases, 0 differ from ggml-cpu's dot;
  • ds4_lane_bench --check: IQ1_M and IQ2_XS own rows bit-identical to ggml's dot, one token and several; every format within 1.8e-7 of the double reference;
  • ds4_gguf_test: ALL OK; the engine run below gives the same token ids and DSpark counts as v1.1.35.

Measured. CPU: 16-vCPU Xeon E5-2697 v4 VM (Broadwell, AVX2 + BMI2, 4-channel DDR4-2133), g++ 13.3, -march=native. ds4_lane_bench, one token, an expert end to end (gate/up/down, activation quant, SiLU, the pool's jobs), v1.1.35's binary vs this branch's, one run each:

format 1 thread, v1.1.35 1 thread, this PR 14 threads, v1.1.35 14 threads, this PR
IQ1_M 7.097 ms 4.199 (1.69x) 0.757 0.387 (1.96x)
IQ2_XS (no iq2_xs format in v1.1.35's bench) 3.522 0.338
IQ2_XXS (code unchanged) 4.423 4.811 0.489 0.498

(IQ2_XXS's code is not changed; its 1-thread difference is run-to-run spread on a shared VM.)

Engine: 2x CMP 170HX 64 GB (sm_80; PCIe Gen2 x16 + Gen2 x4, platform-specific), DeepSeek-V4.1-Flash-1017 GSQ-RCO IQ2_XXS (routed experts IQ1_M / IQ2_XS / IQ2_XXS; most in VRAM, the rest on the CPU lane), --tp 1 --gpus 0,1 --dspark on --cpu-threads 14 --suffix-draft 0, 2000 fixed prompt ids + 256 greedy tokens, one run per binary: verify time 5086.6 -> 4529.6 ms over the same 80 DSpark rounds (-11 %), decode 40.68 -> 45.10 tok/s, the same ids. Earlier, through the server on our v1.1.29-based fork (5 prompts x 512 tokens, temperature 0): -6.5 % / -3.8 % a verify window, --dspark none -3.1 % / -2.3 % a step, the same text; the larger gain on v1.1.35 was not analysed.

Zen 3 / Zen 4 / newer Intel (the pdep form) and Zen 1/2 / Hygon (the pdep-free form): not measured. The gain depends on how much CPU-lane time is exposed; a box that streams more experts from RAM should gain more (not measured).

Checks (as .github/workflows/tests.yml): tools/check_hip_compat.py OK; server tests 463 OK (12 skipped); installer and tools tests 584 OK (31 skipped) - the same counts as v1.1.35.

🤖 Generated with Claude Code


🔄 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/mw00/project-maya/pull/623 **Author:** [@SeriousRising](https://github.com/SeriousRising) **Created:** 10/28/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `cpu-iq1m-iq2xs-rows` --- ### 📝 Commits (1) - [`b772203`](https://github.com/mw00/project-maya/commit/b772203a4acfd7e88f7476fc7a6f33359b26f549) CPU lane: IQ1_M rows with folded scales and int16 sums, IQ2_XS one-token own rows (bit for bit ggml-cpu dot) ### 📊 Changes **7 files changed** (+186 additions, -68 deletions) <details> <summary>View changed files</summary> 📝 `docs/SETTINGS.md` (+1 -0) 📝 `include/strata/kernels/cpu/iq_avx2.hpp` (+1 -1) 📝 `include/strata/kernels/cpu/native_expert.hpp` (+2 -0) 📝 `src/kernels/cpu/iq_avx2.cpp` (+126 -62) 📝 `src/kernels/cpu/native_expert.cpp` (+4 -2) 📝 `src/kernels/cpu/native_rows_exact_test.cpp` (+44 -0) 📝 `tests/ds4_lane_bench.cpp` (+8 -3) </details> ### 📄 Description **What.** `src/kernels/cpu/iq_avx2.cpp` (`row_dot_iq1m`, `row_dot_iq2xs`, `iq256_rows1_supported`), on top of #452's rows: - **IQ1_M.** A microbenchmark showed #452's rows are bound by the total uop count (Broadwell: 4 a cycle, ~20 cycles per 64 weights), not by the shuffle port. Two exact integer identities cut the uops: 1. IQ1_M grid bytes are only -1 / 0 / +1, so `maddubs(|g|, sign(q8, g))` equals `maddubs(scale, sign(q8, g))` with the block scale folded in, and both `|g|` sign ops go. 2. Scales 2s + 1 <= 15 go into maddubs' unsigned operand. A lane is at most 2 x 15 x 128 = 3840, and 8 of them a block at most 30720, which fits int16. So the sums accumulate in int16, with **one `madd` a block** instead of 4 `madd` + 4 `add` per 64 weights. Grid indices come from ggml's `pdep` form where `pdep` is fast (CPUID: BMI2, and not AMD / Hygon below family 19h), elsewhere from scalar indices into a 4-entry table. The delta signs come from one broadcast of qh, with no `set_epi64x`. The int32 lanes per block are ggml's exact integers, and ggml's float steps are unchanged. - **IQ2_XS.** The grid by `tab4` from scalar u16 loads, half-scales from a 256-entry table. Its one-token own rows are enabled (type 17 in `iq256_rows1_supported` / `iq256_rows1`); before, IQ2_XS at one token fell back to ggml's `vec_dot`. - No AVX2 code runs before `main`: the tables are `constexpr` (`.rodata`), and the `pdep` probe is a function-local static behind `cpu_avx2_ok()`, so a pre-AVX2 CPU still reaches the ggml fallback. - Tests: `native_rows_exact_test` gains the IQ1_M int16 worst case (every scale 15, an all +1 grid, every delta bit, q8 = -127, lanes at +-30480). `ds4_lane_bench` gains an `iq2_xs` format and prints the exactness of each format's one-token and multi-token rows. **Setting:** `DS4_IQ1M_PDEP=0/1` forces the index form on a BMI2 CPU, for checking the other form (both exact); unset = the CPUID choice above. A row in `docs/SETTINGS.md`, beside `DS4_IQ1_PDEP`. **Overlap with #584** (open): #584 sends one-token IQ1_M rows to ggml-cpu's own BMI2 dot where `pdep` is fast. This PR touches the same routing: our rows are faster than ggml's dot at one token (table below) and also cover several tokens, which #584 leaves alone. If #584 lands first, this replaces its one-token routing with these rows and would keep its `cpu_pdep_slow()` probe instead of ours; happy to rebase either way. | IQ1_M, one 2304 x 5120 matrix, one Broadwell core, L3-resident | ms | |---|---| | #452's rows (v1.1.35) | 2.292 | | ggml-cpu AVX2 + BMI2 dot (what #584 routes to) | 1.269 | | this PR, `pdep`-free form (chosen on Zen 1/2, Hygon) | 1.402 | | **this PR, `pdep` form** | **1.152** | **Output: unchanged**, bit for bit ggml-cpu's dot: - the engine's start gate is unchanged (`rows_match_ggml`: 306 one-token rows and nt 2/5/11, with the subnormal shifts; any mismatch falls back to ggml); both forms pass it for IQ1_M and IQ2_XS; - `native_rows_exact_test`: "all identical" with `DS4_IQ1M_PDEP` unset, `=0` and `=1`; - `ds4_iq1_rows_test` (`DS4_IQ1_PDEP=0` and `=1`, its two CMake tests): 36 cases, 0 differ from ggml-cpu's dot; - `ds4_lane_bench --check`: IQ1_M and IQ2_XS own rows bit-identical to ggml's dot, one token and several; every format within 1.8e-7 of the double reference; - `ds4_gguf_test`: ALL OK; the engine run below gives the same token ids and DSpark counts as v1.1.35. **Measured.** CPU: 16-vCPU Xeon E5-2697 v4 VM (Broadwell, AVX2 + BMI2, 4-channel DDR4-2133), g++ 13.3, `-march=native`. `ds4_lane_bench`, one token, an expert end to end (gate/up/down, activation quant, SiLU, the pool's jobs), v1.1.35's binary vs this branch's, one run each: | format | 1 thread, v1.1.35 | 1 thread, this PR | 14 threads, v1.1.35 | 14 threads, this PR | |---|---|---|---|---| | IQ1_M | 7.097 ms | **4.199** (1.69x) | 0.757 | **0.387** (1.96x) | | IQ2_XS | (no `iq2_xs` format in v1.1.35's bench) | 3.522 | | 0.338 | | IQ2_XXS (code unchanged) | 4.423 | 4.811 | 0.489 | 0.498 | (IQ2_XXS's code is not changed; its 1-thread difference is run-to-run spread on a shared VM.) Engine: 2x CMP 170HX 64 GB (sm_80; PCIe Gen2 x16 + Gen2 x4, platform-specific), DeepSeek-V4.1-Flash-1017 GSQ-RCO IQ2_XXS (routed experts IQ1_M / IQ2_XS / IQ2_XXS; most in VRAM, the rest on the CPU lane), `--tp 1 --gpus 0,1 --dspark on --cpu-threads 14 --suffix-draft 0`, 2000 fixed prompt ids + 256 greedy tokens, one run per binary: verify time 5086.6 -> 4529.6 ms over the same 80 DSpark rounds (**-11 %**), decode 40.68 -> 45.10 tok/s, the same ids. Earlier, through the server on our v1.1.29-based fork (5 prompts x 512 tokens, temperature 0): -6.5 % / -3.8 % a verify window, `--dspark none` -3.1 % / -2.3 % a step, the same text; the larger gain on v1.1.35 was not analysed. Zen 3 / Zen 4 / newer Intel (the `pdep` form) and Zen 1/2 / Hygon (the `pdep`-free form): not measured. The gain depends on how much CPU-lane time is exposed; a box that streams more experts from RAM should gain more (not measured). **Checks** (as `.github/workflows/tests.yml`): `tools/check_hip_compat.py` OK; server tests 463 OK (12 skipped); installer and tools tests 584 OK (31 skipped) - the same counts as v1.1.35. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <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 labels
pull-request
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
mw00/project-maya#629
No description provided.