Skip to content

cuda: wider FWHT blocks at decode/verify sizes, bit-identical: +2.6-4.9% 9B, +4% 27B MTP on H200 - #396

Merged
bri-prism merged 1 commit into
prismfrom
cuda/fwht-wide-blocks
Oct 25, 2026
Merged

bri-prism merged 1 commit into
prismfrom
cuda/fwht-wide-blocks

Conversation

@bri-prism

@bri-prism bri-prism commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

What

fwht_cuda_block (plain/signed transform, n ≥ 512) and fwht_quantize_q8_1 (transform + q8_1, the PTQ1_0 path of #377) launch one 256-thread block per transform.

During decode and speculative verify only 1–64 transforms are in flight. On the 9B, for example, the o_proj and ffn_down inputs give 4–8 blocks of 4096 elements on a 132-SM H200. Those few small blocks are bound by the 12 butterfly stages' latency, not by bandwidth.

With 64 or fewer transforms, this PR uses min(n/2, 1024) threads per block, so every thread still holds at least two elements:

  • 1024 threads for the 9B's 4096-wide transforms;
  • 512 threads for the 27B's 1024-wide blocks.

Above 64 transforms (prefill) nothing changes.

Bit-identical: ggml_cuda_fwht_block_butterfly<N, NT> runs its stages in ascending stride order for any NT.

Override: GGML_CUDA_FWHT_NT=512|1024 overrides the wide value; 256 restores the old behaviour.

Results (H200, prism 97ea5ae, job 31313, tokens identical in every cell)

model / mode prism this PR GGML_CUDA_FWHT_NT=256
9B PQ2_0, no spec 315.7–315.9 +2.6 to +2.9% −0.3 to +0.1%
9B MTP3 369–598 +2.5 to +3.0% −0.9 to +0.4%
9B DFlash7 269–663 +4.3 to +4.9% −0.7 to 0%
27B PTQ1_0, no spec 141.8–142.4 +0.0 to +0.4%
27B MTP2 204.7–283.1 +4.0 to +4.4%

The block-width sweep (jobs 31218 and 31254, on top of #391/#395) picked the rule:

  • 9B: 1024 threads beat 512 under speculation.
  • 27B: 512 threads beat 1024 for its 1024-wide blocks (MTP2 +3.7 to +4.3% vs +3.0 to +3.7%).

Tests

Test Result
MUL_MAT_HADAMARD 34/34
ROT_MATVEC 20/20 (fused FWHT + q8_1, PQ2_0 / PTQ1_0)
MUL_MAT 1666/1666

On the #391/#395 stack, ADD_RMS_NORM_HADAMARD (22/22) also passes at NT 256, 512 and 1024.

Independent of #391 and #395. It applies on top of them without conflicts and adds to their gains.

…code / verify sizes

fwht_cuda_block and fwht_quantize_q8_1 run one 256-thread block per transform. At decode
and speculative verify there are only 1-64 transforms in flight, so a handful of small
blocks leaves most of the GPU idle and the kernel is bound by its stage latency. With 64
or fewer transforms, use min(n/2, 1024) threads (at least two elements per thread). The
butterfly runs its stages in the same order for any block width, so results are
bit-identical. GGML_CUDA_FWHT_NT overrides the wide value (256 disables it).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01PRQc3TQpn72qBxrUn5vKqo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant