Skip to content

feat(attention): head-dim-tiled Triton flash attention for ViT (gfx1151)#4065

Open
carlushuang wants to merge 2 commits into
mainfrom
carhuang/gfx1151_vit_flash_attn
Open

feat(attention): head-dim-tiled Triton flash attention for ViT (gfx1151)#4065
carlushuang wants to merge 2 commits into
mainfrom
carhuang/gfx1151_vit_flash_attn

Conversation

@carlushuang

@carlushuang carlushuang commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

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 whose head_dim is 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).

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.
@carlushuang carlushuang requested a review from a team July 2, 2026 15:15
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 4065 --add-label <label>

@brunomazzottiamd

Copy link
Copy Markdown
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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants