[PR #5476] [Engine] gfx103x decode: opt-in one-warp MMVQ for K <= 4096 and a per-format expert layout table (STRATA_MMVQ_NW1, STRATA_EXP_TABLE) #5453

Open
opened 2026-11-07 19:36:07 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5476
Author: @Vop3p
Created: 11/7/2026
Status: 🔄 Open

Base: main ← Head: pr/gfx103x-decode-tables


📝 Commits (1)

  • ca4a88d gfx103x decode: opt-in one-warp MMVQ for K <= 4096 (STRATA_MMVQ_NW1) and a per-format expert layout table (STRATA_EXP_TABLE)

📊 Changes

2 files changed (+23 additions, -1 deletions)

View changed files

📝 src/kernels/cuda/iq_kernels.cu (+14 -1)
📝 src/kernels/cuda/native_mmvq.cu (+9 -0)

📄 Description

Problem and result

Two decode-window kernel choices on gfx1030 (RX 6900 XT). Both pick code that is already in the tree; neither adds a kernel.

  1. STRATA_MMVQ_NW1=1: launch_multi_n launches the dense multi-column MMVQ (qkv / gate / q / shared expert at T = 2..4) with 4 warps and 2 rows per block. On gfx1030 with cold weights, the existing template native_mmvq_multi_kernel<F, NCOLS, 1, 1> (one warp, one row per block) is faster for K <= 4096. The opt-in only changes the dispatch, and K = 6144 (out) keeps the default. Kernel times, same binary off/on:
matrix T = 2 T = 3 T = 4
qkv Q6_K 54.2 -> 49.3 us 57.1 -> 51.4 63.1 -> 53.9
qkv Q5_K 50.0 -> 44.6 75.4 -> 45.7 88.5 -> 51.5
gate Q4_K 30.5 -> 26.5 37.5 -> 28.0 49.8 -> 30.8
q Q6_K 63.0 -> 59.5 66.4 -> 59.6 74.3 -> 62.8
shared expert 5.4 -> 4.7 6.4 -> 5.3 8.3 -> 5.9

Not bitwise: one warp per row sums in a different order, with a relative difference < 1e-5.

  1. STRATA_EXP_TABLE=1: native_expert_grouped has one exp_mode() for every format, but on gfx1030 the best existing layout depends on the format. A sweep of modes 2..8 against mode 0 with native_expert_bench (every result bitwise equal) found gate/up IQ2_S and IQ3_S fastest at mode 8 and down Q2_0 fastest at mode 4. IQ3_XXS gate/up and IQ4_NL down are fastest at mode 0; IQ4_NL down is 7-15% slower at mode 8. No single global mode works, so the table picks per format and leaves every other format at the card's default. A strided call (grid_groups < cap_groups) and an explicit STRATA_EXP_MODE keep their layout. Bitwise identical to mode 0.

    The verifier calls native_expert_grouped with cap = n x top-k (n = window tokens), and the real group count is only on the device. So the table was measured at that cap (BENCH_CAP) over the possible group shapes, for a whole layer's expert step, against mode 0:

groups in the window IQ2_S gate/up + Q2_0 down layer IQ3_S gate/up + IQ4_NL down layer
every group 1 token (no overlap) -27 .. -30% -8 .. -10%
groups of 2 -8 .. -11% -2 .. -5%
3 tokens share every expert (G 10, T 3) 0% +0.4%
4 tokens share every expert (G 10, T 4) +6.3% +5.5%

Full overlap is rare in real decoding. In 266K recorded verify-window routings from our production runs, 59% of windows have 3 tokens, with a median of 23 distinct expert groups out of a possible 30. Of the entries in those windows, 57% sit in a group of 1, 30% in a group of 2 and 13% in a group of 3. 25% of windows have 1 token, 15% have 2, and 1.3% have 4 or 5.

End to end, 2x RX 6900 XT, 10 cold-start interleaved pairs, both variables off vs on, same binary:

off (median) on (median) paired difference (median) pairs faster range
decode 32K, ms per window 27.09 26.16 -3.4% 10/10 -3.8 .. -3.0%
decode 4K, ms per window 28.35 28.17 -0.6% 10/10 -0.8 .. -0.4%
decode 32K, tok/s 75.0 77.0 +2.7% 10/10 +2.3 .. +3.2%
prompt 32K, tok/s 1,771 1,778 +0.4% 0.0 .. +1.0%

The output text differs from off (MMVQ_NW1 is not bitwise), but each arm produced the same text in all 10 runs, and the number of windows was within one (122/122 at 4K, 126/127 at 32K), so tok/s here is a fair measure.

none (opt-in kernel selections between existing kernels and layouts, measured on one architecture)

Approach

  • Opt-in rather than a gfx103x default, because both were measured on one chip (two boards of the RX 6900 XT). For the table, the full-overlap case is up to 6% slower. That is rare in decoding, but it is a real regression for that shape.
  • MMVQ_NW1: a static env check in launch_multi_n after the existing b6_launch hook, and only for n_in <= 4096.
  • EXP_TABLE: a static env check that is ignored when STRATA_EXP_MODE is set. gate/up mode 8 for gu_type IQ2_S (22) / IQ3_S (21), down mode 4 for d_type Q2_0 (42), otherwise the existing choice. It is skipped for strided calls, like the existing CUDA-layout rule above it, and not compiled for gfx906.

Validation

Environment: 2x RX 6900 XT (gfx1030, 16 GB, PCIe 4.0 x8 each), Ryzen 5 5600X, 128 GB DDR4-3200, Ubuntu 26.04, kernel 7.0.0-42, ROCm 10.0 runtime (/opt/rocm/lib).

Passed:

  • Build: main 54828c7e + this change, -DSTRATA_ENABLE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx1030 -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_PREFILL_MMQ=ON -DSTRATA_Q6K_EXPERTS=ON -DGGML_HIP_GRAPHS=ON -DGGML_HIP_NO_VMM=ON -DSTRATA_BUILD_TESTS=ON.
  • native_expert_bench at the verifier's cap: 33 shape/layer/mode combinations, all bitwise equal to mode 0 (layers 1 and 17, one card, 50 iterations).
  • The MMVQ microbenchmark (the table in item 1), off/on, built from our production tree with the same change (a small harness around launch_multi_n, not part of this PR).
  • ctest -j 1: 221/224. The three failures are the same on main 54828c7e without this change: ple_parity (Q2_0 gguf relative path), conversation_copy_streams_test (148 MiB first copy stream) and isa_guard_check (CPU iq512 function).
  • End to end: the table above. IQ3_S pack, two-card layer split at 27, --spec 3 --spec-min-p 0.6 --pipeline-windows 1 --kv int8, parallel 1, our usual HIP env. benchmark.py 4K + 32K, 256 tokens each, arms alternating. 0 stalls.

Failed:

  • none observed

Not run:

  • CUDA / SYCL / Metal. STRATA_MMVQ_NW1 is not behind a HIP #if: if set on CUDA, it would also take the one-warp template. That path is untested there. Tell me if you want it limited to HIP.
  • Other gfx103x chips and other RDNA generations. The table is format-specific and measured on gfx1030 only.
  • A quality run. EXP_TABLE is bitwise. MMVQ_NW1 changes the summation order (< 1e-5 relative), and I did not run KL for it.

Limits

  • Most of the gain shows up at 32K, where the window carries more T >= 2 dense GEMVs and expert groups. At 4K it is -0.6% per window.
  • The table's choice is by format only. The verifier passes cap and not the real group count, so a per-shape choice would need device-side dispatch. I did not do that because full overlap is rare.

Developed with an AI coding assistant; every number above was measured on the machine described in Validation.

🤖 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/Niko1221/Strata/pull/5476 **Author:** [@Vop3p](https://github.com/Vop3p) **Created:** 11/7/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/gfx103x-decode-tables` --- ### 📝 Commits (1) - [`ca4a88d`](https://github.com/Niko1221/Strata/commit/ca4a88d6c4b72543ef6d72790ec90a89d15cefbd) gfx103x decode: opt-in one-warp MMVQ for K <= 4096 (STRATA_MMVQ_NW1) and a per-format expert layout table (STRATA_EXP_TABLE) ### 📊 Changes **2 files changed** (+23 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/kernels/cuda/iq_kernels.cu` (+14 -1) 📝 `src/kernels/cuda/native_mmvq.cu` (+9 -0) </details> ### 📄 Description ## Problem and result Two decode-window kernel choices on gfx1030 (RX 6900 XT). Both pick code that is already in the tree; neither adds a kernel. 1. **`STRATA_MMVQ_NW1=1`**: `launch_multi_n` launches the dense multi-column MMVQ (qkv / gate / q / shared expert at T = 2..4) with 4 warps and 2 rows per block. On gfx1030 with cold weights, the existing template `native_mmvq_multi_kernel<F, NCOLS, 1, 1>` (one warp, one row per block) is faster for K <= 4096. The opt-in only changes the dispatch, and K = 6144 (`out`) keeps the default. Kernel times, same binary off/on: | matrix | T = 2 | T = 3 | T = 4 | |---|---|---|---| | qkv Q6_K | 54.2 -> 49.3 us | 57.1 -> 51.4 | 63.1 -> 53.9 | | qkv Q5_K | 50.0 -> 44.6 | 75.4 -> 45.7 | 88.5 -> 51.5 | | gate Q4_K | 30.5 -> 26.5 | 37.5 -> 28.0 | 49.8 -> 30.8 | | q Q6_K | 63.0 -> 59.5 | 66.4 -> 59.6 | 74.3 -> 62.8 | | shared expert | 5.4 -> 4.7 | 6.4 -> 5.3 | 8.3 -> 5.9 | Not bitwise: one warp per row sums in a different order, with a relative difference < 1e-5. 2. **`STRATA_EXP_TABLE=1`**: `native_expert_grouped` has one `exp_mode()` for every format, but on gfx1030 the best existing layout depends on the format. A sweep of modes 2..8 against mode 0 with `native_expert_bench` (every result bitwise equal) found gate/up IQ2_S and IQ3_S fastest at mode 8 and down Q2_0 fastest at mode 4. IQ3_XXS gate/up and IQ4_NL down are fastest at mode 0; IQ4_NL down is 7-15% slower at mode 8. No single global mode works, so the table picks per format and leaves every other format at the card's default. A strided call (`grid_groups < cap_groups`) and an explicit `STRATA_EXP_MODE` keep their layout. **Bitwise identical** to mode 0. The verifier calls `native_expert_grouped` with cap = n x top-k (n = window tokens), and the real group count is only on the device. So the table was measured at that cap (`BENCH_CAP`) over the possible group shapes, for a whole layer's expert step, against mode 0: | groups in the window | IQ2_S gate/up + Q2_0 down layer | IQ3_S gate/up + IQ4_NL down layer | |---|---|---| | every group 1 token (no overlap) | -27 .. -30% | -8 .. -10% | | groups of 2 | -8 .. -11% | -2 .. -5% | | 3 tokens share every expert (G 10, T 3) | 0% | +0.4% | | 4 tokens share every expert (G 10, T 4) | +6.3% | +5.5% | Full overlap is rare in real decoding. In 266K recorded verify-window routings from our production runs, 59% of windows have 3 tokens, with a median of 23 distinct expert groups out of a possible 30. Of the entries in those windows, 57% sit in a group of 1, 30% in a group of 2 and 13% in a group of 3. 25% of windows have 1 token, 15% have 2, and 1.3% have 4 or 5. End to end, 2x RX 6900 XT, 10 cold-start interleaved pairs, both variables off vs on, same binary: | | off (median) | on (median) | paired difference (median) | pairs faster | range | |---|---|---|---|---|---| | decode 32K, ms per window | 27.09 | 26.16 | **-3.4%** | 10/10 | -3.8 .. -3.0% | | decode 4K, ms per window | 28.35 | 28.17 | -0.6% | 10/10 | -0.8 .. -0.4% | | decode 32K, tok/s | 75.0 | 77.0 | +2.7% | 10/10 | +2.3 .. +3.2% | | prompt 32K, tok/s | 1,771 | 1,778 | +0.4% | | 0.0 .. +1.0% | The output text differs from off (MMVQ_NW1 is not bitwise), but each arm produced the same text in all 10 runs, and the number of windows was within one (122/122 at 4K, 126/127 at 32K), so tok/s here is a fair measure. ## Related discussion none (opt-in kernel selections between existing kernels and layouts, measured on one architecture) ## Approach - Opt-in rather than a gfx103x default, because both were measured on one chip (two boards of the RX 6900 XT). For the table, the full-overlap case is up to 6% slower. That is rare in decoding, but it is a real regression for that shape. - `MMVQ_NW1`: a static env check in `launch_multi_n` after the existing `b6_launch` hook, and only for `n_in <= 4096`. - `EXP_TABLE`: a static env check that is ignored when `STRATA_EXP_MODE` is set. gate/up mode 8 for `gu_type` IQ2_S (22) / IQ3_S (21), down mode 4 for `d_type` Q2_0 (42), otherwise the existing choice. It is skipped for strided calls, like the existing CUDA-layout rule above it, and not compiled for gfx906. ## Validation Environment: 2x RX 6900 XT (gfx1030, 16 GB, PCIe 4.0 x8 each), Ryzen 5 5600X, 128 GB DDR4-3200, Ubuntu 26.04, kernel 7.0.0-42, ROCm 10.0 runtime (`/opt/rocm/lib`). **Passed:** - Build: main 54828c7e + this change, `-DSTRATA_ENABLE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx1030 -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_PREFILL_MMQ=ON -DSTRATA_Q6K_EXPERTS=ON -DGGML_HIP_GRAPHS=ON -DGGML_HIP_NO_VMM=ON -DSTRATA_BUILD_TESTS=ON`. - `native_expert_bench` at the verifier's cap: 33 shape/layer/mode combinations, all bitwise equal to mode 0 (layers 1 and 17, one card, 50 iterations). - The MMVQ microbenchmark (the table in item 1), off/on, built from our production tree with the same change (a small harness around `launch_multi_n`, not part of this PR). - `ctest -j 1`: 221/224. The three failures are the same on main 54828c7e without this change: `ple_parity` (Q2_0 gguf relative path), `conversation_copy_streams_test` (148 MiB first copy stream) and `isa_guard_check` (CPU iq512 function). - End to end: the table above. IQ3_S pack, two-card layer split at 27, `--spec 3 --spec-min-p 0.6 --pipeline-windows 1 --kv int8`, parallel 1, our usual HIP env. `benchmark.py` 4K + 32K, 256 tokens each, arms alternating. 0 stalls. **Failed:** - none observed **Not run:** - CUDA / SYCL / Metal. `STRATA_MMVQ_NW1` is not behind a HIP `#if`: if set on CUDA, it would also take the one-warp template. That path is untested there. Tell me if you want it limited to HIP. - Other gfx103x chips and other RDNA generations. The table is format-specific and measured on gfx1030 only. - A quality run. `EXP_TABLE` is bitwise. `MMVQ_NW1` changes the summation order (< 1e-5 relative), and I did not run KL for it. ## Limits - Most of the gain shows up at 32K, where the window carries more T >= 2 dense GEMVs and expert groups. At 4K it is -0.6% per window. - The table's choice is by format only. The verifier passes cap and not the real group count, so a per-shape choice would need device-side dispatch. I did not do that because full overlap is rare. --- Developed with an AI coding assistant; every number above was measured on the machine described in Validation. 🤖 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 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#5453
No description provided.