Repository navigation
Conversation
The FA2 head_dim > 192 gate uses an exact compute-capability allowlist. NVIDIA#2836 removed it, but NVIDIA#2629 brought it back while adding padded Q/V head-dim handling, so sm103 (B300/GB300) again falls back to fused or unfused attention for padded head dims in (192, 256]. Add (10, 3) to the allowlist instead of dropping the list. flash-attn's hdim256 backward picks its kernel by opt-in shared memory per block, and below 144 KB (sm86/sm89) it launches nothing when dropout is enabled. sm103 has the same 227 KB as sm90/sm100, so it takes the full kernel. Add a backend-selection test for sm103 head dims around the 192/256 bounds, including the MLA case where head_dim_v sets the padded size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
This was referenced Oct 20, 2026
0z5a
marked this pull request as ready for review
October 20, 2026 14:45
Contributor
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryAllows FlashAttention 2 on sm103 when the padded head size is greater than 192 and at most 256.
No actionable issues were found. This review checked code paths, not GPU execution; tests were not run. Reviews (1) · Last reviewed commit: "[PyTorch] Allow FlashAttention 2 head_di..." · Reviewed by Greptile |
This branch has not been deployed
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.
Description
get_attention_backenddisables FlashAttention 2 for padded head dims in (192, 256] unless the device is in an exact allowlist,((8, 0), (9, 0), (10, 0), (12, 0)). sm103 (B300 / GB300) is not in it. So on sm103, every config withmax(head_dim_qk, head_dim_v)in (192, 256] falls back to FusedAttention or UnfusedDotProductAttention, even when flash-attn is installed and requested. Examples are head_dim 256, or MLA with head_dim_v 256.This is a regression:
#3360 reported the same problem on B300 and was closed by its author. As discussed there, this PR is the narrower fix: it adds only
(10, 3)and leaves sm86/sm89 out.The fallback also defeats an existing preference. For THD with dropout on
(10, 0)and(10, 3),is_slow_fused_thd_dropoutdisables FusedAttention so that FA2 is used. On sm103 with head_dim > 192, FA2 was already disabled by the allowlist, so the preference never applies.Why a list entry rather than dropping the clause: flash-attn's hdim256 backward picks its kernel by opt-in shared memory per block. Below 144 KB (sm86/sm89/sm120 have 99 KB) it launches no kernel at all when dropout is enabled (Dao-AILab/flash-attention#3053). sm103 has 227 KB, the same as sm90 and sm100, so it takes the same backward kernel as sm100. The existing
(12, 0)entry has that problem with dropout. It is tracked in #3711 and fixed separately.Type of change
Changes
(10, 3)to the FA2 head_dim > 192 allowlist. Update the debug message from "sm80/90/100+" (which wrongly suggested every sm100+ device) to "sm80/90/100/103/120".test_fa2_large_head_dim_backend_selectiontotests/pytorch/attention/test_attention_backend_selection.py. It mocks the compute capability and the flash-attn version, like the FA4 cases in that file. It covers:Testing
utils.py:sm103-d256,sm103-d224andsm103-mla-padded-d256fail; the other 4 pass.test_attention_backend_selection.py: 35 passed, 2 skipped (the existing SM12x-GPU tests).9d9bd9e5with this branch's Python sources on top. The attention selector and its tests are unchanged between9d9bd9e5and this branch's basea7b6c0cb.black24.4.2 with the repository's pre-commit arguments reports no changes.Checklist:
🤖 Generated with Claude Code