[PR #560] iq_mmvq: read each weight block once per batch (block index outermost), +20% prefill on IQ experts #596

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/560
Author: @precisionailabsllc-collab
Created: 10/27/2026
Status: 🔄 Open

Base: main ← Head: pr/iq-mmvq-batched


📝 Commits (1)

  • 058f927 iq_mmvq: read each weight block once per batch (block index outermost)

📊 Changes

3 files changed (+193 additions, -10 deletions)

View changed files

📝 CMakeLists.txt (+8 -0)
📝 src/kernels/cuda/iq_kernels.cu (+78 -10)
➕ tests/iq_mmvq_parity_test.cu (+107 -0)

📄 Description

What

iq_mmvq called row_dot() once per activation column, and row_dot() re-reads and re-dequantises the
same weight bytes each time. A k-column batch therefore paid the weight traffic k times.

This makes the block index the outer loop, so one weight block is loaded and decoded once and applied to
every column:

for (int k = lane; k < nb * F.ipb; k += 32) {          // one block, once
    const block_q8_1* base = x + kbx * (F.qk / 32);
    for (int c = 0; c < NC; ++c) s[c] += F::dot(row, base + c * xb, kbx, iqs);
}

Widths are grouped NC at a time (8, then 4, then 2) with the single-column form for the tail, so any
ncols works. ncols == 1 keeps the existing kernel untouched, so decode is unaffected.

It is a scheduling change, not an arithmetic one

The per-lane accumulation order is identical (same k, same stride) and the warp reduction is the same
warp_sum, so each column is bit-identical to the single-column call.

tests/iq_mmvq_parity_test.cu (new, registered in ctest) checks that over all 10 supported IQ formats
(16, 17, 18, 19, 20, 21, 22, 23, 29, 42) x 9 widths (1, 2, 3, 4, 5, 7, 8, 9, 16), comparing raw bits:

iq_mmvq parity: 90 format/width combinations, 0 numerically different,
                1 differing only in a NaN sign bit
OK

The single NaN-sign case is IQ1_M at 16 columns on the random-byte fixture: random fp16 scales go NaN and
IEEE leaves a NaN's sign to the implementation. It is not a numeric difference and cannot arise from real
quantised weights. The test's pass criterion is value equality with NaN treated as equal to NaN; the strict
bit count is reported separately.

Effect

Measured on a Radeon 8060S (gfx1151, ROCm 7.15), single GPU, with a MiniMax-M3.1-Flash expert pack whose
routed experts are IQ1_M / IQ2_XS / IQ2_XXS (so they go through this kernel):

prefill, 501-token prompt
before 23.6 s (21.2 tok/s)
after 18.9 s (26.4 tok/s)

+20% on prefill, which is where a batch actually has several columns per expert. Anything with IQ-type
weights and a multi-token prompt should see the same shape of gain; the win scales with how many columns
share a weight block.

Scope

  • Only src/kernels/cuda/iq_kernels.cu, plus the new test and its CMake entry.
  • iq_mmvq's public signature is unchanged; no caller changes.
  • The single-column path is byte-for-byte the old 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/560 **Author:** [@precisionailabsllc-collab](https://github.com/precisionailabsllc-collab) **Created:** 10/27/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/iq-mmvq-batched` --- ### 📝 Commits (1) - [`058f927`](https://github.com/mw00/project-maya/commit/058f927c9c31996d003966a7479c3b122f80909a) iq_mmvq: read each weight block once per batch (block index outermost) ### 📊 Changes **3 files changed** (+193 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+8 -0) 📝 `src/kernels/cuda/iq_kernels.cu` (+78 -10) ➕ `tests/iq_mmvq_parity_test.cu` (+107 -0) </details> ### 📄 Description ## What `iq_mmvq` called `row_dot()` once per activation column, and `row_dot()` re-reads and re-dequantises the **same weight bytes** each time. A `k`-column batch therefore paid the weight traffic `k` times. This makes the block index the **outer** loop, so one weight block is loaded and decoded once and applied to every column: ```cuda for (int k = lane; k < nb * F.ipb; k += 32) { // one block, once const block_q8_1* base = x + kbx * (F.qk / 32); for (int c = 0; c < NC; ++c) s[c] += F::dot(row, base + c * xb, kbx, iqs); } ``` Widths are grouped `NC` at a time (8, then 4, then 2) with the single-column form for the tail, so any `ncols` works. `ncols == 1` keeps the existing kernel untouched, so **decode is unaffected**. ## It is a scheduling change, not an arithmetic one The per-lane accumulation order is identical (same `k`, same stride) and the warp reduction is the same `warp_sum`, so each column is bit-identical to the single-column call. `tests/iq_mmvq_parity_test.cu` (new, registered in ctest) checks that over **all 10 supported IQ formats** (16, 17, 18, 19, 20, 21, 22, 23, 29, 42) x **9 widths** (1, 2, 3, 4, 5, 7, 8, 9, 16), comparing raw bits: ``` iq_mmvq parity: 90 format/width combinations, 0 numerically different, 1 differing only in a NaN sign bit OK ``` The single NaN-sign case is IQ1_M at 16 columns on the random-byte fixture: random fp16 scales go NaN and IEEE leaves a NaN's sign to the implementation. It is not a numeric difference and cannot arise from real quantised weights. The test's pass criterion is value equality with NaN treated as equal to NaN; the strict bit count is reported separately. ## Effect Measured on a **Radeon 8060S (gfx1151, ROCm 7.15)**, single GPU, with a MiniMax-M3.1-Flash expert pack whose routed experts are IQ1_M / IQ2_XS / IQ2_XXS (so they go through this kernel): | | prefill, 501-token prompt | |---|---| | before | 23.6 s (21.2 tok/s) | | after | **18.9 s (26.4 tok/s)** | +20% on prefill, which is where a batch actually has several columns per expert. Anything with IQ-type weights and a multi-token prompt should see the same shape of gain; the win scales with how many columns share a weight block. ## Scope - Only `src/kernels/cuda/iq_kernels.cu`, plus the new test and its CMake entry. - `iq_mmvq`'s public signature is unchanged; no caller changes. - The single-column path is byte-for-byte the old 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#596
No description provided.