[PR #5014] [CLOSED] [Engine] q36: faster long prompts, decode and sampled MTP on gfx1151 #5285

Closed
opened 2026-11-07 16:34:04 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5014
Author: @storm-ace
Created: 11/2/2026
Status: ❌ Closed

Base: main ← Head: fix/q36-long-context-decode


📝 Commits (5)

  • 6c83169 q36: decode attention reads each K / V cell once per GQA group
  • 0323b0b q36: MTP drafts for sampled requests, grouped prompt attention
  • fc3893a q36: flash prompt attention on WMMA, hipBLASLt rows
  • fdcf58e docs(q36): end-to-end numbers, the occupancy finding
  • eb71c30 q36: keep the WMMA types HIP-only, FA on by default on gfx1151 only

📊 Changes

3 files changed (+556 additions, -12 deletions)

View changed files

📝 docs/QWEN36.md (+46 -0)
📝 src/qwen35/q36_engine.cu (+474 -12)
📝 tools/hip/gfx1151-hipblaslt-100500.txt (+36 -0)

📄 Description

Problem and result

Qwen3.6-35B-A3B (UD-Q4_K_XL) as a coding-agent backend on a Strix Halo (Ryzen AI MAX+ PRO 395, Radeon 8060S, gfx1151, Windows) slowed down sharply with context: decode fell from ~30 tok/s after an 8K prompt to ~12 tok/s after 32K, a 35K-token prompt took ~110 s to read, and sampled requests (agents run at temperature > 0) never used the MTP drafts. Through the server, a ~36K-token request (prompt + 300 tokens at temperature 0.6) went from 131.8 s to 52.0 s: prompt read 323 -> 871 tok/s, decode 13.9 -> 28.5-33.2 tok/s.

None yet. This changes defaults of the q36 path; each change is listed below with the switch that turns it off. The CUDA build was not run and the hardware runs are from one machine (see Not run). I am happy to split it into smaller PRs or turn any part opt-in if you prefer that scope.

Approach

All in src/qwen35/q36_engine.cu, plus table rows and docs:

  1. GQA decode attention (k_attn_part_gqa<G>). k_attn_part ran one block per query head, so the 8 query heads of a KV head each read that head's whole K/V cache (8x the traffic), and each thread walked its own 1 KB K row 4 bytes at a time. One block per KV head and 256-cell chunk now computes the G heads together, K is staged in LDS tiles and loaded coalesced, and the rows of a verify window on the same chunk launch next to each other. Each head sums its cell in k_attn_part's order: bitwise equal (STRATA_Q36_VERIFY=1 compares). Off: STRATA_Q36_OLD_KERNELS=1.
  2. MTP drafts for sampled requests. sample_spec keeps the draft with the probability p(draft) of the distribution sample() draws from (temperature, top-k/p, min-p, penalties) and otherwise draws from that distribution without the draft: the speculative-sampling rule for a one-token draft, so the tokens keep exactly the plain sampler's distribution (not its random stream). spec_step takes a Judge that decides the window from the rows' logits. Off: STRATA_Q36_NO_SPEC_SAMPLE=1.
  3. Grouped prompt attention. The G query heads of a KV head become one GEMM per KV head (q16 as [kvh][t][g][HD]) instead of G narrow ones, each query slice covering only the cells its rows see. Bitwise equal on the checked prompt. Off: STRATA_Q36_ATT_OLD=1.
  4. Flash prompt attention on WMMA (k_attn_fa_wmma, RDNA3 / RDNA3.5 v_wmma_f32_16x16x16_f16, wave32): scores, causal mask, online softmax and P V fused, no T x P score matrix. 64 grouped query rows per block, 16-cell K/V tiles in LDS (V transposed). FP16 operands, FP32 accumulation: not the GEMM path's bits (KL below). On by default only on gfx1151, where it was measured; compiled for the other gfx11 chips but only with STRATA_Q36_FA=1 (not run there). Off: STRATA_Q36_NO_FA=1.
  5. hipBLASLt rows. Every Qwen3.6 prompt-projection shape missed tools/hip/gfx1151-hipblaslt-100500.txt and fell back to hipBLAS (STRATA_HIPBLASLT_VERBOSE=1: launches=0 fallbacks=1250). 35 rows added (hidden 2048 shapes, T = 16..4096), calibrated with tune_hipblaslt on this GPU (up to 5.6x the hipBLAS time per the tuner). Off: STRATA_HIPBLASLT_TABLE=off.
  6. Probe: STRATA_Q36_PROF=1 times the prompt attention's parts and the layers by type in --bench-pp (host-side syncs; diagnostics only).

docs/QWEN36.md ("Long context and sampled requests") documents each change, its switch and the numbers. The FA kernel's comment documents the gfx11 fragment layout it relies on.

Validation

Environment: Ryzen AI MAX+ PRO 395, Radeon 8060S (gfx1151, 16 GB carve-out + shared, 48 GB seen by Windows), Windows 11 Pro 10.0.26200, ROCm 10.2.0a20260930 (TheRock wheels via tools/hip/build_windows.bat, STRATA_HIP_ARCHS=gfx1151), Qwen3.6-35B-A3B-UD-Q4_K_XL, every expert in VRAM, --max-context 131072, prompt chunk 4096 (auto).

Passed

  • HIP build (gfx1151) of every commit on this branch, including the last one.
  • Decode exactness, commit 6c831690: STRATA_Q36_VERIFY=1 strata --native <gguf> --max-context 8192 --no-graph --mtp 0 --n 48 --tokens <2600 ids> -> strata-q36 VERIFY: 22512 comparisons, 0 mismatches.
  • Grouped prompt attention, commit 0323b0ba: teacher-forced, 1,229-token real-text prompt (tools/qwen35/parity_prompts.ids row 1 + its greedy continuation), STRATA_Q36_CHUNK=256, 32 steps, --dump-full-logits, against STRATA_Q36_ATT_OLD=1: KL 0, every logit equal, top-1 32/32.
  • Whole prompt path, commit fc3893a1 (FA + table rows) against the old path (STRATA_HIPBLASLT_TABLE=off STRATA_Q36_NO_FA=1 STRATA_Q36_ATT_OLD=1), same harness: 256-cell chunks mean KL 2.17e-6, max 1.27e-5, top-1 32/32; chunk 4096 mean KL 1.15e-6, max 9.05e-6, top-1 32/32. (For scale: the floor in this doc's KL table, llama.cpp CPU vs HIP, is 0.0019-0.056.)
  • --bench-pp 32768 --bench-tg 0, 3 repetitions each, STRATA_Q36_PROF=1 (its syncs included):
Build pp32768 (rep 0 / 1 / 2) Profile (one repetition)
upstream c62d5e3a + GQA decode only 362.4 / 362.2 / 359.1 tok/s (no probe) -
+ grouped prompt attention 390.7 / 389.6 / 388.0 attention GEMMs 15.2 s + 14.3 s, softmax 4.8 s
+ flash attention 517.4 / 519.4 / 509.3 fused attention 11.3 s; GDN mixers 29.8 s, attention mixers 18.9 s, MoE 15.2 s
+ hipBLASLt rows 938.1 / 929.6 / 948.3 GDN mixers 8.7 s, attention mixers 13.0 s, MoE 13.4 s
  • Through the server (serve/server.py of the installed Strata Control, engine from this branch), salted prompts of q36_engine.cu source, nothing reused, max_tokens 300, temperature 0.6, one request per size per build; the engine's strata serve: session 0: prompt ... lines:
Build ~9K prompt read decode ~36K prompt read decode drafts kept
upstream engine 0.1.55 (installed) 494 tok/s 36.7 323 13.9 0 of 0
GQA decode 483 37.0 334 27.1 0 of 0
+ MTP for sampled requests, grid order 507 48.8 344 33.2 186/230, 175/248
final (all of the above) 1,190 49.0 871 28.5 185/228, 180/240

The decode after 36K varied between 33.2 and 28.5 tok/s across these runs with the same decode code; the second run came after about an hour of continuous load.

  • A sampled answer with MTP drafts (temperature 0.6, short coding question) read coherently; 68.0 tok/s, 131 of 176 drafts kept.
  • Hands-on use: the final build (eb71c306) run through the Strata desktop app (its Qwen3.6 run config pointed at this branch's engine) and used interactively by me; answers looked right and no errors were seen. This is a manual check, not a measurement.
  • CI on this PR: check, metal-link and title passed.

Failed: none observed.

Not run

  • CUDA build: no CUDA toolkit or NVIDIA GPU here. The WMMA types and helpers are behind __HIPCC__ and the kernel body behind the gfx11 macros, so the CUDA build should compile the kernel's empty body, but that is unverified.
  • The scripted runs above were not repeated on the last commit (CUDA guards, FA gated to gfx1151); it was built for HIP and used hands-on, and on gfx1151 it does not change the path that runs.
  • No run on other RDNA3 / RDNA3.5 chips, on RDNA4 / gfx12, or on NVIDIA. FA stays off on all of them by default.
  • No statistical test of the sampled-request distribution beyond the derivation above and the coherent output.
  • Hybrid mode (experts partly on the CPU), --parallel > 1 and pictures were not measured with these changes.

Limits

  • The fused attention reaches ~8 TFLOPS on the 8060S; its occupancy is bound by the 128 accumulator VGPRs per lane (a K/V register prefetch was slower, Q read from cache instead of LDS measured the same). Splitting a row's 256 output dims over two waves is the next thing to try.
  • The 35 table rows are valid for hipBLASLt 1.5.0 (100500) on gfx1151 only, like the rest of that file.
  • After these changes a 32K prompt spends most of its time in the GDN mixers (~9 s) and the MoE blocks (~13 s), which this PR does not touch.

🤖 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/5014 **Author:** [@storm-ace](https://github.com/storm-ace) **Created:** 11/2/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/q36-long-context-decode` --- ### 📝 Commits (5) - [`6c83169`](https://github.com/Niko1221/Strata/commit/6c831690a9e5535b0d038eecce5f71e6aa10df10) q36: decode attention reads each K / V cell once per GQA group - [`0323b0b`](https://github.com/Niko1221/Strata/commit/0323b0ba93d6b6ee1202243837c9323eb2c53c93) q36: MTP drafts for sampled requests, grouped prompt attention - [`fc3893a`](https://github.com/Niko1221/Strata/commit/fc3893a1d3c80c6ce9d695fa6cbf139e151f591f) q36: flash prompt attention on WMMA, hipBLASLt rows - [`fdcf58e`](https://github.com/Niko1221/Strata/commit/fdcf58e39da4bdc7c9ecbbcfa2b0964c6f3d36bb) docs(q36): end-to-end numbers, the occupancy finding - [`eb71c30`](https://github.com/Niko1221/Strata/commit/eb71c3062d781230b69163e055c3b622d9317190) q36: keep the WMMA types HIP-only, FA on by default on gfx1151 only ### 📊 Changes **3 files changed** (+556 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `docs/QWEN36.md` (+46 -0) 📝 `src/qwen35/q36_engine.cu` (+474 -12) 📝 `tools/hip/gfx1151-hipblaslt-100500.txt` (+36 -0) </details> ### 📄 Description ### Problem and result Qwen3.6-35B-A3B (UD-Q4_K_XL) as a coding-agent backend on a Strix Halo (Ryzen AI MAX+ PRO 395, Radeon 8060S, gfx1151, Windows) slowed down sharply with context: decode fell from ~30 tok/s after an 8K prompt to ~12 tok/s after 32K, a 35K-token prompt took ~110 s to read, and sampled requests (agents run at temperature > 0) never used the MTP drafts. Through the server, a ~36K-token request (prompt + 300 tokens at temperature 0.6) went from **131.8 s to 52.0 s**: prompt read 323 -> 871 tok/s, decode 13.9 -> 28.5-33.2 tok/s. ### Related discussion None yet. This changes defaults of the q36 path; each change is listed below with the switch that turns it off. The CUDA build was not run and the hardware runs are from one machine (see Not run). I am happy to split it into smaller PRs or turn any part opt-in if you prefer that scope. ### Approach All in `src/qwen35/q36_engine.cu`, plus table rows and docs: 1. **GQA decode attention** (`k_attn_part_gqa<G>`). `k_attn_part` ran one block per query head, so the 8 query heads of a KV head each read that head's whole K/V cache (8x the traffic), and each thread walked its own 1 KB K row 4 bytes at a time. One block per KV head and 256-cell chunk now computes the G heads together, K is staged in LDS tiles and loaded coalesced, and the rows of a verify window on the same chunk launch next to each other. Each head sums its cell in `k_attn_part`'s order: **bitwise equal** (`STRATA_Q36_VERIFY=1` compares). Off: `STRATA_Q36_OLD_KERNELS=1`. 2. **MTP drafts for sampled requests**. `sample_spec` keeps the draft with the probability p(draft) of the distribution `sample()` draws from (temperature, top-k/p, min-p, penalties) and otherwise draws from that distribution without the draft: the speculative-sampling rule for a one-token draft, so the tokens keep exactly the plain sampler's distribution (not its random stream). `spec_step` takes a `Judge` that decides the window from the rows' logits. Off: `STRATA_Q36_NO_SPEC_SAMPLE=1`. 3. **Grouped prompt attention**. The G query heads of a KV head become one GEMM per KV head (`q16` as `[kvh][t][g][HD]`) instead of G narrow ones, each query slice covering only the cells its rows see. Bitwise equal on the checked prompt. Off: `STRATA_Q36_ATT_OLD=1`. 4. **Flash prompt attention on WMMA** (`k_attn_fa_wmma`, RDNA3 / RDNA3.5 `v_wmma_f32_16x16x16_f16`, wave32): scores, causal mask, online softmax and P V fused, no T x P score matrix. 64 grouped query rows per block, 16-cell K/V tiles in LDS (V transposed). FP16 operands, FP32 accumulation: not the GEMM path's bits (KL below). **On by default only on gfx1151**, where it was measured; compiled for the other gfx11 chips but only with `STRATA_Q36_FA=1` (not run there). Off: `STRATA_Q36_NO_FA=1`. 5. **hipBLASLt rows**. Every Qwen3.6 prompt-projection shape missed `tools/hip/gfx1151-hipblaslt-100500.txt` and fell back to hipBLAS (`STRATA_HIPBLASLT_VERBOSE=1`: `launches=0 fallbacks=1250`). 35 rows added (hidden 2048 shapes, T = 16..4096), calibrated with `tune_hipblaslt` on this GPU (up to 5.6x the hipBLAS time per the tuner). Off: `STRATA_HIPBLASLT_TABLE=off`. 6. **Probe**: `STRATA_Q36_PROF=1` times the prompt attention's parts and the layers by type in `--bench-pp` (host-side syncs; diagnostics only). `docs/QWEN36.md` ("Long context and sampled requests") documents each change, its switch and the numbers. The FA kernel's comment documents the gfx11 fragment layout it relies on. ### Validation Environment: Ryzen AI MAX+ PRO 395, Radeon 8060S (gfx1151, 16 GB carve-out + shared, 48 GB seen by Windows), Windows 11 Pro 10.0.26200, ROCm 10.2.0a20260930 (TheRock wheels via `tools/hip/build_windows.bat`, `STRATA_HIP_ARCHS=gfx1151`), Qwen3.6-35B-A3B-UD-Q4_K_XL, every expert in VRAM, `--max-context 131072`, prompt chunk 4096 (auto). **Passed** - HIP build (gfx1151) of every commit on this branch, including the last one. - Decode exactness, commit `6c831690`: `STRATA_Q36_VERIFY=1 strata --native <gguf> --max-context 8192 --no-graph --mtp 0 --n 48 --tokens <2600 ids>` -> `strata-q36 VERIFY: 22512 comparisons, 0 mismatches`. - Grouped prompt attention, commit `0323b0ba`: teacher-forced, 1,229-token real-text prompt (`tools/qwen35/parity_prompts.ids` row 1 + its greedy continuation), `STRATA_Q36_CHUNK=256`, 32 steps, `--dump-full-logits`, against `STRATA_Q36_ATT_OLD=1`: KL 0, every logit equal, top-1 32/32. - Whole prompt path, commit `fc3893a1` (FA + table rows) against the old path (`STRATA_HIPBLASLT_TABLE=off STRATA_Q36_NO_FA=1 STRATA_Q36_ATT_OLD=1`), same harness: 256-cell chunks mean KL 2.17e-6, max 1.27e-5, top-1 32/32; chunk 4096 mean KL 1.15e-6, max 9.05e-6, top-1 32/32. (For scale: the floor in this doc's KL table, llama.cpp CPU vs HIP, is 0.0019-0.056.) - `--bench-pp 32768 --bench-tg 0`, 3 repetitions each, `STRATA_Q36_PROF=1` (its syncs included): | Build | pp32768 (rep 0 / 1 / 2) | Profile (one repetition) | | --- | --- | --- | | upstream `c62d5e3a` + GQA decode only | 362.4 / 362.2 / 359.1 tok/s (no probe) | - | | + grouped prompt attention | 390.7 / 389.6 / 388.0 | attention GEMMs 15.2 s + 14.3 s, softmax 4.8 s | | + flash attention | 517.4 / 519.4 / 509.3 | fused attention 11.3 s; GDN mixers 29.8 s, attention mixers 18.9 s, MoE 15.2 s | | + hipBLASLt rows | 938.1 / 929.6 / 948.3 | GDN mixers 8.7 s, attention mixers 13.0 s, MoE 13.4 s | - Through the server (`serve/server.py` of the installed Strata Control, engine from this branch), salted prompts of `q36_engine.cu` source, nothing reused, `max_tokens` 300, temperature 0.6, one request per size per build; the engine's `strata serve: session 0: prompt ...` lines: | Build | ~9K prompt read | decode | ~36K prompt read | decode | drafts kept | | --- | ---: | ---: | ---: | ---: | --- | | upstream engine 0.1.55 (installed) | 494 tok/s | 36.7 | 323 | 13.9 | 0 of 0 | | GQA decode | 483 | 37.0 | 334 | 27.1 | 0 of 0 | | + MTP for sampled requests, grid order | 507 | 48.8 | 344 | 33.2 | 186/230, 175/248 | | final (all of the above) | 1,190 | 49.0 | 871 | 28.5 | 185/228, 180/240 | The decode after 36K varied between 33.2 and 28.5 tok/s across these runs with the same decode code; the second run came after about an hour of continuous load. - A sampled answer with MTP drafts (temperature 0.6, short coding question) read coherently; 68.0 tok/s, 131 of 176 drafts kept. - Hands-on use: the final build (`eb71c306`) run through the Strata desktop app (its Qwen3.6 run config pointed at this branch's engine) and used interactively by me; answers looked right and no errors were seen. This is a manual check, not a measurement. - CI on this PR: `check`, `metal-link` and `title` passed. **Failed**: none observed. **Not run** - **CUDA build**: no CUDA toolkit or NVIDIA GPU here. The WMMA types and helpers are behind `__HIPCC__` and the kernel body behind the gfx11 macros, so the CUDA build should compile the kernel's empty body, but that is unverified. - The scripted runs above were not repeated on the last commit (CUDA guards, FA gated to gfx1151); it was built for HIP and used hands-on, and on gfx1151 it does not change the path that runs. - No run on other RDNA3 / RDNA3.5 chips, on RDNA4 / gfx12, or on NVIDIA. FA stays off on all of them by default. - No statistical test of the sampled-request distribution beyond the derivation above and the coherent output. - Hybrid mode (experts partly on the CPU), `--parallel` > 1 and pictures were not measured with these changes. ### Limits - The fused attention reaches ~8 TFLOPS on the 8060S; its occupancy is bound by the 128 accumulator VGPRs per lane (a K/V register prefetch was slower, Q read from cache instead of LDS measured the same). Splitting a row's 256 output dims over two waves is the next thing to try. - The 35 table rows are valid for hipBLASLt 1.5.0 (`100500`) on gfx1151 only, like the rest of that file. - After these changes a 32K prompt spends most of its time in the GDN mixers (~9 s) and the MoE blocks (~13 s), which this PR does not touch. 🤖 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 16:34:04 +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#5285
No description provided.