Repository navigation
perf(qwen35/hip): the prompt conv writes q, k and v to their own rows - #2117
Conversation
|
Thanks @AbrahamCete. Writing q, k and v to their own rows from the conv drops 144 of the 27B's 160 column copies with the same sums, and the byte test against the single output pins it. Logits byte-identical on both checkpoints and served tokens equal, with the prefill tool faster and the served cells inside their spread, is what this needed. Ready to land. |
43905bd to
af4af0a
Compare
The linear attention's prompt forward wrote the conv's channels to one [rows, channels] buffer, then ran tf_copy_cols three times to pull q, k and v apart before the q and k norms. tf_conv_prefill now takes an optional split: with key_width, channel c goes to q, k or v at its own contiguous row, and the three copies are gone. Each output keeps the same sum, so the bytes are unchanged. Flash Next keeps the single output.
af4af0a to
e5104eb
Compare
|
Thank you @AbrahamCete. 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. |
|
Thanks @AbrahamCete! This is in TensorFold 1.2.3, out now: https://github.com/ashhart/TensorFold/releases/tag/v1.2.3 |
What this changes
In the prompt forward, Qwen 3.5's linear attention wrote the conv's output (
tf_conv_prefill) to one fp32 buffer of rows by channels. ThensplitQkvrantf_copy_colsthree times, for each layer and span of rows, to pull q, k and v apart before the q and k norms. In a 2048-token prompt pass that is 144 of the 27B's 160tf_copy_colslaunches, and 90 of the 35B-A3B's 100.This PR gives
tf_conv_prefillan optional split (ConvSplit):key_widthset, each thread picks its channel's output once: q, k or v, each with its own contiguous rows. The sums and their order are unchanged, so every value has the same bits; only where it is stored changes.splitQkvis nownormQk, the two norms alone.tf_copy_colslaunches left are the full-attention layers' split of q from its gate. This PR leaves them alone.The new test
kernel_tests/conv_split.zigruns 37 rows and 364 channels with a key width of 96, so a split falls inside the first 256-channel block and the values end inside the second. The split outputs hold the bytes of the single output's columns, and the new conv state is the same.Receipt
Environment: Ryzen AI Max+ 395 (gfx1151), Ubuntu 26.04, Zig 0.17.0, hipcc with HIP 7.1.52801 and Ubuntu clang 21.1.8 (rocprofv3 from ROCm 7.13). Checkpoints: Qwen3.8-27B-MLX-4bit and Qwen3.6-35B-A3B-MLX-4bit-MTP. Base: main 45876f5. Both sides were built from
git archivetrees.Kernel time, rocprofv3 over a 2048-token
tf-qwen35-test prefillrun, per prefill:tf_copy_colslaunches instead of 160.tf-qwen35-test prefill, one prefill after a warm-up, alternated B C B C B C, seconds:Served, one fresh server a run, alternated B1 C1 B2 C2:
tools/bench_cache.py --require-cold --tokens 16,--context 34816 --parallel 1 --prompt-cache-gib 0,ttft_s:Every cold request's
token_shais the same on both sides, with 0 cached tokens. On the 27B the copies were 0.7% of the pass, and these runs don't resolve it: their spread is about as large.tools/bench_concurrent.py --levels 1,4 --tokens 256 --reps 3 --temperatures 0 --alone --serial,--parallel 4: token hashes are equal on every server (35B code9f2923ac14d0, chata8c28b8297b4; 27B code2b28aa2108de, chata06fab348fbe), 0 failed. Decode is unchanged: code at 4 streams 231.5 / 230.6 on main and 231.2 / 231.2 here on the 35B; 44.0 / 43.9 and 43.8 / 44.0 on the 27B.Exactness:
tf-qwen35-test logits, 2048 tokens) are byte-identical to main's on both checkpoints, bf16 and--f32(27Bdcc85692582d/232dd4cf1fcd, 35B18bee11563f1/84fbaeb871d7).tf-qwen35-test check --only invariants: 27B 42 passed, 0 failed, 5 skipped; 35B-A3B 46 passed, 0 failed, 1 skipped, the same on both trees.Tests run:
zig build test -Dhip=true --summary all: 570/570 steps, 7189/7251 tests passed, 62 skipped.zig build hip-kernel-test --summary all: 132/136 passed, 4 skipped, 0 failed. The new test is not among the skips: before the change it didn't compile, and a planted offset in the split path fails it alone.SUMMARY gfx1151 93 kernels: 93 pass gates 1-4, 0 fail, 2 known findings; 11 controls: 11 red as planted, 0 missed; 147 limit problems, the same as main.tools/zig/lean_check.py: 425 problems, the same as main.zig fmt --checkis clean.Not run, and why: