mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3904] [Engine] qwen35: faster prompt reads at long context (--fused-prompt-attn, --chunked-gdn) #4822
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4822
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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 experts9903b66[Engine] qwen35: a parity case for the Q4_K down experts at FF 512aab82b7[Engine] qwen35: --kv int8 for the qwen35moe engine, and --tokens-file0a2b727[Engine] qwen35: grouped-query decode attention (#3641's kernel), --kv fp16 and k8v473ba60e[Engine] qwen35: int8 decode attention reads the cache through shared memory, one pass per verify windowefb3066[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 cache022982d[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 onpr/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 inq36_engine.cu. With the flag off the call site runs the old kernel.--fused-prompt-attnis 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/main5c8dd32. 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 BF16ssm_alpha/ssm_betagraft (the file of #3699).Passed:
strata q36_attn_parity q36_pattn_parity q36_gdn_parity.q36_attn_parity,q36_pattn_parity 1,q36_gdn_parity 1: all ok.cmpat 4K and 14K IDENTICAL / IDENTICAL (command as in the level-02 PR).--kv int8 --gqa-attnand the new flags off, against level 02's binary:gate_a.sh(same command plus--kv int8 --gqa-attn), IDENTICAL / IDENTICAL.--kv int8 --gqa-attn, 262144), both unchanged from level 02.Timing (same box and day, 2026-10-23; binaries built from level 02
efb3066and this branch022982d; one coldstrataprocess 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):pp = prompt read tok/s, individual runs, then the mean:
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:
Limits
--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-gdnis 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.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/Stratabranchq36-r2: these PRs' flags on, plus a few fork-only defaults), same card and server sweep, withSTRATA_Q8_PACKED=0(that file keeps its attention and DeltaNet matrices in Q8_0, and the packed copy would take 1.9 GiBfrom the expert slots): Unsloth's
Qwen3.6-35B-A3B-UD-Q4_K_XL(fromunsloth/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.