[PR #2806] [Engine] sycl: decode QSA selection and attention in fewer, shorter launches (opt-in, bitwise) #4274

Open
opened 2026-11-07 15:34:29 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/2806
Author: @hotschmoe
Created: 10/16/2026
Status: 🔄 Open

Base: main ← Head: pr/sycl-decode-attn


📝 Commits (1)

  • 1c501b0 sycl: decode QSA selection and attention in fewer, shorter launches (opt-in, bitwise)

📊 Changes

7 files changed (+1008 additions, -0 deletions)

View changed files

📝 docs/INTEL.md (+31 -0)
📝 sycl/CMakeLists.txt (+12 -0)
➕ sycl/include/strata/qsa_decode_attn_multi.hpp (+24 -0)
📝 sycl/src/core/verify.cpp (+37 -0)
📝 sycl/src/kernels/cuda/qsa_decode_attn.dp.cpp (+220 -0)
📝 sycl/src/kernels/cuda/qsa_select.dp.cpp (+166 -0)
➕ sycl/src/kernels/qsa_verify_batch_parity.cpp (+518 -0)

📄 Description

Problem and result

On an Arc Pro B70 the QSA selection (block scores, top-k) and attention of a decode window are small, latency-bound launches, and a batch window (--batch) ran them one row at a time. This adds four opt-in switches that do the same arithmetic in fewer launches or with less serial work. Each gives exactly the bits of the path it replaces; all are off by default, and each is a branch in front of the existing code that tests its flag first.

switch what it does
STRATA_BATCH_QSA_ATTN=1 A batch window ran the scores, top-k and attention one row at a time. Now the scores run once per slot, the top-k once per window, and the attention once per window over every slot's pools.
STRATA_QSA_TOPK_SCAN=1 The wide top-k kernel (capacity above ~135K cells) found each radix pass's digit with one thread walking 256 bins. Now a work-group scan. Integers only: the same ids.
STRATA_QSA_SCORES_TRANSPOSED=1 The decode block scores reduce a block's (query, head) sums together: 16-31 shuffles per block instead of 20 per query, the same pairs in the same order.
STRATA_ATTN_MERGE_ACTIVE=1 The attention merge of a call of 8 rows or fewer folds only the chunks its selection reaches. The MTP drafter's 32K window is 512 chunks.

Result on 0.2.0-beta, two B70s, all four on, outputs bitwise identical in every arm: two streams in one window +1.9% aggregate (54.7 / 61.4 -> 55.7 / 62.6 tok/s), one stream +0.3%. A small engine gain at these contexts; the kernels themselves are 1.3-2.6x faster (table under Validation), and the gain grows with context.

Feature issue #2805 (closed in the 0.2.0 tracker reset). No maintainer agreement on scope yet. If four switches are too many for the gain, STRATA_BATCH_QSA_ATTN alone carries most of the two-stream effect and I can split it out.

Approach

  • sycl/src/core/verify.cpp: STRATA_BATCH_QSA_ATTN; in record_window's QSA branch, a branch before the per-row batch loop runs the scores per slot, one qsa_block_topk and one qsa_decode_attn_multi for the window.
  • sycl/include/strata/qsa_decode_attn_multi.hpp (new) and sycl/src/kernels/cuda/qsa_decode_attn.dp.cpp: qsa_decode_attn_multi (qsa_decode_attn_batch over up to four pool sets per launch; mixed KV formats or STRATA_ATTN_LANECELL=1 fall back per set), attn_merge_active_kernel.
  • sycl/src/kernels/cuda/qsa_select.dp.cpp: block_topk_wide_kernel<bool SCAN = false> (only the new launch instantiates the scan; the existing launch compiles the same code), block_scores_multi_t_kernel<NQ>.
  • sycl/src/kernels/qsa_verify_batch_parity.cpp (new), two ctest entries: without switches it checks the batch form against per-row calls (2x1, 2x2, 4x2, 6x1, 1x4 windows at 1K / 16K / 64K), selections against qsa_block_topk_ref, attention against qsa_decode_attn_step, 1-8-query scores against one call per query, the MTP drafter call, and writes a hash of each of 45 outputs; the second entry repeats with the three kernel switches and requires the same hashes. No tolerance anywhere.
  • docs/INTEL.md: a short section.

Left alone: the default path, the prompt path, qsa_decode_attn_step (decode without MTP), K/V and indexer appends, streamed-K/V batch windows, CUDA and HIP.

Validation

Setup: 0.2.0-beta main e88ee39d against this branch rebased on it. 2x Intel Arc Pro B70 32 GB, kernel 7.1, Compute Runtime 26.22.38646.4 at run time; built with the repository dev image (sycl/tools/Dockerfile on the current llama-sycl-b70:stable, IGC 2.41.5; an older cached base with IGC 2.36.3 cannot build 0.2.0, see #3219), AOT bmg-g31. Model Qwen3.8-Flash-Next ISTA GSQ-RCO IQ3_XXS, --layer-split 30 --prefill 8192 --max-context 65536 --kv int8 --spec 4 --mtp <BF16 draft layer> --mtp-max-t 4 --spec-min-p 0 --stream-experts --expert-cache auto, one slot, greedy, two fixed coding prompts with 512-token replies, a fresh engine per arm, then fresh 4K and 32K prompts. Coherence check and per-card health after every stop.

Passed:

  • qsa_verify_batch_parity --selftest --write-ref (0.2.0-beta + this branch, head 1c501b02, one B70), then with STRATA_QSA_TOPK_SCAN=1 STRATA_QSA_SCORES_TRANSPOSED=1 STRATA_ATTN_MERGE_ACTIVE=1 --selftest --ref: both qsa_verify_batch_parity: PASS (0 failures), the second against the first run's hashes.
  • One stream (tok/s per prompt; output SHAs and draft counts in all three rows identical):
prompt 1 prompt 2 4K / 32K read tok/s
main e88ee39d 70.6 73.9 1,219 / 2,078
this branch, switches unset 70.7 73.8 1,219 / 2,085
all four switches 70.8 74.1 1,220 / 2,080
  • Two streams in one window ("parallel": 2, --batch-groups 1, --max-context 16384 --vram-reserve-mib 512; a layer split runs no MTP drafts in the slots), aggregate tok/s, 2 runs: unset 54.68 / 61.44, switches 55.73 / 62.55 (+1.9% / +1.8%); per-stream output SHAs identical between the arms. The engine log shows STRATA_BATCH_QSA_ATTN=1 and batch windows of up to 2 sequences on both stages.
  • Coherence true and per-card health passed after every stop.

Failed: none observed.

Not run: the kernel bench on 0.2.0 (unchanged code; on 0.1.x, us at 1K / 16K / 64K: batch 2x1 selection + attention 102.8 / 184.0 / 252.6 -> 62.3 / 107.9 / 156.2, 2x2 183.6 / 365.0 / 498.2 -> 78.3 / 138.2 / 205.0, top-k scan 16K / 64K 36.3 / 57.9 -> 19.5 / 42.1, transposed scores 5.5 / 18.7 / 63.1 -> 4.6 / 14.1 / 43.2, MTP merge 86.9 / 223.7 / 460.9 -> 41.0 / 157.2 / 335.9); STRATA_QSA_TOPK_SCAN in the engine (the wide top-k is only used above ~135K cells, and --max-context 200000 does not fit every expert on a plain two-card layer split), --batch-mtp windows of 2 rows per slot (refused on a layer split), CUDA/HIP (not touched).

Limits

  • The end-to-end gain at 16K-65K contexts is small (0.3-2%); the switches matter more at long context and in MTP batch windows, which this setup cannot exercise on main.
  • The docs/INTEL.md section quotes the 0.1.x measurement (main 296b59d2); I can swap in the 0.2.0 numbers.
  • Prepared with AI assistance (Claude Code): the code, the measurements and this text were produced by Claude on the submitter's two Arc Pro B70s, at the submitter's request.

🤖 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/2806 **Author:** [@hotschmoe](https://github.com/hotschmoe) **Created:** 10/16/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/sycl-decode-attn` --- ### 📝 Commits (1) - [`1c501b0`](https://github.com/Niko1221/Strata/commit/1c501b02ae368bcc3a75f5dc27efa8b535815b53) sycl: decode QSA selection and attention in fewer, shorter launches (opt-in, bitwise) ### 📊 Changes **7 files changed** (+1008 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `docs/INTEL.md` (+31 -0) 📝 `sycl/CMakeLists.txt` (+12 -0) ➕ `sycl/include/strata/qsa_decode_attn_multi.hpp` (+24 -0) 📝 `sycl/src/core/verify.cpp` (+37 -0) 📝 `sycl/src/kernels/cuda/qsa_decode_attn.dp.cpp` (+220 -0) 📝 `sycl/src/kernels/cuda/qsa_select.dp.cpp` (+166 -0) ➕ `sycl/src/kernels/qsa_verify_batch_parity.cpp` (+518 -0) </details> ### 📄 Description ## Problem and result On an Arc Pro B70 the QSA selection (block scores, top-k) and attention of a decode window are small, latency-bound launches, and a batch window (`--batch`) ran them one row at a time. This adds four opt-in switches that do the same arithmetic in fewer launches or with less serial work. Each gives exactly the bits of the path it replaces; all are off by default, and each is a branch in front of the existing code that tests its flag first. | switch | what it does | | --- | --- | | `STRATA_BATCH_QSA_ATTN=1` | A batch window ran the scores, top-k and attention one row at a time. Now the scores run once per slot, the top-k once per window, and the attention once per window over every slot's pools. | | `STRATA_QSA_TOPK_SCAN=1` | The wide top-k kernel (capacity above ~135K cells) found each radix pass's digit with one thread walking 256 bins. Now a work-group scan. Integers only: the same ids. | | `STRATA_QSA_SCORES_TRANSPOSED=1` | The decode block scores reduce a block's (query, head) sums together: 16-31 shuffles per block instead of 20 per query, the same pairs in the same order. | | `STRATA_ATTN_MERGE_ACTIVE=1` | The attention merge of a call of 8 rows or fewer folds only the chunks its selection reaches. The MTP drafter's 32K window is 512 chunks. | Result on 0.2.0-beta, two B70s, all four on, outputs bitwise identical in every arm: two streams in one window +1.9% aggregate (54.7 / 61.4 -> 55.7 / 62.6 tok/s), one stream +0.3%. A small engine gain at these contexts; the kernels themselves are 1.3-2.6x faster (table under Validation), and the gain grows with context. ## Related discussion Feature issue #2805 (closed in the 0.2.0 tracker reset). No maintainer agreement on scope yet. If four switches are too many for the gain, `STRATA_BATCH_QSA_ATTN` alone carries most of the two-stream effect and I can split it out. ## Approach - `sycl/src/core/verify.cpp`: `STRATA_BATCH_QSA_ATTN`; in `record_window`'s QSA branch, a branch before the per-row batch loop runs the scores per slot, one `qsa_block_topk` and one `qsa_decode_attn_multi` for the window. - `sycl/include/strata/qsa_decode_attn_multi.hpp` (new) and `sycl/src/kernels/cuda/qsa_decode_attn.dp.cpp`: `qsa_decode_attn_multi` (`qsa_decode_attn_batch` over up to four pool sets per launch; mixed KV formats or `STRATA_ATTN_LANECELL=1` fall back per set), `attn_merge_active_kernel`. - `sycl/src/kernels/cuda/qsa_select.dp.cpp`: `block_topk_wide_kernel<bool SCAN = false>` (only the new launch instantiates the scan; the existing launch compiles the same code), `block_scores_multi_t_kernel<NQ>`. - `sycl/src/kernels/qsa_verify_batch_parity.cpp` (new), two ctest entries: without switches it checks the batch form against per-row calls (2x1, 2x2, 4x2, 6x1, 1x4 windows at 1K / 16K / 64K), selections against `qsa_block_topk_ref`, attention against `qsa_decode_attn_step`, 1-8-query scores against one call per query, the MTP drafter call, and writes a hash of each of 45 outputs; the second entry repeats with the three kernel switches and requires the same hashes. No tolerance anywhere. - `docs/INTEL.md`: a short section. Left alone: the default path, the prompt path, `qsa_decode_attn_step` (decode without MTP), K/V and indexer appends, streamed-K/V batch windows, CUDA and HIP. ## Validation Setup: 0.2.0-beta `main` e88ee39d against this branch rebased on it. 2x Intel Arc Pro B70 32 GB, kernel 7.1, Compute Runtime 26.22.38646.4 at run time; built with the repository dev image (`sycl/tools/Dockerfile` on the current `llama-sycl-b70:stable`, IGC 2.41.5; an older cached base with IGC 2.36.3 cannot build 0.2.0, see #3219), AOT `bmg-g31`. Model Qwen3.8-Flash-Next ISTA GSQ-RCO IQ3_XXS, `--layer-split 30 --prefill 8192 --max-context 65536 --kv int8 --spec 4 --mtp <BF16 draft layer> --mtp-max-t 4 --spec-min-p 0 --stream-experts --expert-cache auto`, one slot, greedy, two fixed coding prompts with 512-token replies, a fresh engine per arm, then fresh 4K and 32K prompts. Coherence check and per-card health after every stop. **Passed:** - `qsa_verify_batch_parity --selftest --write-ref` (0.2.0-beta + this branch, head 1c501b02, one B70), then with `STRATA_QSA_TOPK_SCAN=1 STRATA_QSA_SCORES_TRANSPOSED=1 STRATA_ATTN_MERGE_ACTIVE=1 --selftest --ref`: both `qsa_verify_batch_parity: PASS (0 failures)`, the second against the first run's hashes. - One stream (tok/s per prompt; output SHAs and draft counts in all three rows identical): | | prompt 1 | prompt 2 | 4K / 32K read tok/s | |---|---|---|---| | main e88ee39d | 70.6 | 73.9 | 1,219 / 2,078 | | this branch, switches unset | 70.7 | 73.8 | 1,219 / 2,085 | | all four switches | 70.8 | 74.1 | 1,220 / 2,080 | - Two streams in one window (`"parallel": 2`, `--batch-groups 1`, `--max-context 16384 --vram-reserve-mib 512`; a layer split runs no MTP drafts in the slots), aggregate tok/s, 2 runs: unset 54.68 / 61.44, switches 55.73 / 62.55 (+1.9% / +1.8%); per-stream output SHAs identical between the arms. The engine log shows `STRATA_BATCH_QSA_ATTN=1` and `batch windows of up to 2 sequences` on both stages. - Coherence true and per-card health passed after every stop. **Failed:** none observed. **Not run:** the kernel bench on 0.2.0 (unchanged code; on 0.1.x, us at 1K / 16K / 64K: batch 2x1 selection + attention 102.8 / 184.0 / 252.6 -> 62.3 / 107.9 / 156.2, 2x2 183.6 / 365.0 / 498.2 -> 78.3 / 138.2 / 205.0, top-k scan 16K / 64K 36.3 / 57.9 -> 19.5 / 42.1, transposed scores 5.5 / 18.7 / 63.1 -> 4.6 / 14.1 / 43.2, MTP merge 86.9 / 223.7 / 460.9 -> 41.0 / 157.2 / 335.9); `STRATA_QSA_TOPK_SCAN` in the engine (the wide top-k is only used above ~135K cells, and `--max-context 200000` does not fit every expert on a plain two-card layer split), `--batch-mtp` windows of 2 rows per slot (refused on a layer split), CUDA/HIP (not touched). ## Limits - The end-to-end gain at 16K-65K contexts is small (0.3-2%); the switches matter more at long context and in MTP batch windows, which this setup cannot exercise on main. - The `docs/INTEL.md` section quotes the 0.1.x measurement (main 296b59d2); I can swap in the 0.2.0 numbers. - Prepared with AI assistance (Claude Code): the code, the measurements and this text were produced by Claude on the submitter's two Arc Pro B70s, at the submitter's request. 🤖 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#4274
No description provided.