[PR #3904] [Engine] qwen35: faster prompt reads at long context (--fused-prompt-attn, --chunked-gdn) #4822

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

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3904
Author: @xyehya
Created: 10/24/2026
Status: 🔄 Open

Base: main ← Head: pr/q36-03-prompt-read


📝 Commits (8)

  • 1883224 [Engine] qwen35: accept Q4_K down-projection experts
  • 9903b66 [Engine] qwen35: a parity case for the Q4_K down experts at FF 512
  • aab82b7 [Engine] qwen35: --kv int8 for the qwen35moe engine, and --tokens-file
  • 0a2b727 [Engine] qwen35: grouped-query decode attention (#3641's kernel), --kv fp16 and k8v4
  • 73ba60e [Engine] qwen35: int8 decode attention reads the cache through shared memory, one pass per verify window
  • efb3066 [Engine] qwen35: --attn-mma, decode attention on tensor cores for the int8 cache (not bit-identical)
  • 6e21c89 [Engine] qwen35: --fused-prompt-attn, the prompt attention in one tensor-core kernel from the int8 cache
  • 022982d [Engine] qwen35: --chunked-gdn, the prompt's gated delta rule in pieces of 16 tokens

📊 Changes

12 files changed (+2859 additions, -56 deletions)

View changed files

📝 CMakeLists.txt (+29 -0)
📝 docs/QWEN36.md (+72 -1)
📝 setup.py (+2 -2)
📝 src/kernels/cuda/iq_kernels.cu (+3 -3)
📝 src/kernels/native_expert_parity.cpp (+7 -2)
➕ src/qwen35/q36_attn.cuh (+890 -0)
📝 src/qwen35/q36_engine.cu (+362 -48)
➕ src/qwen35/q36_gdn.cuh (+258 -0)
➕ src/qwen35/q36_pattn.cuh (+297 -0)
➕ tools/qwen35/q36_attn_parity.cu (+500 -0)
➕ tools/qwen35/q36_gdn_parity.cu (+199 -0)
➕ tools/qwen35/q36_pattn_parity.cu (+240 -0)

📄 Description

Series (each stacked on the one before; review in order): #3699 → #3903 → #3904 → #3905 → #3906 → #3907 → #3908 → #3909 → #3910. Scope discussion: #3700. This is 3 of 9; it builds on #3903.

Branch pr/q36-03-prompt-read, stacked on pr/q36-02-decode-attn.

Problem and result

At long context the prompt read of the Qwen3.6 engine path spends its time in two places that are not the experts: the attention converts the whole int8 cache to fp16 for every chunk and layer and writes fp32 scores and fp16 probabilities to memory and back; and the DeltaNet layers run the gated delta rule one token after another (two barriers per token). Two opt-ins, both off by default:

  • --fused-prompt-attn (int8 cache, sm_80+, 8 query heads per KV head): the prompt attention in one tensor-core kernel straight from the int8 cells, online softmax. It also frees the fp16 K/V copies and the score buffers (0.875 GiB at 262K cells), which the experts get as more slots.
  • --chunked-gdn: the gated delta rule in pieces of 16 tokens.

Neither is bit-identical to the default path (sums in another order). Result on an RTX 5080 16 GB (same day, --max-context 262144 --kv int8 --gqa-attn, level 02 against level 03 with both flags; fresh prompt read, tok/s, two runs each, in Validation): 4K 5,350 -> 5,364 (+0.3%), 16K 5,689 -> 5,799 (+1.9%), 40K 4,553 -> 5,549 (+21.9%), 90K 2,837 -> 4,377 (+54%), 200K 1,074 -> 2,785 (+159%; 186.7 s -> 72.1 s for 200,704 tokens). KL against the default path is not measured on this branch.

Scope: #3700 (see the level-02 PR). Builds on that PR (--kv int8). No maintainer answer yet on scope; draft until there is one.

Approach

Each flag is a separate kernel file (q36_pattn.cuh, q36_gdn.cuh) and a branch at one call site in q36_engine.cu. With the flag off the call site runs the old kernel. --fused-prompt-attn is ignored with a message when the cache is not int8, the card is below sm_80 or the head shape differs; the HIP build gets stubs and never enables either flag. Both kernels have a parity tool against a double-precision oracle (q36_pattn_parity, q36_gdn_parity; GPU, return 77 when no suitable device).

Validation

Revision: branch pr/q36-03-prompt-read (022982d), level 02 below it, origin/main 5c8dd32. Environment: Fedora 44 (Linux 7.2.11), CUDA 13.4.92 with g++-15 as host compiler, RTX 5080 16 GB (driver 615.78.08), Core Ultra 9 285K, 61 GB DDR5 (6400 MT/s configured), Sage-A1.5 Q4_K_M with the BF16 ssm_alpha/ssm_beta graft (the file of #3699).

Passed:

  • Build CUDA sm_120 and "75;120", targets strata q36_attn_parity q36_pattn_parity q36_gdn_parity.
  • q36_attn_parity, q36_pattn_parity 1, q36_gdn_parity 1: all ok.
  • Default path against level 01's binary, flags off, fp32 cache: logits cmp at 4K and 14K IDENTICAL / IDENTICAL (command as in the level-02 PR).
  • With --kv int8 --gqa-attn and the new flags off, against level 02's binary: gate_a.sh (same command plus --kv int8 --gqa-attn), IDENTICAL / IDENTICAL.
  • Slot count, free-running: 90 of 256 (fp32, 65K) and 82 (--kv int8 --gqa-attn, 262144), both unchanged from level 02.

Timing (same box and day, 2026-10-23; binaries built from level 02 efb3066 and this branch 022982d; one cold strata process per run under the GPU lock, arms alternated A-B-A-B, two runs each; 16K is a separate driver run of the same kind). Command ($P = the prompt ids of that depth):

strata --native $MODEL --max-context 262144 --prefill auto --pool-workers 16 --kv int8 --gqa-attn [--fused-prompt-attn --chunked-gdn] --mtp 0 --tokens-file $P --n 1

pp = prompt read tok/s, individual runs, then the mean:

prompt level 02 level 03 with both flags change
4,096 5358 / 5342.4 = 5350.2 5364.2 / 5364.3 = 5364.2 +0.3%
16,384 5689.7 / 5688.7 = 5689.2 5798.3 / 5799.3 = 5798.8 +1.9%
40,960 4552.7 / 4552.3 = 4552.5 5546 / 5551 = 5548.5 +21.9%
90,112 2839.9 / 2833.6 = 2836.8 4371.4 / 4381.9 = 4376.6 +54.3%
200,704 1075 / 1073.8 = 1074.4 2785.1 / 2784 = 2784.6 +159.2%

Decode (forced 256 tokens, same command with --n 256 --force): level 03 with the flags off decodes like level 02 (4K 177.2 against 176.7 tok/s, 40K 172.1 against 171.8), so the build alone costs nothing. With both flags: 4K 176.7 -> 179.8 tok/s (+1.8%), 40K 171.8 -> 171.1 (-0.4%, inside the run-to-run spread). Experts per layer in VRAM at 262144: 82 -> 94 with the flags (the fused kernel's prompt buffers are smaller).

Failed: none observed.

Not run:

  • KL of either flag against the default path, on this branch. The figures in the docs were measured on the tree these commits came from, not on this branch; the timing pass above is speed only.
  • The two flags separately (the timing arm has both on).
  • HIP / SYCL builds (the headers have HIP stubs; never compiled for HIP).
  • sm_75 execution (compiled only), other sm_80+ cards.

Limits

  • Neither flag is bit-identical to the default path: the docs give the KL against the default path and against the chunk-1024 floor; the maximum over single steps is large for --fused-prompt-attn (2.67 at one step of one prompt in the docs' table), so it needs a look from a maintainer before anyone suggests it as default.
  • --chunked-gdn is built for 128 x 128 states (Qwen3.6-35B-A3B). Chunks of 9 to 33 rows are a few microseconds per layer slower than the default kernel.
  • Measured on one card.

Not specific to Sage-A1.5

Sage-A1.5 is a fine-tune of Qwen3.6-35B-A3B with the same architecture and tensor layout, so this path runs the base model
unchanged. The before/after numbers above are Sage-A1.5's. The base model was measured once, on my fork's build of the whole series
(xyehya/Strata branch q36-r2: these PRs' flags on, plus a few fork-only defaults), same card and server sweep, with
STRATA_Q8_PACKED=0 (that file keeps its attention and DeltaNet matrices in Q8_0, and the packed copy would take 1.9 GiB
from the expert slots): Unsloth's Qwen3.6-35B-A3B-UD-Q4_K_XL (from unsloth/Qwen3.6-35B-A3B-MTP-GGUF),
262K int8 cache, decode 221 / 208 / 199 / 187 / 164 / 159 tok/s and prompt read 6,473 / 7,010 / 6,277 / 4,656 / 3,411 /
2,506 tok/s at 4K / 16K / 40K / 90K / 160K / 240K (Sage-A1.5 on the same build: decode 231 / 210 / 213 / 187 / 179 / 162).
Not measured: this PR's own before/after on the base model.

🤖 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/3904 **Author:** [@xyehya](https://github.com/xyehya) **Created:** 10/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/q36-03-prompt-read` --- ### 📝 Commits (8) - [`1883224`](https://github.com/Niko1221/Strata/commit/1883224f75d2f2fc29aa303e750c2918385f0af4) [Engine] qwen35: accept Q4_K down-projection experts - [`9903b66`](https://github.com/Niko1221/Strata/commit/9903b6609a29b699c088f78f29810d16458d45f8) [Engine] qwen35: a parity case for the Q4_K down experts at FF 512 - [`aab82b7`](https://github.com/Niko1221/Strata/commit/aab82b73b4a3c0be261c5432dc65d455ac216155) [Engine] qwen35: --kv int8 for the qwen35moe engine, and --tokens-file - [`0a2b727`](https://github.com/Niko1221/Strata/commit/0a2b72720c69800b811f8baea30fdfb4bb164ef3) [Engine] qwen35: grouped-query decode attention (#3641's kernel), --kv fp16 and k8v4 - [`73ba60e`](https://github.com/Niko1221/Strata/commit/73ba60e899f38d6698e9d857d04b7e08a3a4b54c) [Engine] qwen35: int8 decode attention reads the cache through shared memory, one pass per verify window - [`efb3066`](https://github.com/Niko1221/Strata/commit/efb3066fc0908c060cbccf749741d848381f2124) [Engine] qwen35: --attn-mma, decode attention on tensor cores for the int8 cache (not bit-identical) - [`6e21c89`](https://github.com/Niko1221/Strata/commit/6e21c895f215690eae1ae196b428e1090fcc1db9) [Engine] qwen35: --fused-prompt-attn, the prompt attention in one tensor-core kernel from the int8 cache - [`022982d`](https://github.com/Niko1221/Strata/commit/022982df36843763f7f43978bf3259d95a3948d0) [Engine] qwen35: --chunked-gdn, the prompt's gated delta rule in pieces of 16 tokens ### 📊 Changes **12 files changed** (+2859 additions, -56 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+29 -0) 📝 `docs/QWEN36.md` (+72 -1) 📝 `setup.py` (+2 -2) 📝 `src/kernels/cuda/iq_kernels.cu` (+3 -3) 📝 `src/kernels/native_expert_parity.cpp` (+7 -2) ➕ `src/qwen35/q36_attn.cuh` (+890 -0) 📝 `src/qwen35/q36_engine.cu` (+362 -48) ➕ `src/qwen35/q36_gdn.cuh` (+258 -0) ➕ `src/qwen35/q36_pattn.cuh` (+297 -0) ➕ `tools/qwen35/q36_attn_parity.cu` (+500 -0) ➕ `tools/qwen35/q36_gdn_parity.cu` (+199 -0) ➕ `tools/qwen35/q36_pattn_parity.cu` (+240 -0) </details> ### 📄 Description Series (each stacked on the one before; review in order): #3699 → #3903 → #3904 → #3905 → #3906 → #3907 → #3908 → #3909 → #3910. Scope discussion: #3700. This is 3 of 9; it builds on #3903. Branch `pr/q36-03-prompt-read`, stacked on `pr/q36-02-decode-attn`. ## Problem and result At long context the prompt read of the Qwen3.6 engine path spends its time in two places that are not the experts: the attention converts the whole int8 cache to fp16 for every chunk and layer and writes fp32 scores and fp16 probabilities to memory and back; and the DeltaNet layers run the gated delta rule one token after another (two barriers per token). Two opt-ins, both off by default: - `--fused-prompt-attn` (int8 cache, sm_80+, 8 query heads per KV head): the prompt attention in one tensor-core kernel straight from the int8 cells, online softmax. It also frees the fp16 K/V copies and the score buffers (0.875 GiB at 262K cells), which the experts get as more slots. - `--chunked-gdn`: the gated delta rule in pieces of 16 tokens. Neither is bit-identical to the default path (sums in another order). Result on an RTX 5080 16 GB (same day, `--max-context 262144 --kv int8 --gqa-attn`, level 02 against level 03 with both flags; fresh prompt read, tok/s, two runs each, in Validation): 4K 5,350 -> 5,364 (+0.3%), 16K 5,689 -> 5,799 (+1.9%), 40K 4,553 -> 5,549 (+21.9%), 90K 2,837 -> 4,377 (+54%), 200K 1,074 -> 2,785 (+159%; 186.7 s -> 72.1 s for 200,704 tokens). KL against the default path is not measured on this branch. ## Related discussion Scope: #3700 (see the level-02 PR). Builds on that PR (`--kv int8`). No maintainer answer yet on scope; draft until there is one. ## Approach Each flag is a separate kernel file (`q36_pattn.cuh`, `q36_gdn.cuh`) and a branch at one call site in `q36_engine.cu`. With the flag off the call site runs the old kernel. `--fused-prompt-attn` is ignored with a message when the cache is not int8, the card is below sm_80 or the head shape differs; the HIP build gets stubs and never enables either flag. Both kernels have a parity tool against a double-precision oracle (`q36_pattn_parity`, `q36_gdn_parity`; GPU, return 77 when no suitable device). ## Validation Revision: branch `pr/q36-03-prompt-read` (022982d), level 02 below it, `origin/main` 5c8dd32. Environment: Fedora 44 (Linux 7.2.11), CUDA 13.4.92 with g++-15 as host compiler, RTX 5080 16 GB (driver 615.78.08), Core Ultra 9 285K, 61 GB DDR5 (6400 MT/s configured), Sage-A1.5 Q4_K_M with the BF16 `ssm_alpha`/`ssm_beta` graft (the file of #3699). **Passed:** - Build CUDA sm_120 and "75;120", targets `strata q36_attn_parity q36_pattn_parity q36_gdn_parity`. - `q36_attn_parity`, `q36_pattn_parity 1`, `q36_gdn_parity 1`: all ok. - Default path against level 01's binary, flags off, fp32 cache: logits `cmp` at 4K and 14K IDENTICAL / IDENTICAL (command as in the level-02 PR). - With `--kv int8 --gqa-attn` and the new flags off, against level 02's binary: `gate_a.sh` (same command plus `--kv int8 --gqa-attn`), IDENTICAL / IDENTICAL. - Slot count, free-running: 90 of 256 (fp32, 65K) and 82 (`--kv int8 --gqa-attn`, 262144), both unchanged from level 02. **Timing** (same box and day, 2026-10-23; binaries built from level 02 `efb3066` and this branch `022982d`; one cold `strata` process per run under the GPU lock, arms alternated A-B-A-B, two runs each; 16K is a separate driver run of the same kind). Command (`$P` = the prompt ids of that depth): ``` strata --native $MODEL --max-context 262144 --prefill auto --pool-workers 16 --kv int8 --gqa-attn [--fused-prompt-attn --chunked-gdn] --mtp 0 --tokens-file $P --n 1 ``` pp = prompt read tok/s, individual runs, then the mean: | prompt | level 02 | level 03 with both flags | change | |---|---|---|---:| | 4,096 | 5358 / 5342.4 = 5350.2 | 5364.2 / 5364.3 = 5364.2 | +0.3% | | 16,384 | 5689.7 / 5688.7 = 5689.2 | 5798.3 / 5799.3 = 5798.8 | +1.9% | | 40,960 | 4552.7 / 4552.3 = 4552.5 | 5546 / 5551 = 5548.5 | +21.9% | | 90,112 | 2839.9 / 2833.6 = 2836.8 | 4371.4 / 4381.9 = 4376.6 | +54.3% | | 200,704 | 1075 / 1073.8 = 1074.4 | 2785.1 / 2784 = 2784.6 | +159.2% | Decode (forced 256 tokens, same command with `--n 256 --force`): level 03 with the flags off decodes like level 02 (4K 177.2 against 176.7 tok/s, 40K 172.1 against 171.8), so the build alone costs nothing. With both flags: 4K 176.7 -> 179.8 tok/s (+1.8%), 40K 171.8 -> 171.1 (-0.4%, inside the run-to-run spread). Experts per layer in VRAM at 262144: 82 -> 94 with the flags (the fused kernel's prompt buffers are smaller). **Failed:** none observed. **Not run:** - KL of either flag against the default path, on this branch. The figures in the docs were measured on the tree these commits came from, not on this branch; the timing pass above is speed only. - The two flags separately (the timing arm has both on). - HIP / SYCL builds (the headers have HIP stubs; never compiled for HIP). - sm_75 execution (compiled only), other sm_80+ cards. ## Limits - Neither flag is bit-identical to the default path: the docs give the KL against the default path and against the chunk-1024 floor; the maximum over single steps is large for `--fused-prompt-attn` (2.67 at one step of one prompt in the docs' table), so it needs a look from a maintainer before anyone suggests it as default. - `--chunked-gdn` is built for 128 x 128 states (Qwen3.6-35B-A3B). Chunks of 9 to 33 rows are a few microseconds per layer slower than the default kernel. - Measured on one card. ## Not specific to Sage-A1.5 Sage-A1.5 is a fine-tune of Qwen3.6-35B-A3B with the same architecture and tensor layout, so this path runs the base model unchanged. The before/after numbers above are Sage-A1.5's. The base model was measured once, on my fork's build of the whole series (`xyehya/Strata` branch `q36-r2`: these PRs' flags on, plus a few fork-only defaults), same card and server sweep, with `STRATA_Q8_PACKED=0` (that file keeps its attention and DeltaNet matrices in Q8_0, and the packed copy would take 1.9 GiB from the expert slots): Unsloth's `Qwen3.6-35B-A3B-UD-Q4_K_XL` (from `unsloth/Qwen3.6-35B-A3B-MTP-GGUF`), 262K int8 cache, decode 221 / 208 / 199 / 187 / 164 / 159 tok/s and prompt read 6,473 / 7,010 / 6,277 / 4,656 / 3,411 / 2,506 tok/s at 4K / 16K / 40K / 90K / 160K / 240K (Sage-A1.5 on the same build: decode 231 / 210 / 213 / 187 / 179 / 162). Not measured: this PR's own before/after on the base model. 🤖 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#4822
No description provided.