[PR #4567] [CLOSED] [Engine] QSA decode attention: opt-in 32-cell chunks (STRATA_QSA_ATTN_VARIANT=2) #5094

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4567
Author: @Jackwwg83
Created: 10/29/2026
Status: ❌ Closed

Base: main ← Head: qsa-attn-32cell


📝 Commits (1)

  • b63b372 QSA decode attention: opt-in 32-cell chunks (STRATA_QSA_ATTN_VARIANT=2)

📊 Changes

4 files changed (+112 additions, -25 deletions)

View changed files

📝 CMakeLists.txt (+9 -0)
📝 include/strata/kernels/qsa_decode_attn.hpp (+3 -0)
📝 src/kernels/cuda/qsa_decode_attn.cu (+51 -19)
📝 src/kernels/qsa_merge_daily_parity.cpp (+49 -6)

📄 Description

What

This change adds an opt-in variant of the batched QSA decode attention.
STRATA_QSA_ATTN_VARIANT=2 splits the selected cells into 32-cell chunks instead of 64.
The merge pass reads the matching chunk count.
The default path does not change: same kernels, same dispatch, same bits.
Only the exact value 2 enables the variant.

Why

At long context the chunk kernel launches too few blocks to fill a large GPU.
Half-size chunks double the number of blocks and keep more of the GPU busy.

Measured with a kernel micro-benchmark on an AMD Radeon AI PRO R9700 (gfx1201, 64 CUs):
131,072-token context, T=4 verify window, int8 KV, one QSA layer.

per QSA layer
default (64-cell chunks) 109.4 us
variant 2 (32-cell chunks) 75.4 us

That is 34 us per layer, about 0.4 ms per decode window over the 12 QSA layers of Qwen3.8-Flash-Next.
We run it in production on an R9700 + Ryzen AI Max+ 395 box, together with other changes.

Cost

The partial-result scratch is about twice as large (qsa_decode_attn_scratch_floats sizes it).
The process reads the variable once. Set it before the first scratch query or graph capture.

Numerics

Accumulation stays in FP32. Smaller chunks change the order of the partial sums, so results can differ at the bit level.
qsa_variants_parity --variants compares the batch call and its graph replay with the default kernel over FP16, int8, Q4_0 and K8V4 pools, masked pages, mixed widths, chunk boundaries and 1-6 queries.
Tolerance: abs(v2 - ref) <= 2e-5 + 2e-5 * abs(ref). The default control requires identical bits.

Results on this branch (v0.2.7 + this change):

device variant result max abs error RMS error
Radeon 8060S (gfx1151) 0 PASS, 0 bit differences 0 0
Radeon 8060S (gfx1151) 2 PASS 2.0e-6 5.8e-8
R9700 (gfx1201) 0 PASS, 0 bit differences 0 0

The variant-2 parity on the R9700 passed on our v0.2.2-based branch with the same kernel code. On this branch the R9700 was serving production, so the larger scratch did not fit. CUDA was not built (no NVIDIA card here); the change keeps the existing CUDA guards and template instantiations.

Test

ctest --test-dir <build> --output-on-failure -R '^qsa_attn_variant_(0|2)$'

A missing GPU returns 77 (skipped).

🤖 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/4567 **Author:** [@Jackwwg83](https://github.com/Jackwwg83) **Created:** 10/29/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `qsa-attn-32cell` --- ### 📝 Commits (1) - [`b63b372`](https://github.com/Niko1221/Strata/commit/b63b3720eed52332f0a810cedf79fbd92bac5ec7) QSA decode attention: opt-in 32-cell chunks (STRATA_QSA_ATTN_VARIANT=2) ### 📊 Changes **4 files changed** (+112 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+9 -0) 📝 `include/strata/kernels/qsa_decode_attn.hpp` (+3 -0) 📝 `src/kernels/cuda/qsa_decode_attn.cu` (+51 -19) 📝 `src/kernels/qsa_merge_daily_parity.cpp` (+49 -6) </details> ### 📄 Description ## What This change adds an opt-in variant of the batched QSA decode attention. `STRATA_QSA_ATTN_VARIANT=2` splits the selected cells into 32-cell chunks instead of 64. The merge pass reads the matching chunk count. The default path does not change: same kernels, same dispatch, same bits. Only the exact value `2` enables the variant. ## Why At long context the chunk kernel launches too few blocks to fill a large GPU. Half-size chunks double the number of blocks and keep more of the GPU busy. Measured with a kernel micro-benchmark on an AMD Radeon AI PRO R9700 (gfx1201, 64 CUs): 131,072-token context, T=4 verify window, int8 KV, one QSA layer. | | per QSA layer | |---|---:| | default (64-cell chunks) | 109.4 us | | variant 2 (32-cell chunks) | 75.4 us | That is 34 us per layer, about 0.4 ms per decode window over the 12 QSA layers of Qwen3.8-Flash-Next. We run it in production on an R9700 + Ryzen AI Max+ 395 box, together with other changes. ## Cost The partial-result scratch is about twice as large (`qsa_decode_attn_scratch_floats` sizes it). The process reads the variable once. Set it before the first scratch query or graph capture. ## Numerics Accumulation stays in FP32. Smaller chunks change the order of the partial sums, so results can differ at the bit level. `qsa_variants_parity --variants` compares the batch call and its graph replay with the default kernel over FP16, int8, Q4_0 and K8V4 pools, masked pages, mixed widths, chunk boundaries and 1-6 queries. Tolerance: `abs(v2 - ref) <= 2e-5 + 2e-5 * abs(ref)`. The default control requires identical bits. Results on this branch (v0.2.7 + this change): | device | variant | result | max abs error | RMS error | |---|---|---|---:|---:| | Radeon 8060S (gfx1151) | 0 | PASS, 0 bit differences | 0 | 0 | | Radeon 8060S (gfx1151) | 2 | PASS | 2.0e-6 | 5.8e-8 | | R9700 (gfx1201) | 0 | PASS, 0 bit differences | 0 | 0 | The variant-2 parity on the R9700 passed on our v0.2.2-based branch with the same kernel code. On this branch the R9700 was serving production, so the larger scratch did not fit. CUDA was not built (no NVIDIA card here); the change keeps the existing CUDA guards and template instantiations. ## Test ```sh ctest --test-dir <build> --output-on-failure -R '^qsa_attn_variant_(0|2)$' ``` A missing GPU returns 77 (skipped). 🤖 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:32:38 +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#5094
No description provided.