[PR #2020] [CLOSED] prefill: gfx11 F16 matrix-core routed experts (opt-in STRATA_PF_F16=1): prompt +10-14% on gfx1151 #3812

Closed
opened 2026-11-07 15:30:56 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2020
Author: @libratechw
Created: 10/12/2026
Status: ❌ Closed

Base: main ← Head: pr/f16-experts


📝 Commits (2)

  • 13b30a4 prefill: the routed experts on gfx11's F16 matrix cores (opt-in STRATA_PF_F16=1)
  • ae38fd5 docs: STRATA_PF_F16=1 on gfx1151 (what it covers, the layer and prompt times, first-token KL)

📊 Changes

7 files changed (+868 additions, -10 deletions)

View changed files

📝 CMakeLists.txt (+9 -1)
📝 docs/STRIX_HALO.md (+9 -0)
➕ src/prefill/moe_f16_common.cuh (+250 -0)
➕ src/prefill/moe_f16_kq.cu (+345 -0)
➕ src/prefill/moe_f16_kq.hpp (+43 -0)
📝 src/prefill/moe_fused_iq.cu (+183 -6)
📝 tests/cuda/prefill_fused_iq_test.cpp (+29 -3)

📄 Description

Title

Issue: Refs #1258

Summary

With STRATA_PF_FUSED=1 the routed experts of a prompt run on gfx11's int8 matrix cores, each weight sub-block decoded to int8
with a per-block epilogue. STRATA_PF_F16=1 runs the covered formats on the F16 matrix cores instead: the codes stay packed in
LDS, each wave turns its own rows into F16, and the F16 WMMA accumulates all of K in FP32. The K-quant kernels adapt gufo's
RoutedF16GEMMKernel (97b8645f, MIT; attribution and licence text at the top of both new files). The output differs from the
int8 kernels', so it is off by default; gfx12 keeps the int8 kernels.

What changed

  • src/prefill/moe_f16_common.cuh (new): the switch, the work item, the activations staged as F16, the WMMA loop, the two
    epilogues.
  • src/prefill/moe_f16_kq.cu/.hpp (new): Q4_K / Q5_K gate/up and Q5_1 down (with STRATA_PF_FUSED_KQ=1). They read the
    weights 16 / 8 bytes at a time, so each of gate/up and down takes them only when the batch's blobs, offsets and row
    strides are aligned to that (the native blobs are promised 2 bytes); otherwise that half stays on its int8 kernel. gfx906,
    whose build leaves this file out, covers nothing here.
  • src/prefill/moe_fused_iq.cu: native_f16_kernel for IQ2_XXS / IQ2_XS / IQ2_S / IQ3_XXS / IQ3_S / IQ4_XS gate/up and Q2_0 /
    IQ4_NL / Q8_0 down (through the existing 16-bit loads), and the dispatch.
  • tests/cuda/prefill_fused_iq_test.cpp, CMakeLists.txt: with STRATA_PF_F16=1 on a gfx11 device the test allows 5e-3
    against the int8 model and MMQ (measured 2.7e-3) and places the blobs 256-byte aligned, so the F16 kernels are what it
    checks; elsewhere the int8 limits stay. ctest hip_prefill_fused_iq_f16 runs the default pairs with the switch,
    hip_prefill_fused_iq_f16_kq the four K-quant pairs (it sets STRATA_PF_FUSED_KQ=1 too).
  • docs/STRIX_HALO.md: what it covers, the layer and prompt times, first-token KL.

Ryzen AI Max+ 395 (gfx1151, ROCm 7.14.1, Linux), on 296b59d2. One layer, hip_prefill_fused_iq, 16,384 tokens, top 10 over
512 experts, median of 3:

gate/up / down int8 kernels, ms F16, ms
Q4_K / Q5_1 (UD-Q4_K_XL) 86.4 53.7 (-38%)
Q4_K / Q8_0 85.9 53.5 (-38%)
IQ3_S / IQ4_NL (UD-IQ4_XS) 79.8 58.2 (-27%)

Prompt tok/s, the branch's binary without and with STRATA_PF_F16=1, --serve --prefill 16384 --spec 4, the section-5
switches with STRATA_PF_SWITCH_MIN_T=2048 (UD-Q4_K_XL also STRATA_PF_FUSED_KQ=1), a chat request of 4K / 32K tokens,
fresh servers alternating, 5 pairs after dropping those with page migration or reclaim; median tok/s and the median of the
pair ratios, every pair faster:

4K 32K
UD-Q4_K_XL 1,129 -> 1,294 (+14.4%) 1,249 -> 1,422 (+13.9%)
UD-IQ4_XS 1,114 -> 1,269 (+13.5%) 1,266 -> 1,389 (+9.9%)

The UD-Q4_K_XL 32K cell is of this code; the layer times and the other three cells are of an earlier head with the same
kernels (before the alignment check and the test changes). Without the switch, the layer's output hashes (six pairs, 2,048
and 16,384 tokens) are 296b59d2's.

First-token KL against a run with no switches, 12 natural-text chat requests of 1.5K-24K tokens, mean (median); the fast arms
with STRATA_PF_SWITCH_MIN_T=0; the top token is the same in 12 of 12 in every arm:

section-5 switches + int8 fused experts + STRATA_PF_F16=1
UD-Q4_K_XL 0.0065 (0.0017) 0.0114 (0.0048)
UD-IQ4_XS 0.0076 (0.0035) 0.0104 (0.0057)

F16 moves further from the default than the int8 path, so this stays opt-in. The records and scripts are in
libratechw/Strata@e5d05554, 2020/.

Builds and tests:

  • HIP gfx1151, this head: ctest, 114 tests: 106 pass (the three hip_prefill_fused_iq* among them), 5 skip, and the same
    three fail as on 296b59d2 (ple_parity, expert_parity, pool_test).
  • HIP: moe_fused_iq.cu and moe_f16_kq.cu compile for gfx1012, gfx1030, gfx1100, gfx1103, gfx1150, gfx1151, gfx1200 and
    gfx1201 (77506be1; the head changes neither file). gfx906: moe_fused_iq.cu no longer leaves the f16kq functions
    undefined (it did at 77506be1); the whole gfx906 build stops earlier, at mmq_nvfp4_w4a4.cu (ggml's vendors/cuda.h),
    which this branch does not touch.
  • CUDA 13.0, RTX 3060 (Windows), 77506be1 (the head's changes since are in a header CUDA does not include, a HIP ctest, a
    test comment and the doc): builds; ctest, 117 tests: 114 pass, 2 skip, and ple_parity fails as on 296b59d2.
  • SYCL: not affected (the SYCL experts are their own files).

Not run: other gfx11 cards (gfx1100-1103, gfx1150), and quality beyond the first-token KL.

🤖 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/2020 **Author:** [@libratechw](https://github.com/libratechw) **Created:** 10/12/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/f16-experts` --- ### 📝 Commits (2) - [`13b30a4`](https://github.com/Niko1221/Strata/commit/13b30a4dfc755a89069eb0233687dae320fcb0ca) prefill: the routed experts on gfx11's F16 matrix cores (opt-in STRATA_PF_F16=1) - [`ae38fd5`](https://github.com/Niko1221/Strata/commit/ae38fd57edb92f29e7ae102a023034b1ade1d2f3) docs: STRATA_PF_F16=1 on gfx1151 (what it covers, the layer and prompt times, first-token KL) ### 📊 Changes **7 files changed** (+868 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+9 -1) 📝 `docs/STRIX_HALO.md` (+9 -0) ➕ `src/prefill/moe_f16_common.cuh` (+250 -0) ➕ `src/prefill/moe_f16_kq.cu` (+345 -0) ➕ `src/prefill/moe_f16_kq.hpp` (+43 -0) 📝 `src/prefill/moe_fused_iq.cu` (+183 -6) 📝 `tests/cuda/prefill_fused_iq_test.cpp` (+29 -3) </details> ### 📄 Description ## Title Issue: Refs #1258 ## Summary With `STRATA_PF_FUSED=1` the routed experts of a prompt run on gfx11's int8 matrix cores, each weight sub-block decoded to int8 with a per-block epilogue. `STRATA_PF_F16=1` runs the covered formats on the F16 matrix cores instead: the codes stay packed in LDS, each wave turns its own rows into F16, and the F16 WMMA accumulates all of K in FP32. The K-quant kernels adapt gufo's `RoutedF16GEMMKernel` (97b8645f, MIT; attribution and licence text at the top of both new files). The output differs from the int8 kernels', so it is off by default; gfx12 keeps the int8 kernels. ## What changed - `src/prefill/moe_f16_common.cuh` (new): the switch, the work item, the activations staged as F16, the WMMA loop, the two epilogues. - `src/prefill/moe_f16_kq.cu/.hpp` (new): Q4_K / Q5_K gate/up and Q5_1 down (with `STRATA_PF_FUSED_KQ=1`). They read the weights 16 / 8 bytes at a time, so each of gate/up and down takes them only when the batch's blobs, offsets and row strides are aligned to that (the native blobs are promised 2 bytes); otherwise that half stays on its int8 kernel. gfx906, whose build leaves this file out, covers nothing here. - `src/prefill/moe_fused_iq.cu`: `native_f16_kernel` for IQ2_XXS / IQ2_XS / IQ2_S / IQ3_XXS / IQ3_S / IQ4_XS gate/up and Q2_0 / IQ4_NL / Q8_0 down (through the existing 16-bit loads), and the dispatch. - `tests/cuda/prefill_fused_iq_test.cpp`, `CMakeLists.txt`: with `STRATA_PF_F16=1` on a gfx11 device the test allows 5e-3 against the int8 model and MMQ (measured 2.7e-3) and places the blobs 256-byte aligned, so the F16 kernels are what it checks; elsewhere the int8 limits stay. ctest `hip_prefill_fused_iq_f16` runs the default pairs with the switch, `hip_prefill_fused_iq_f16_kq` the four K-quant pairs (it sets `STRATA_PF_FUSED_KQ=1` too). - `docs/STRIX_HALO.md`: what it covers, the layer and prompt times, first-token KL. Ryzen AI Max+ 395 (gfx1151, ROCm 7.14.1, Linux), on 296b59d2. One layer, `hip_prefill_fused_iq`, 16,384 tokens, top 10 over 512 experts, median of 3: | gate/up / down | int8 kernels, ms | F16, ms | |---|---:|---:| | Q4_K / Q5_1 (UD-Q4_K_XL) | 86.4 | 53.7 (-38%) | | Q4_K / Q8_0 | 85.9 | 53.5 (-38%) | | IQ3_S / IQ4_NL (UD-IQ4_XS) | 79.8 | 58.2 (-27%) | Prompt tok/s, the branch's binary without and with `STRATA_PF_F16=1`, `--serve --prefill 16384 --spec 4`, the section-5 switches with `STRATA_PF_SWITCH_MIN_T=2048` (UD-Q4_K_XL also `STRATA_PF_FUSED_KQ=1`), a chat request of 4K / 32K tokens, fresh servers alternating, 5 pairs after dropping those with page migration or reclaim; median tok/s and the median of the pair ratios, every pair faster: | | 4K | 32K | |---|---:|---:| | UD-Q4_K_XL | 1,129 -> 1,294 (+14.4%) | 1,249 -> 1,422 (+13.9%) | | UD-IQ4_XS | 1,114 -> 1,269 (+13.5%) | 1,266 -> 1,389 (+9.9%) | The UD-Q4_K_XL 32K cell is of this code; the layer times and the other three cells are of an earlier head with the same kernels (before the alignment check and the test changes). Without the switch, the layer's output hashes (six pairs, 2,048 and 16,384 tokens) are 296b59d2's. First-token KL against a run with no switches, 12 natural-text chat requests of 1.5K-24K tokens, mean (median); the fast arms with `STRATA_PF_SWITCH_MIN_T=0`; the top token is the same in 12 of 12 in every arm: | | section-5 switches + int8 fused experts | + `STRATA_PF_F16=1` | |---|---:|---:| | UD-Q4_K_XL | 0.0065 (0.0017) | 0.0114 (0.0048) | | UD-IQ4_XS | 0.0076 (0.0035) | 0.0104 (0.0057) | F16 moves further from the default than the int8 path, so this stays opt-in. The records and scripts are in [libratechw/Strata@e5d05554, `2020/`](https://github.com/libratechw/Strata/tree/e5d0555410983415288228c096fdb1fbabb01df7/2020). Builds and tests: - HIP gfx1151, this head: ctest, 114 tests: 106 pass (the three `hip_prefill_fused_iq*` among them), 5 skip, and the same three fail as on 296b59d2 (`ple_parity`, `expert_parity`, `pool_test`). - HIP: `moe_fused_iq.cu` and `moe_f16_kq.cu` compile for gfx1012, gfx1030, gfx1100, gfx1103, gfx1150, gfx1151, gfx1200 and gfx1201 (77506be1; the head changes neither file). gfx906: `moe_fused_iq.cu` no longer leaves the `f16kq` functions undefined (it did at 77506be1); the whole gfx906 build stops earlier, at `mmq_nvfp4_w4a4.cu` (ggml's `vendors/cuda.h`), which this branch does not touch. - CUDA 13.0, RTX 3060 (Windows), 77506be1 (the head's changes since are in a header CUDA does not include, a HIP ctest, a test comment and the doc): builds; ctest, 117 tests: 114 pass, 2 skip, and `ple_parity` fails as on 296b59d2. - SYCL: not affected (the SYCL experts are their own files). Not run: other gfx11 cards (gfx1100-1103, gfx1150), and quality beyond the first-token KL. 🤖 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>
bsakaguchi 2026-11-07 15:30:56 +07:00
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#3812
No description provided.