Support head dim 256#329
Open
woct0rdho wants to merge 4 commits into
Open
Conversation
f6c9c5c to
c049753
Compare
This was referenced Jun 11, 2026
…= 128 and pv_accum_dtype == fp16+fp32 and non-causal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Head dim 256 is needed for models like AuraFlow and Ideogram 4. This PR adds it in the CUDA kernels. Later we can also add it in the Triton kernels if needed.
I've tested on RTX 3080 (sm86) and RTX 4090 (sm89). When seq len is large, they reach the ideal 2x speedup compared to FlashAttention.
As always,
pv_accum_dtype="fp16+fp32"(or"fp32+fp16"in some interfaces) is faster thanpv_accum_dtype="fp32", andpv_accum_dtype="fp16"is even faster, but more likely to cause black/noise/degraded output. Maybe the time has come that we have to tune it for each model.Currently sm90 is not supported due to constraint of WGMMA size. If you have sm90, you can help make it work.
Implementation details
When
head_dim == 256, intranspose_pad_permute_cuda, we reduceCTA_SIZEon device to 32 so the assertCTA_SIZE * HEAD_DIM <= 8192(1024 threads per block) is satisfied. In all attn kernels, we reduceWARP_Qto 16 because of register pressure.By the way, I've applied a patch although it's not related to head dim 256: In sm80 attn kernels, when
head_dim == 128andpv_accum_dtype == "fp16+fp32"and non-causal, we should set(CTA_Q, CTQ_K, WARP_Q, WARP_K)to(128, 32, 32, 32), because of how the inst buf works. This gives 2x or even 3x speedup and actually makespv_accum_dtype="fp16+fp32"usable. I found it when benchmarking all configs with common ComfyUI workloads on sm86. In summary, the benchmarked workloads are:And the heuristic configs
(CTA_Q, CTQ_K, WARP_Q, WARP_K)on sm86 are:Maybe there are similar cases in the seven sm89 attn kernels but I haven't looked.