feat(attention): head-dim-tiled Triton flash attention for ViT (gfx1151)#4065
Open
carlushuang wants to merge 2 commits into
Open
feat(attention): head-dim-tiled Triton flash attention for ViT (gfx1151)#4065carlushuang wants to merge 2 commits into
carlushuang wants to merge 2 commits into
Conversation
Non-causal per-image varlen attention for Vision Transformer encoders whose head_dim is small and not a power of two (e.g. Qwen3.x ViT head_dim=72). Instead of padding head_dim to the next pow2 (128) like stock flash kernels, tile it into 5x16=80 lanes (WMMA k-tile 16) with masked loads for d >= head_dim, so the QK/AV contraction is only 80-deep (~1.6x fewer WMMA k-steps). Online softmax, one workgroup per (image, head, query-block). head_dim <= 80. Portable Triton; validated on gfx1151 (RDNA3.5) where torch SDPA falls back to the math backend.
Contributor
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
|
Contributor
|
#3858 is proposing kernel changes targeting vision-transformer head_dim (72) (and other small non-power-of-2 dims). Should we merge both PRs? |
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.
feat(attention): head-dim-tiled Triton flash attention for ViT
Adds
aiter/ops/triton/attention/vit_flash_attn.py— non-causal per-image varlen attention for ViT encoders whosehead_dimis small and not a power of two (e.g. Qwen3.x ViT: 72). Stock flash kernels pad head_dim to the next pow2 (128); this tiles it into 5×16=80 (WMMA k-tile 16) with masked loads for d ≥ head_dim, so the contraction is 80-deep (online softmax, one workgroup per image/head/query-block; head_dim ≤ 80). Portable Triton, validated on gfx1151 where torch SDPA falls back to the unfused math backend; consumed by ROCm/ATOM Qwen3.x VL (~21× over SDPA, relerr < 0.007).