mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3905] [Engine] qwen35: faster decode chain and prompt expert stream (two kernels always on, two opt-in flags) #4823
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#4823
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/3905
Author: @xyehya
Created: 10/24/2026
Status: 🔄 Open
Base:
main← Head:pr/q36-04-bit-identical📝 Commits (10+)
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 tokensa3c2dc4[Engine] qwen35: k_add_rms_q and k_moe_out in registers with a one-barrier same-order sum9017b2f[Engine] qwen35: --side-stream: z, alpha / beta (and the attention k, v) on a stream beside the first matrix📊 Changes
13 files changed (+3158 additions, -91 deletions)
View changed files
📝
CMakeLists.txt(+29 -0)📝
docs/QWEN36.md(+112 -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(+519 -83)➕
src/qwen35/q36_gdn.cuh(+258 -0)📝
src/qwen35/q36_kernels.cuh(+102 -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 4 of 9; it builds on #3904.
Branch
pr/q36-04-bit-identical, stacked onpr/q36-03-prompt-read.Problem and result
Three places in the Qwen3.6 engine path wait for something they do not need to wait for. Everything below keeps the logits byte-identical to the previous level, and with no flag the only change is item 1 (two kernels, bit-identical by construction and by test). Items 2 and 3 are opt-in flags.
k_add_rms_qand the MoE end (k_moe_out_s8: 8 experts, 2048 wide) re-readhthrough a volatile load and need nine or ten barriers for a 256-way sum. They now keep their values in registers and use one barrier, with the same pairing of the sum (same bits). Also always on: in the MMQ prompt path each token's MoE input is quantized once and scattered to its sorted rows (MMQ::quantize_scatter, already in the tree; NVFP4 activations keepquantize()), the wait for the routing counts is an event wait, and the shared expert is enqueued before it. These move no bytes.--side-stream(decode): the GDNz/alpha/betaproducts and the attentionk/vproducts are independent of the layer's first matrix. They run on a second, higher-priority stream and join before the kernel that reads them.--split-stage-copy(prompt reads in the hybrid mode): the resident experts' device-to-device copies to the staging buffer ran on the PCIe copy stream, behind compute kernels. With the flag they run on a stream of their own, and the split copy is taken from 1/8 of the experts resident (before: below half).Result on an RTX 5080 16 GB (same day,
--max-context 262144 --kv int8 --gqa-attn --fused-prompt-attn --chunked-gdn, level 03 against this level; runs in Validation):--side-stream --split-stage-copyadded: total against level 03 decode +9.1% / +6.6% / +8.5% at 4K / 16K / 40K; prompt read +28.4% at 4K (5,364 -> 6,887), +20.2% at 16K, +8.0% at 40K, +2.5% at 90K.Related discussion
none (no scope issue). Both flags are off by default because the gain is measured on one card only:
--side-streamcosts about 40 us of host time per token, so host-bound shapes may gain less or lose; the old half-resident rule behind--split-stage-copycame from one RTX 3060 measurement (37 of 256 resident, both copy kinds on one stream) that has not been re-run with the separate stream. If a second card's numbers show a gain, either could become a default in a later PR.Approach
STRATA_Q36_VERIFY=1for the same-bits claim.--side-streamis used only for decode steps and verify windows that are not captured in a CUDA graph (the hybrid mode never uses graphs), and only when the driver gives the side stream a higher priority than the main stream (else the flag says so and is ignored); it is ignored under HIP.STRATA_Q36_SIDE_SKEW=<us>/STRATA_Q36_SIDE_SKEW_JOIN=<us>(tests) insert a spin kernel before the side stream's first kernel / before the join, to force the interleavings natural timing does not.--split-stage-copymoves the threshold and the stream of the resident experts' copies; the bytes in staging are the same. With the flag off the copies stay where they were: the whole layer from host memory below half resident, and above that the resident runs on the copy stream, in order with the PCIe copies (the new stream and its events are created only with the flag).STRATA_Q36_STREAM_ALL=1(existing) still gives the whole-layer copy. The side stream and its events are likewise created only with--side-stream.docs/QWEN36.md. The two always-on steps are the only change to the default path; the former commit that also switched both flags on is split into three commits (kernels; side stream; MMQ prompt path steps; split copy).Validation
Revision: branch
pr/q36-04-bit-identical(af08278), level 03 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:
Build CUDA sm_120 and "75;120" (commands as in the level-01 PR), target
strataplus the parity tools of the lower levels.q36_attn_parity,q36_pattn_parity 1,q36_gdn_parity 1: pass.Default path (no flags) against level 01's binary, fp32 cache: logits
cmpat 4K and 14K IDENTICAL / IDENTICAL (command as in the level-02 PR). With--kv int8 --gqa-attnagainst level 02's binary (gate_a.sh): IDENTICAL / IDENTICAL.Free-running slot count unchanged: 90 of 256 (fp32, 65K), 82 (int8, 262144).
The side stream's race test on this branch (
--kv int8 --gqa-attn, fixed 56 slots, logitscmpof--side-streamagainst the same binary without it): plain--mtp 0logits IDENTICAL / IDENTICAL (4K / 14K); withSTRATA_Q36_SIDE_SKEW=300 STRATA_Q36_SIDE_SKEW_JOIN=300(spin kernels of 300 us at the fork and at the join)--mtp 0logits IDENTICAL / IDENTICAL. Verify windows (--dump-full-logits/--forcedo not run the speculative path, so these are free greedy generation of 160 tokens, 4K and 14K prompts, generated ids compared):--mtp 2plain and with the skews, and--mtp 3with the skews, IDENTICAL in all runs (--mtp 3: 95 of 192 drafts accepted, so windows of up to 4 rows ran).--split-stage-copyagainst the same binary without it (--mtp 0, logits at 4K / 14K): IDENTICAL / IDENTICAL.Above half resident, flags off (
--expert-slots 128 --max-context 8192, 4K prompt, so the resident-runs branch of the staging copy runs): level 03's binary against this branch's, logits IDENTICAL (128 of 256 experts per layer resident, so the branch ran); with--split-stage-copy: IDENTICAL (bits are the same; speed is not measured).The earlier commits report
STRATA_Q36_VERIFY=1 --no-graph0 mismatches in 92,263 comparisons for item 1; that run is from the tree the commit came from, not re-run on this branch.The timings below were taken on the revision before the last amend of this branch (stack-4 changed only the staging-copy stream when at least half of the experts are resident, which this card does not reach: 82 to 97 of 256). The submitted revision
af08278was compared with the timed one by full-logitcmpwith this level's flags on both sides (--attn-mma --fused-prompt-attn --chunked-gdn --side-stream --split-stage-copy, fixed 56 slots, 4K and 14K prompts): IDENTICAL / IDENTICAL (64,563,200 bytes each).Timing (same box and day, 2026-10-23; one cold
strataprocess per run under the GPU lock, arms alternated A-B-A-B, two runs each; level 03 built from022982d, this level from the revision before the amend). Command,$P/$G= prompt ids and forced text of that depth,[flags]as in the table:Arms: level 03 (no extra flags); this level (no extra flags); this level with
--side-stream --split-stage-copy. 94 experts per layer in VRAM in all three, GPU share and CPU entries equal within a depth. Individual runs, then the mean (tok/s):Failed: none observed.
Not run:
--side-streamand--split-stage-copyone at a time (the timing arm has both on); decode with--mtpabove 0 (timed with--mtp 0); timing of the submitted revision (compared by logits only).--batchrows with--side-stream.--split-stage-copyon a 12 GB card (RTX 3060, 37 of 256 resident) and--side-streamon a driver with one priority level.Limits
One card, one model. The RTX 5080 in these runs holds 82 to 97 of 256 experts per layer, so the branch above half resident (the path an RTX 4090/5090-class card with 24 or 32 GB takes) was not reached in a normal run; it is unchanged by this PR when the flag is off, and a short run with 128 slots at a small context (below) compared the logits only. On the card in the docs
--side-streamgives +1 to +1.4% in decode and--split-stage-copy+2% to +17% in the prompt read (4K / 16K / 40K); a machine where the host is the limit may not gain. The timing pass above measured the two flags together: decode +4.1% to +4.2% on top of the always-on kernels, prompt read +2.5% to +28.4% (4K to 90K).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.