[PR #132] [CLOSED] cpu_exact1: the CPU lane's singleton IQ2_XXS rows run an exact AVX-2 gate/up kernel #357

Closed
opened 2026-10-29 21:24:36 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/132
Author: @handmade0octopus
Created: 10/12/2026
Status: ❌ Closed

Base: main ← Head: pr/cpu-exact1


📝 Commits (1)

  • bdfab17 cpu_exact1: the CPU lane's singleton IQ2_XXS rows run an exact AVX-2 gate/up kernel

📊 Changes

8 files changed (+404 additions, -0 deletions)

View changed files

📝 CMakeLists.txt (+3 -0)
📝 include/strata/kernels/cpu/iq_avx2.hpp (+10 -0)
📝 include/strata/kernels/cpu/native_expert.hpp (+3 -0)
📝 src/kernels/cpu/iq_avx2.cpp (+77 -0)
📝 src/kernels/cpu/native_expert.cpp (+47 -0)
➕ src/kernels/cpu/q8k_exact_port.inc (+68 -0)
📝 src/program/generate.cpp (+15 -0)
➕ tests/glm_cpu_exact1_test.cpp (+181 -0)

📄 Description

What

The CPU lane computes a route's RAM-tier experts on the host. For a decode, that work is dominated by singleton calls: one IQ2_XXS row against one q8_1 activation. ggml's vec_dot path for that case dequantizes through its own rounding and costs ~0.74 ms per expert on a 6-thread Ryzen 5 3600 lane. This adds an AVX-2 kernel that computes the gate/up rows exactly the way the device path does (dequant, clamp, sigmoid-mul) and takes over only the dominating case: one row x one token, type 16 (IQ2_XXS). Everything else - other formats, multi-token calls, the contiguous batched dispatch - keeps ggml. On by default where the CPU has AVX-2 (and no AVX-512 ggml path); STRATA_GLM_CPU_EXACT1=0 falls back to ggml, STRATA_GLM_CPU_EXACT1_DIAG=1 prints per-request counters.

Numbers (Maya-S-v2-IQ2_XXS, one 4090 D, RAM-resident tiers, ~9.5 CPU-lane experts/token)

Campaign protocol: 32,755-token prompt, 128 warm-up tokens, 2,048 measured on the fully cached prefix, temp 1.0 / top_p 0.95 / seed 734621, thinking max.

build CPU lane decode
v1.1.0 (ggml path) 9.46 experts/tok in 6.96 ms/tok 27.86 tok/s
v1.1.0 + this kernel 9.46 experts/tok in 6.57 ms/tok 28.05 tok/s

Per-expert: 0.736 -> 0.694 ms. Teacher-forced scoring over 2,047 positions with the path active: identical nll (0.16356) and top-1 (97.61%) to the ggml path; the diag counters confirm every CPU row went through the exact kernel (exact_rows=39,692,288 ggml_rows=0).

Verification

  • glm_cpu_exact1_test (needs a real pack) checks the exact path's activation on real experts.
  • The counters sample around decode only (startup and prompt work excluded).

🔄 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/132 **Author:** [@handmade0octopus](https://github.com/handmade0octopus) **Created:** 10/12/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/cpu-exact1` --- ### 📝 Commits (1) - [`bdfab17`](https://github.com/mw00/project-maya/commit/bdfab17a72ea9aefd6251424e27ecce3b143882a) cpu_exact1: the CPU lane's singleton IQ2_XXS rows run an exact AVX-2 gate/up kernel ### 📊 Changes **8 files changed** (+404 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+3 -0) 📝 `include/strata/kernels/cpu/iq_avx2.hpp` (+10 -0) 📝 `include/strata/kernels/cpu/native_expert.hpp` (+3 -0) 📝 `src/kernels/cpu/iq_avx2.cpp` (+77 -0) 📝 `src/kernels/cpu/native_expert.cpp` (+47 -0) ➕ `src/kernels/cpu/q8k_exact_port.inc` (+68 -0) 📝 `src/program/generate.cpp` (+15 -0) ➕ `tests/glm_cpu_exact1_test.cpp` (+181 -0) </details> ### 📄 Description ## What The CPU lane computes a route's RAM-tier experts on the host. For a decode, that work is dominated by singleton calls: one IQ2_XXS row against one q8_1 activation. ggml's vec_dot path for that case dequantizes through its own rounding and costs ~0.74 ms per expert on a 6-thread Ryzen 5 3600 lane. This adds an AVX-2 kernel that computes the gate/up rows exactly the way the device path does (dequant, clamp, sigmoid-mul) and takes over only the dominating case: one row x one token, type 16 (IQ2_XXS). Everything else - other formats, multi-token calls, the contiguous batched dispatch - keeps ggml. On by default where the CPU has AVX-2 (and no AVX-512 ggml path); `STRATA_GLM_CPU_EXACT1=0` falls back to ggml, `STRATA_GLM_CPU_EXACT1_DIAG=1` prints per-request counters. ## Numbers (Maya-S-v2-IQ2_XXS, one 4090 D, RAM-resident tiers, ~9.5 CPU-lane experts/token) Campaign protocol: 32,755-token prompt, 128 warm-up tokens, 2,048 measured on the fully cached prefix, temp 1.0 / top_p 0.95 / seed 734621, thinking max. | build | CPU lane | decode | |---|---|---| | v1.1.0 (ggml path) | 9.46 experts/tok in 6.96 ms/tok | 27.86 tok/s | | v1.1.0 + this kernel | 9.46 experts/tok in **6.57 ms/tok** | **28.05 tok/s** | Per-expert: 0.736 -> 0.694 ms. Teacher-forced scoring over 2,047 positions with the path active: identical nll (0.16356) and top-1 (97.61%) to the ggml path; the diag counters confirm every CPU row went through the exact kernel (`exact_rows=39,692,288 ggml_rows=0`). ## Verification - `glm_cpu_exact1_test` (needs a real pack) checks the exact path's activation on real experts. - The counters sample around decode only (startup and prompt work excluded). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:24:36 +07:00
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#357
No description provided.