Repository navigation
qwen3_5 cuda: decode attention merge with a thread per head value (TF_QWEN_MERGE_WIDE, default off) - #6185
qwen3_5 cuda: decode attention merge with a thread per head value (TF_QWEN_MERGE_WIDE, default off)#6185jojomondag wants to merge 5 commits into
Conversation
|
Raw numbers behind the description's table, on 1,500 words, 0 cached tokens: 13 replies a server
24,000 words, 20,480 cached tokens: 13 replies a server
88,000 words, 86,016 cached tokens: 9 replies a server
150,000 words, 147,456 cached tokens: 7 replies a server
246,000 words, 245,760 cached tokens: 5 replies a server
The runs still owed (the hash runs with their receipts, the contract's |
Synthena Initial Review — Needs maintainer review (
|
|
On the two review warnings:
|
Synthena Initial Review — Needs changes (
|
|
On the review at A wrong statement of mine, corrected. For about an hour the description said The The early return before Staging and The cached switch's memory order (warning). The signature at the launch (warning). Receipt (warning). As in my comment above: the served table and its raw numbers are from |
Synthena Initial Review — Needs changes (
|
|
On the review at
|
…_QWEN_MERGE_WIDE, default off) The merge of an attention layer's chunk partials gives each (head, row) 256 threads, one for each of the head's values, in place of one warp of 8 values a lane. Every thread runs the warp kernel's loop over the chunks for its value (the maximum over live chunks, then the weight sum and its value's sum in chunk order, the same fmaf operands), so every output has the same bits; only who computes it changes. The switch covers the one launch of tf_q35_attn_merge; the drafter's merge keeps its own kernel. The kernel is in its own header, qwen35.cu includes it. Registered with the kernel contract (qwen-merge-wide).
… keeps its allowlisted definition The include sat between tf_q35_attn_merge and block_sums, where tools/zig/cuda_common_check.py reads it as the start of block_sums's definition and no longer finds the allowlisted fingerprint. The header needs nothing the warp merge defines, so it goes above it. No kernel's source changes. Refs ashhart#6161
…clude moved; the issue number replaces a placeholder zig/dense_serving_test.zig pins qwen35.cu's sha256, which the previous commit changed by moving the include, so test-qwen-serving-host failed there. The pin's comment and the profile row's evidence said #ISSUE and now name ashhart#6161. The wide kernel asserts that a block has a staging thread for every chunk (MAXCH <= 256) and says that its early return is the whole block's. No kernel's code changes. Refs ashhart#6161
… every device row count edge The merge's grid is (query heads, rows). Qwen 3.5/3.8 admit up to 32 query heads (max_query_heads) and the partials hold up to 128 rows (most_verify), but the contract ran 24 heads and at most 64 rows. It now also runs 8, 16 and 32 heads, 65 and 128 rows, and a device row count of 0, 1, 127 and 128 at 128 rows. Every row past the count must keep the output's fill bytes in the wide kernel's output. The cases move to contract_qwen_merge_wide_cases.zig, whose host test (under test-qwen35-merge-wide-host) fails when the table misses one of those limits.
7d51965 to
f576d37
Compare
|
Thanks @jojomondag. We rebased this onto today's main ourselves (your three commits kept as yours), resolved the conflicts, and added one commit that widens the merge-wide device contract to 8-32 heads, 1-128 rows and the 0/1/127/128 row-count edges, with a host test that fails before and passes after. We also re-pinned
|
|
Thanks @jojomondag. Both blockers are settled. The The remaining verification runs on this head are ours: the switch unset against set twice with reply hashes, the kernel-contract summary, and the bf16, paged and two-stream served cells. We're running them now. Nothing more is needed from you. The planted controls and the byte-equal repeats in the device test are exactly the right shape for this change. Thank you.
|
What this changes
Every Qwen 3.5/3.8 decode attention ends in
tf_q35_attn_merge: one warp for each (head, row), each lane holding 8 of the head's 256 values and walking the row's chunk partials in order. WithTF_QWEN_MERGE_WIDE=1(default off) that one launch takestf_q35_attn_merge_widewith a block of 256 threads, one output value a thread. The chunk maxima and weights are staged once in shared memory, then every thread runs the warp kernel's loop for its value: the maximum over live chunks, thenlsum = fmaf(PL, e, lsum)andacc = fmaf(PO, e, acc)withe = __expf(PM - mx), in chunk order, andacc / lsumrounded to bf16. Each output's operands and their order are the warp kernel's, so its bits are too; there is no other reduction order and no tolerance. Unset, the launch, its block width and every other path are today's.0ba35fe6d, three commits.1da3ff553is the change (21 files, +337 −5, of which 230 lines are the device testcontract_qwen_merge_wide.zig, 34 the kernel headerqwen35_attn_merge_wide.cuh, 37 the selectorcuda_merge_wide.zigwith its host test).dbfd89598moves the header's#includeinqwen35.cufrom belowtf_q35_attn_mergeto above it: where it stood,tools/zig/cuda_common_check.pyread it as the start ofblock_sums's definition and no longer found the allowlisted fingerprint, which is what failedfast-gateon the first head.7d519658dre-pinsqwen35.cu's bytes inzig/dense_serving_test.zig(the move changed them, sotest-qwen-serving-hostfailed ondbfd89598), puts qwen3_5 cuda: decode attention merge with a thread per head value (opt-in TF_QWEN_MERGE_WIDE): decode +0.2 to +2.0 % on one RTX 5090, every output byte equal #6161 where the profile row and the pin's comment said#ISSUE, and adds astatic_assert(MAXCH <= 256)and a comment to the kernel header. No kernel's code changes: with nvcc 13.0.88 and with nvcc 13.4 at sm_120 the SASS of all 34 functions ofqwen35.cuis the same on all three heads. The branch merges into current main0ca167746without a conflict. Merged with main,test-gradient-servingwill be red on the pin ofzig/src/platform/environment.zig(the switch's row), as on qwen3_5 cuda: decode MLP gate and up as one segmented launch off GB10 (TF_QWEN_MLP_SEG, default off) #6163; I have left the re-pin to the landing, since the hash depends on which switch lands first.atc overlap --json: run at 2026-12-03 11:28 UTC with ATC 0.9.6 on1da3ff553. 54 open pull requests share files with this one. Of the 10 that could be test-merged, 3 conflict: qwen27 metal: qk projections, flat glue and Metal 4 verify passes, each bit-identical and switchable #2342 (2 files), qwen27 Metal: plain greedy picks ride the verify's last command buffer (#2930) #2936 (1), hip ranks: every byte after the key proof crosses the link in sealed records #3075 (2). 44 could not be test-merged within ATC's limits (complete: false:timeLimit,pullRequestsLimit,otherPullRequestsLimit,pullFilesUnavailable). Nothing is claimed or started.Checks on this head
7d519658don main0ba35fe6d. The host checks below ran on this head. The device runs ran on1da3ff553(the same kernels by SASS, above) and are repeated on this head with the runs under "Not run yet".python3 tools/zig/lean_check.py, on the base and on this head: 88 and 88, the same findings (0 new).zig build -Dfixed-cpu test-host: exit 0, no failed step. (It failed ondbfd89598, in the pin named above; an earlier version of this description said otherwise.)The
fast-gatesteps on a trial merge with main0ca167746:tools/pr_check.py --base origin/main --pr 6185(0 errors; lean 88 against 88),git diff --check,tools/zig/cuda_common_check.py(61 local copies, 0 violations),cuda_fragment_check.py,cuda_common_check_test.py,tools/test_pdl_early_loads.py,zig fmt --check build.zig zigandzig test zig/tests/portable_names.zig: all pass.Host selector test,
zig build test-qwen35-merge-wide-host(reached bytest-host): which kernel and block width the merge takes with the switch unset and set; exit 0. With a wrong expectation planted it fails (expected 1, found 2, 23 pass, 1 fail, exit 1).zig fmt --check build.zig zigandgit diff --check: clean.zig build nativeandzig build compile-cuda-testswith-Dsm=120: both compile.Device test with planted controls, byte-equal repeats and guards,
tf-cuda-test qwen-merge-wideon one RTX 5090 (nvcc 13.4, sm_120), on1da3ff553, exit 0. Both merges run on the same partials at 24 query heads, each case twice, guard bytes checked after each:The cases cover chunk counts 1, 2, 61, 63 and 64, rows past the device row count (which must stay untouched), chunks of zero weight, -Inf and NaN maxima, and garbage past each row's chunk count. The four controls must differ and do; the swapped-chunks one runs on a head built so that the fp32 order changes the bf16 result.
Compiler and per-SM usage records,
tf-cuda-test kernel-contract-limitson fatbins built by nvcc 13.0.88 for sm_80/86/89/120/121, on1da3ff553:record currentfor the new launch on all five.The tool exits 1 on stale records of other families, which main
0ba35fe6dcarries too. I have no 13.2 or 13.3 compiler for the record sets between 13.0 and my device compiler.qwen35.cu's other kernels: the SASS of its 33 existing functions is the same on main0ba35fe6dand on this head (nvcc 13.0.88 and nvcc 13.4, sm_120).fast-gatefailed oncuda_common_check.py(fixed bydbfd89598);zigfails on the serving pin ofenvironment.zig(above) and failed ondbfd89598on theqwen35.cupin too (fixed by7d519658d);verifyis the receipt gate. Not run yet on this head.tools/perf_receipt.py(main's binary against the head's, the switch set, a control with it unset, and a repeat);tf-cuda-test kernel-contractwith itsSUMMARYline on the device;Receipt
Main against branch: cells and numbers, or why they can't be run: the switch unset against set on this head (unset is main's path: the launch is
tf_q35_attn_mergewith 32 threads). One RTX 5090, one server an arm (the switch is read once), order unset, set, set, unset in one run;--drafter --kv-cache fp8 --prompt-precision int8 --context 262144 --parallel 1 --prompt-cache-gib 24,tools/bench_long_decode.py --tokens 256 --seed 1234, sampled replies (T=1) and one greedy reply an arm and cell. Server binary sha256c225c7945b2446c4…, built from1da3ff553. tok/s is all tokens over all decode time of a cell's replies; the last three columns are per reply (the same reply in the four servers):How far these go. At 0 and 20,480 cached tokens the gain is above the baseline's own variation: every reply is faster in both set servers, and the two unset servers are 0.1 % apart. From 86,016 cached tokens on it is not: at 86,016 the totals read +0.8 % but the median reply only +0.12 %, and single replies move by up to 3.4 % between the two set servers; at 147,456 and 245,760 the two unset servers are as far apart (2.6 % and 1.0 %) as the change (one reply of the second unset server at 147,456 ran 9.5 % slower than in the first). So for the long contexts these runs show no loss and no established size. Every reply's token and output hash equals the first server's in all four servers of every cell (47 replies a server). No
panicline in the eight server logs.All earlier attempts, in another build: the same kernel on main
79f40fb76(withTF_CUDA_TEST_ATTN_MT2=1,TF_QWEN_PROMPT_SPLITK=1,TF_QWEN_LAZY_SAVE=1,TF_QWEN_REQUEST_STARTS=1), same card. On this branch the table above is the only served run.The raw per-reply numbers and hashes of the table are in the first comment below.
Boxes it reaches: Qwen 3.5/3.8 decode attention on CUDA, every form that ends in
tf_q35_attn_merge(bf16 and fp8 caches, whole and paged, the MT2, w2, rows and join forms, and prompt forwards that take the decode partials), only with the switch set. The drafter's own merge (tf_q35d_attn_merge) and the prompt tile path, which has no merge, are untouched. The 256-thread block assumes a head of 256 values (static_assert), which every Qwen 3.5/3.8 geometry has.New switch? Default, accepted values, profile row:
TF_QWEN_MERGE_WIDE,0or1, unset0, profile classidentical, indocs/environment.md,docs/environment-names.md,platform/environment.zig,environment_valid_cases.zig,core/profile.zigand the CLI's environment list. One new kernel in theqwen35image, registered with the kernel contract. No stored-data change.Environment, with the TensorFold commit, Zig and backend toolchain, machine and GPU, checkpoint and revision: heads
1da3ff553(device runs) and7d519658d(host checks) on main0ba35fe6d,zig build native -Dsm=120, Zig 0.17.0, nvcc 13.4 (usage records from nvcc 13.0.88); one RTX 5090 32 GB (170 SMs), driver 615.78.08, Ryzen 7 9800X3D, Linux, nothing else on the GPU during a timed run;TensorFold/Qwen3.8-27B-MLX-4bit@22d8d538, drafterz-lab/Qwen3.8-27B-DFlash2@50307d4c.Paths and platforms the change reaches, which I ran and which I could not: ran on sm_120 (170 SMs): one stream, drafted, greedy and sampled, an fp8 whole cache, int8 prompts, 0 to 245,760 cached tokens. Not run yet: bf16 caches, paged caches, two streams (above). Could not run: sm_121 and other SM classes.
Exactness, from
tools/bench_concurrent.py --alone --serialortoken_shaagainst"draft": false: the fixture's token and output hashes in every server, and the device test's byte comparison of the two kernels with its four planted controls. Drafted against"draft": falsecomes with the hash runs.Main against this branch, same machine and checkpoint, posted before asking for a run on our machines (or why you can't): the table above (unset is main's path). Main's binary against the head's comes with the hash runs.
Decode speed before and after, from
tools/bench_openai.py: the table above.Prompt speed before and after: not measured. Prompt forwards that take the decode partials reach the merge; the prompt tile path does not.
Licence of any new weights or drafter, or "n/a": n/a
Checklist
The title and description match the head commit, including the receipt and the stack.
New tests fail before the change, pass after it, and skip cleanly without their dependency.
Comments and docstrings are one line. No measurements or history in the source.
No personal data, machine names, internal hosts or local paths in the diff or its commits. No AI attribution lines.
Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
Drafted output equals
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. None of the three is run on this change yet; drafted against"draft": falseand concurrent against solo follow with the runs listed under "Not run yet".No precision traded for speed. If the bits change, the description says which sums change and why.
Decode and prompt processing are no slower than main at one stream and the widest admitted; with
--drafter, no slower than without it, greedy and sampled. Measured: decode at one stream with--drafter. Two streams, the drafter off and prompt speed were not measured.