Skip to content

XPU Qwen3.8-27B: decode attention takes a key's twelve exponentials as one vector exp, bit-equal - #4651

Merged
ashhart merged 9 commits into
ashhart:mainfrom
hygurlabs:xpu-qwen27-attn-exp
Nov 24, 2026
Merged

ashhart merged 9 commits into
ashhart:mainfrom
hygurlabs:xpu-qwen27-attn-exp

Conversation

@Mirrdhyn

@Mirrdhyn Mirrdhyn commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Refs #2543.

attn_decode (Qwen3.8-27B on XPU, zig/kernels/xpu/qwen27/decode.cl) computed twelve scalar exponentials a key: exp(m - mn) and exp(sc - mn) for each of the six query heads of a K/V head. They are now the 16 lanes of one vector exp (head a's two arguments in lanes a and a + 8), and each head reads its two results back with sub_group_broadcast. The arguments, fmax, the update order and every operand are unchanged, and there is no new branch.

Same bytes. The change needs two facts, both measured on the card (docs/receipts/xpu-qwen27-attn-exp/proofs/):

  • vector exp equals scalar exp on all 4,294,967,296 float bit patterns, NaNs and infinities included: 0 mismatches;
  • vector fmax equals scalar fmax on 536,870,912 pairs (all pairs of 25 special values, nearby and random patterns): 0 mismatches.

The kernel contract (card 1) passes: 21 kernels, 12 controls red as planted, 0 limit problems; attn_decode + attn_merge stay bit-equal to the upstream 1a5644892 pair at 20 shapes. The new planted control, tf_ctl_attn_exp_lanes (the same kernel with the scores in lanes 0 to 7 only), goes red at gate 3. attn_decode has 0 spill bytes at 256 GRF.

Served, one Arc Pro B70 (card 0, PCIe 5.0 x16). Main 14951bc65 against this branch, four fresh servers in the order main, branch, main, branch; Qwen3.8-27B GPTQ g128 with DFlash2, --parallel 1 --context 132096 --prompt-cache-gib 0, greedy, 256 tokens, one warm-up and three measured requests, code prompts. Decode tok/s, median of a pass, mean of the two passes of a side:

prompt tokens mode main branch branch / main token_sha256 (first 16 hex)
7,588 drafted 62.26 63.09 1.013 9764d2d6fb7cbdbf
7,588 plain 32.67 32.69 1.001 9764d2d6fb7cbdbf
28,946 drafted 36.32 37.41 1.030 1d59abb499c48841
28,946 plain 28.94 28.97 1.001 1d59abb499c48841
121,022 drafted 13.30 13.96 1.049 0ac2491477780561
121,022 plain 19.50 19.52 1.001 0ac2491477780561

In every cell the 16 requests (four passes, warm-up included) carry one token_sha256, drafted and plain share it, and the drafter's drafted, accepted and round counts are identical on both sides. The two paired ratios of a drafted cell differ by 0.001 or less.

attn_decode GPU time in a drafted round (XPU_PROFILE=1, card 0): 4 rows 8.06 to 7.60 ms and 16 rows 33.51 to 30.99 ms at 20,000 tokens (-5.7 % and -7.5 %); 23.12 to 21.72 ms and 95.69 to 90.43 ms at 58,543 tokens (-6.1 % and -5.5 %). Plain decode runs one row a token, so its gain is within 0.2 %.

Limits. Code prompts only; one host and one card for the served numbers; token equality at other shapes (text prompts, XPU_KV_INT8=1, the multi-stream path) was checked on the dev runner and is not in the receipt.

The receipt directory has the scripts, every request (runs/), the contract and limits output, the kernel logs and how to rerun the proofs.

CHANGELOG: one Unreleased bullet, (#4651, refs #2543).

@Mirrdhyn

Copy link
Copy Markdown
Contributor Author

The proofs folder now names the versions both runs used (docs/receipts/xpu-qwen27-attn-exp/proofs/README.md, 0eedf17ff): IGC 2.41.5 and compute-runtime 26.35.39758.21, on the card on 2026-11-22. The host also carries Ubuntu's IGC 2.41.16, which neither the OpenCL runtime nor ocloc loads there: LD_DEBUG=files resolves both to the 2.41.5 build. The README says to rerun both probes after a driver or compiler change.

@Mirrdhyn

Copy link
Copy Markdown
Contributor Author

On drafted decode at about 121K being below plain: #3052 is that change for the lone stream. It prices each tree width from the stream's own measured rounds, a context band each, so long contexts draw narrower trees (2.32 nodes a round at 121,022 tokens). Its receipt and this PR's use the same 121,022-token prompt (prompt_sha256 60986a50b4990e56) on card 0. There, #3052's head decodes 29.52 tok/s drafted. The warm-up request, which runs on a fresh server before the band is priced, decodes 24.34. Main's fixed 15-node tree decodes 13.30, and main plain decodes 19.50 in this PR's receipt. The two receipts were measured on different main commits (7fb9fc661 and 14951bc65), between which no qwen27, xpu or XPU kernel file changed. Every one of those requests carries the same token_sha256 (0ac2491477780561), plain included, so no tokens change. If #3052 lands, I don't think a separate issue is needed for the lone stream. Several streams sharing a round go through main's shared prices, which keep a plain option measured from the rounds themselves; I have not measured them at long context on XPU.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @Mirrdhyn for the vector-exp work and the detailed parity evidence. One small portability fix is still needed.

In zig/kernels/xpu/qwen27/decode.cl, the final sub_group_broadcast(mv, a) is inside if (lane == 0). Only lane 0 encounters the collective; for heads 1–5, the selected source lane is inactive too. That makes the broadcast undefined, so PM is not guaranteed to hold the head's maximum before attn_merge consumes it.

Please compute const float ma = sub_group_broadcast(mv, a); immediately before the branch, then store ma to PM[base] inside it. The store should remain lane-0-only.

Please make the same hoist in the planted copy in zig/kernels/xpu/contract_gate_controls.cl, while leaving its intentional score-lane mutation unchanged. Then rerun the existing contract and serving-identity checks. Thank you!

  • Synthena

@Mirrdhyn

Copy link
Copy Markdown
Contributor Author

Done in 8b99d80e3: const float ma = sub_group_broadcast(mv, a); now runs on every lane before if (lane == 0), which stores PM[base] = ma; the same hoist is in the planted copy in contract_gate_controls.cl, whose score-lane mutation is unchanged.

Rerun on card 0 (receipt section "Rerun after the review fix", ec7f6fa8e):

  • Contract: 21 kernels pass gates 1-4, 12 of 12 controls red as planted (tf_ctl_attn_exp_lanes red at gate 3), 0 limit problems; attn_decode 256 GRF, 0 spill.
  • Served, main against the branch, drafted and "draft": false: one token_sha256 per cell across both sides and both modes, equal to the receipt's at 7,588, 28,946 and 121,022 prompt tokens; drafter counters equal too. Drafted 62.26 → 63.28, 36.34 → 37.47, 13.30 → 13.97 tok/s; plain level (1.001-1.002). One pass per side this time, so these are not paired ratios.

@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thanks @Mirrdhyn. Both max broadcasts now run before the lane-zero branch, and the planted score-lane fault remains intact. The attached rerun reports all 21 kernels passing and all 12 controls caught; the saved serving rows retain matching hashes and drafter counters.

The current head merges cleanly with main. No further source correction or duplicate device run is requested. The parity evidence remains tied to the named compiler and driver versions; exact-tree CI remains before landing.

  • Synthena

@ashhart
ashhart force-pushed the xpu-qwen27-attn-exp branch from ec7f6fa to 2124808 Compare November 24, 2026 21:16
@ashhart
ashhart merged commit 2f34edf into ashhart:main Nov 24, 2026
@ashhart

ashhart commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Thank you @Mirrdhyn. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants