[PR #4046] [Engine] add opt-in reference-order CPU mixed-IQ down dispatch #4888

Open
opened 2026-11-07 16:31:07 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4046
Author: @CrashxZ
Created: 10/25/2026
Status: 🔄 Open

Base: main ← Head: pr/iq-down-reference-order


📝 Commits (2)

  • 1bedc77 feat(cpu): add opt-in exact mixed-IQ native down dispatch
  • 3cbfd25 refactor: scope mixed-IQ down port to exact CPU dispatch

📊 Changes

6 files changed (+457 additions, -0 deletions)

View changed files

➕ docs/IQ_DOWN_EXACT.md (+98 -0)
📝 src/kernels/cpu/native_expert.cpp (+19 -0)
➕ tools/iq_down_dispatch_test.cpp (+110 -0)
➕ tools/iq_down_exact_test.cpp (+125 -0)
➕ tools/test_iq_down_dispatch.py (+47 -0)
➕ tools/test_iq_down_exact.py (+58 -0)

📄 Description

This adds an opt-in CPU down-projection path for the 2048/512 mixed-IQ layout: IQ2_S gate/up with IQ2_S or IQ3_S down. It reuses upstream's iq256x_rows API to decode weights once across multiple tokens while keeping reference-order dot products.

Set STRATA_IQ_DOWN_EXACT=1 before startup to enable it. The default path is unchanged. The dispatcher checks the runtime and compiled GGML ISA, quantization types, contiguous layout and token width (2–8). Unsupported cases fall back; STRATA_NO_IQ256 and STRATA_IQ_MT_MIN still apply.

This came out of the MoEmentum low-VRAM inference work. The exact-row arithmetic already exists upstream; this PR wires it into the native CPU dispatcher and adds regression tests.

Tests

Tested on Linux with GCC/G++ 15.2.0 and AVX2/FMA/F16C, against llama.cpp 3cf03257f219afbe7334045ff7c6a06ac68c627d:

  • 384 routing and argument-forwarding checks passed.
  • 10,368 public exact-row comparisons passed bitwise.
  • 1,179,648 native comparisons passed bitwise in each mode, enabled and disabled.
  • ASan/UBSan passed for the project translation units. A separate run instrumenting external GGML reported signed-shift warnings in unchanged dependency code.

To reproduce, point $LLAMA at that llama.cpp checkout and use fresh output directories:

python3 tools/test_iq_down_dispatch.py --llama-dir "$LLAMA" --output "$OUT/dispatch"
python3 tools/test_iq_down_exact.py --llama-dir "$LLAMA" --output "$OUT/exact"

Limits

These are kernel and dispatch tests, not full-model validation or a speed benchmark. The option stays off by default, and this PR makes no model-correctness or performance claim.

The earlier draft included GPU registrations. Those were removed after a device-reference check failed; CUDA/HIP source and the grouped device fixture now match the upstream base. The original failure and its rounding analysis are documented in IQ_DOWN_EXACT.md, along with the CPU test details.

AI assistance was used for implementation, testing and review.


🔄 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/Niko1221/Strata/pull/4046 **Author:** [@CrashxZ](https://github.com/CrashxZ) **Created:** 10/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/iq-down-reference-order` --- ### 📝 Commits (2) - [`1bedc77`](https://github.com/Niko1221/Strata/commit/1bedc77d7e46840a618044df48a19664e9c3de92) feat(cpu): add opt-in exact mixed-IQ native down dispatch - [`3cbfd25`](https://github.com/Niko1221/Strata/commit/3cbfd2577f02ebeaceacfae530331b6ea819ee12) refactor: scope mixed-IQ down port to exact CPU dispatch ### 📊 Changes **6 files changed** (+457 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `docs/IQ_DOWN_EXACT.md` (+98 -0) 📝 `src/kernels/cpu/native_expert.cpp` (+19 -0) ➕ `tools/iq_down_dispatch_test.cpp` (+110 -0) ➕ `tools/iq_down_exact_test.cpp` (+125 -0) ➕ `tools/test_iq_down_dispatch.py` (+47 -0) ➕ `tools/test_iq_down_exact.py` (+58 -0) </details> ### 📄 Description This adds an opt-in CPU down-projection path for the 2048/512 mixed-IQ layout: IQ2_S gate/up with IQ2_S or IQ3_S down. It reuses upstream's `iq256x_rows` API to decode weights once across multiple tokens while keeping reference-order dot products. Set `STRATA_IQ_DOWN_EXACT=1` before startup to enable it. The default path is unchanged. The dispatcher checks the runtime and compiled GGML ISA, quantization types, contiguous layout and token width (2–8). Unsupported cases fall back; `STRATA_NO_IQ256` and `STRATA_IQ_MT_MIN` still apply. This came out of the [MoEmentum low-VRAM inference work](https://github.com/CrashxZ/MoEmentum). The exact-row arithmetic already exists upstream; this PR wires it into the native CPU dispatcher and adds regression tests. ## Tests Tested on Linux with GCC/G++ 15.2.0 and AVX2/FMA/F16C, against llama.cpp `3cf03257f219afbe7334045ff7c6a06ac68c627d`: - 384 routing and argument-forwarding checks passed. - 10,368 public exact-row comparisons passed bitwise. - 1,179,648 native comparisons passed bitwise in each mode, enabled and disabled. - ASan/UBSan passed for the project translation units. A separate run instrumenting external GGML reported signed-shift warnings in unchanged dependency code. To reproduce, point `$LLAMA` at that llama.cpp checkout and use fresh output directories: ```sh python3 tools/test_iq_down_dispatch.py --llama-dir "$LLAMA" --output "$OUT/dispatch" python3 tools/test_iq_down_exact.py --llama-dir "$LLAMA" --output "$OUT/exact" ``` ## Limits These are kernel and dispatch tests, not full-model validation or a speed benchmark. The option stays off by default, and this PR makes no model-correctness or performance claim. The earlier draft included GPU registrations. Those were removed after a device-reference check failed; CUDA/HIP source and the grouped device fixture now match the upstream base. The original failure and its rounding analysis are documented in [IQ_DOWN_EXACT.md](https://github.com/CrashxZ/MoEmentum/blob/pr/iq-down-reference-order/docs/IQ_DOWN_EXACT.md), along with the CPU test details. AI assistance was used for implementation, testing and review. --- <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 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
Niko1221/Strata#4888
No description provided.