[PR #5474] [Engine] HIP prompt path: opt-in FP16 reads of the hc up projection and attn_qkv (STRATA_F16_NOWIDEN) and the fused SwiGLU + Q8 pass on HIP (STRATA_SWIGLU_Q8) #5452

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/5474
Author: @Vop3p
Created: 11/7/2026
Status: 🔄 Open

Base: main ← Head: pr/f16-nowiden-swiglu-q8


📝 Commits (1)

  • cf7decc HIP prompt path: opt-in FP16 reads of the hc up projection and attn_qkv (STRATA_F16_NOWIDEN), fused SwiGLU + Q8 on HIP (STRATA_SWIGLU_Q8)

📊 Changes

6 files changed (+211 additions, -26 deletions)

View changed files

📝 include/strata/prefill/gemm.hpp (+14 -0)
📝 include/strata/prefill/kernels.hpp (+6 -2)
📝 src/prefill/gemm.cu (+16 -0)
📝 src/prefill/kernels.cu (+52 -12)
📝 src/prefill/moe_mmq.cu (+17 -3)
📝 src/prefill/prefill.cpp (+106 -9)

📄 Description

Problem and result

With STRATA_HIP_PROMPT_F16=1 the prompt GEMMs run FP16 in and out, and f16_inplace then widens every FP16 product back to FP32 in place. On gfx1030 that widen pass is already at memory bandwidth (636-900 GB/s at N 1024-6144, 528 GB/s at N 10240 in a standalone kernel), so it cannot be made faster. It can only be skipped. In a 32K prompt trace it is ~4% of GPU time. About two thirds of it is two products whose only consumers can read FP16 directly: the hyper-connection up projection (hc_attn_up / hc_ffn_up, N 10240, read by gr_mix_r) and attn_qkv on the GDN layers (N 10240, read by the GDN conv kernels).

This PR has two opt-in parts, both bitwise identical to the default path:

  1. STRATA_F16_NOWIDEN=1 (new code): those two products stay FP16 and their consumers read halves. FP16 to FP32 is exact, so the values do not change; the conversion only moves into the consumer. gr_mix_r_kernel<G16> reads the up projection's FP16 rows. gdn_conv_kernel / gdn_conv_l2_kernel / gdn_conv_hist_kernel<H16> read attn_qkv in its row-slice layout (the native path computes it in slices of R columns). The request is made only where the conv kernel that reads FP16 runs (gdn_conv_f16_ok(): CONVL2=1, not serial, not CHUNKED). A product that goes through MMQ, PF_PAD or has no FP16 I/O reports R = 0 and keeps the widen.
  2. STRATA_SWIGLU_Q8=1 (enables an existing kernel on HIP): swiglu_quant_kernel in moe_mmq.cu already fuses SwiGLU with quantize_mmq_q8_1 for CUDA SM60 resident weights. HIP had it behind an #if ("not checked against the HIP quantizer"). This PR builds it for HIP (__shfl_xor at width 32) and uses it in the plain grouped expert path (both the whole-group and sliced call sites) when there is no tail scale and no Hadamard. The intermediate H no longer goes through memory.

Measured on 2x RX 6900 XT, 10 cold-start interleaved pairs, off vs on, same binary:

off (median) on (median) paired difference (median) pairs faster range
prompt 32K, tok/s 1,770 1,832 +3.5% 10/10 +2.1 .. +4.9%
prompt 8K, tok/s 1,336 1,380 +3.1% 7/10 -14.9 .. +15.9%
decode 32K, ms per window 27.22 27.22 0.0% -0.1 .. +1.1%

Output text is identical in all 10 pairs (8K and 32K). Decode does not use these paths. 8K prompt reads on this machine have a wide spread from run to run; 32K is the clean number.

none (opt-in, HIP prompt path only, bitwise identical to the default)

Approach

  • Opt-in because each part was measured on one chip (gfx1030). Neither changes a value, so making them the default where STRATA_HIP_PROMPT_F16=1 is on would be a one-line change if you prefer that.
  • Gemm gets keep_f16_once(n_full) / take_kept_f16() (up projection: one whole product) and keep_f16_slices_once(n_full) / take_kept_rows() (attn_qkv: every slice stays FP16, and the slice width is returned). f16_inplace skips the widen only for the product that was asked for, so every other GEMM is unchanged. The inject product shares the same Gemm, so the flag is taken back right after the up projection.
  • Self-checks that run the default path again and compare bit for bit: STRATA_F16_NOWIDEN_CHECK=N (mixed output of the hc read), STRATA_F16_NOWIDEN_QKV_CHECK=N (conv output; the conv history is saved and restored around the recomputation) and STRATA_SWIGLU_Q8_CHECK=N (the quantized H, 1152 bytes per row).
  • STRATA_F16_RANGE / STRATA_DBG_NAN range checks live in the widen pass, so they do not see the two products that skip it. Leave NOWIDEN off when you use them.

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. gr_mix_r_kernel<true>/<false> use 32 VGPRs with 0 spills, the same as before; swiglu_quant_kernel uses 34-35 VGPRs.
  • Engine self-checks on an 8K prompt with NOWIDEN_CHECK=12, QKV_CHECK=4 and SWIGLU_Q8_CHECK=8: 24 "bitwise equal" lines, 0 mismatches. Each NOWIDEN check compares 10,485,760 values. On our production tree a longer run compared 400 SwiGLU blocks (IQ4_NL 274, Q2_0 126), all byte-identical.
  • Default off: with neither variable set, the 8K and 32K outputs hash the same as main 54828c7e.
  • ctest -j 1: 221/224. The three failures are the same on main 54828c7e without this change: ple_parity (cannot find the Q2_0 gguf through its relative path), conversation_copy_streams_test (the first copy stream takes 148 MiB here) and isa_guard_check (reports a CPU iq512 function). hip_prefill_gemm passes.
  • Speed: the table above. strata serve, IQ3_S pack, two-card layer split at 27, --prefill 16384 --prefill-pipe 1600 --spec 3 --spec-min-p 0.6 --pipeline-windows 1 --kv int8, parallel 1, STRATA_HIP_PROMPT_F16=1 plus our usual HIP env. benchmark.py 8K + 32K, one run each per arm, a new nonce each request, arms alternating off/on and on/off. 0 stalls.

Failed:

  • none observed (see the three ctest failures above, which main already has)

Not run:

  • CUDA / SYCL / Metal builds. STRATA_F16_NOWIDEN only does something when FP16 prompt I/O is on (HIP). The swiglu_quant change widens an existing #if to __HIPCC__. I did not build the other backends.
  • Other gfx103x chips and other RDNA generations.
  • A quality run (KL). The output is bitwise identical, so I did not run one.

Limits

  • attn_q on the QSA layers (~6% of the widen time) still widens. It has five consumers, so I left it out.
  • On this card the gain is about +3.5% at 32K and smaller for short prompts. On our production tree (same changes) 1K-2K prompts gained +0.5-0.9%.

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/5474 **Author:** [@Vop3p](https://github.com/Vop3p) **Created:** 11/7/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/f16-nowiden-swiglu-q8` --- ### 📝 Commits (1) - [`cf7decc`](https://github.com/Niko1221/Strata/commit/cf7decc8c61969ae0b8f856c751b0a6ade37fbd3) HIP prompt path: opt-in FP16 reads of the hc up projection and attn_qkv (STRATA_F16_NOWIDEN), fused SwiGLU + Q8 on HIP (STRATA_SWIGLU_Q8) ### 📊 Changes **6 files changed** (+211 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/prefill/gemm.hpp` (+14 -0) 📝 `include/strata/prefill/kernels.hpp` (+6 -2) 📝 `src/prefill/gemm.cu` (+16 -0) 📝 `src/prefill/kernels.cu` (+52 -12) 📝 `src/prefill/moe_mmq.cu` (+17 -3) 📝 `src/prefill/prefill.cpp` (+106 -9) </details> ### 📄 Description ## Problem and result With `STRATA_HIP_PROMPT_F16=1` the prompt GEMMs run FP16 in and out, and `f16_inplace` then widens every FP16 product back to FP32 in place. On gfx1030 that widen pass is already at memory bandwidth (636-900 GB/s at N 1024-6144, 528 GB/s at N 10240 in a standalone kernel), so it cannot be made faster. It can only be skipped. In a 32K prompt trace it is ~4% of GPU time. About two thirds of it is two products whose only consumers can read FP16 directly: the hyper-connection up projection (`hc_attn_up` / `hc_ffn_up`, N 10240, read by `gr_mix_r`) and `attn_qkv` on the GDN layers (N 10240, read by the GDN conv kernels). This PR has two opt-in parts, both bitwise identical to the default path: 1. `STRATA_F16_NOWIDEN=1` (new code): those two products stay FP16 and their consumers read halves. FP16 to FP32 is exact, so the values do not change; the conversion only moves into the consumer. `gr_mix_r_kernel<G16>` reads the up projection's FP16 rows. `gdn_conv_kernel` / `gdn_conv_l2_kernel` / `gdn_conv_hist_kernel<H16>` read `attn_qkv` in its row-slice layout (the native path computes it in slices of R columns). The request is made only where the conv kernel that reads FP16 runs (`gdn_conv_f16_ok()`: CONVL2=1, not serial, not CHUNKED). A product that goes through MMQ, PF_PAD or has no FP16 I/O reports R = 0 and keeps the widen. 2. `STRATA_SWIGLU_Q8=1` (enables an existing kernel on HIP): `swiglu_quant_kernel` in `moe_mmq.cu` already fuses SwiGLU with `quantize_mmq_q8_1` for CUDA SM60 resident weights. HIP had it behind an `#if` ("not checked against the HIP quantizer"). This PR builds it for HIP (`__shfl_xor` at width 32) and uses it in the plain grouped expert path (both the whole-group and sliced call sites) when there is no tail scale and no Hadamard. The intermediate H no longer goes through memory. Measured on 2x RX 6900 XT, 10 cold-start interleaved pairs, off vs on, same binary: | | off (median) | on (median) | paired difference (median) | pairs faster | range | |---|---|---|---|---|---| | prompt 32K, tok/s | 1,770 | 1,832 | **+3.5%** | 10/10 | +2.1 .. +4.9% | | prompt 8K, tok/s | 1,336 | 1,380 | +3.1% | 7/10 | -14.9 .. +15.9% | | decode 32K, ms per window | 27.22 | 27.22 | 0.0% | | -0.1 .. +1.1% | Output text is identical in all 10 pairs (8K and 32K). Decode does not use these paths. 8K prompt reads on this machine have a wide spread from run to run; 32K is the clean number. ## Related discussion none (opt-in, HIP prompt path only, bitwise identical to the default) ## Approach - Opt-in because each part was measured on one chip (gfx1030). Neither changes a value, so making them the default where `STRATA_HIP_PROMPT_F16=1` is on would be a one-line change if you prefer that. - `Gemm` gets `keep_f16_once(n_full)` / `take_kept_f16()` (up projection: one whole product) and `keep_f16_slices_once(n_full)` / `take_kept_rows()` (attn_qkv: every slice stays FP16, and the slice width is returned). `f16_inplace` skips the widen only for the product that was asked for, so every other GEMM is unchanged. The inject product shares the same `Gemm`, so the flag is taken back right after the up projection. - Self-checks that run the default path again and compare bit for bit: `STRATA_F16_NOWIDEN_CHECK=N` (mixed output of the hc read), `STRATA_F16_NOWIDEN_QKV_CHECK=N` (conv output; the conv history is saved and restored around the recomputation) and `STRATA_SWIGLU_Q8_CHECK=N` (the quantized H, 1152 bytes per row). - `STRATA_F16_RANGE` / `STRATA_DBG_NAN` range checks live in the widen pass, so they do not see the two products that skip it. Leave NOWIDEN off when you use them. ## 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`. `gr_mix_r_kernel<true>/<false>` use 32 VGPRs with 0 spills, the same as before; `swiglu_quant_kernel` uses 34-35 VGPRs. - Engine self-checks on an 8K prompt with NOWIDEN_CHECK=12, QKV_CHECK=4 and SWIGLU_Q8_CHECK=8: 24 "bitwise equal" lines, 0 mismatches. Each NOWIDEN check compares 10,485,760 values. On our production tree a longer run compared 400 SwiGLU blocks (IQ4_NL 274, Q2_0 126), all byte-identical. - Default off: with neither variable set, the 8K and 32K outputs hash the same as main 54828c7e. - `ctest -j 1`: 221/224. The three failures are the same on main 54828c7e without this change: `ple_parity` (cannot find the Q2_0 gguf through its relative path), `conversation_copy_streams_test` (the first copy stream takes 148 MiB here) and `isa_guard_check` (reports a CPU iq512 function). `hip_prefill_gemm` passes. - Speed: the table above. `strata` serve, IQ3_S pack, two-card layer split at 27, `--prefill 16384 --prefill-pipe 1600 --spec 3 --spec-min-p 0.6 --pipeline-windows 1 --kv int8`, parallel 1, `STRATA_HIP_PROMPT_F16=1` plus our usual HIP env. `benchmark.py` 8K + 32K, one run each per arm, a new nonce each request, arms alternating off/on and on/off. 0 stalls. **Failed:** - none observed (see the three ctest failures above, which main already has) **Not run:** - CUDA / SYCL / Metal builds. `STRATA_F16_NOWIDEN` only does something when FP16 prompt I/O is on (HIP). The `swiglu_quant` change widens an existing `#if` to `__HIPCC__`. I did not build the other backends. - Other gfx103x chips and other RDNA generations. - A quality run (KL). The output is bitwise identical, so I did not run one. ## Limits - `attn_q` on the QSA layers (~6% of the widen time) still widens. It has five consumers, so I left it out. - On this card the gain is about +3.5% at 32K and smaller for short prompts. On our production tree (same changes) 1K-2K prompts gained +0.5-0.9%. --- 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#5452
No description provided.