Repository navigation
Conversation
…rd on sm12x flash-attn's head_dim 256 backward picks its kernel by opt-in shared memory per block. Below 144 KB (sm86, sm89, sm120 and sm121 have 99 KB) it launches no kernel when dropout is enabled and returns without an error, so dq/dk/dv are never written. The check that used to reject this in flash-attn was removed in Dao-AILab/flash-attention@bbb21d6. TE's FA2 head_dim > 192 allowlist includes (12, 0), so training with dropout at a padded head dim in (192, 256] on sm120 selects FA2 and gets unwritten gradients. Disable FA2 in exactly that case: padded head dim > 192, attention dropout > 0, training, backward required, on a 99 KB GPU. Inference and dropout-free training keep FA2. Fixes NVIDIA#3711. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: 0z5a <dezhen.lu@student.uni-tuebingen.de>
0z5a
marked this pull request as ready for review
October 21, 2026 13:42
Contributor
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryThis PR prevents FA2 from running an unsafe dropout backward on sm120 when the padded head dimension exceeds 192.
Reviews (1) · Last reviewed commit: "[PyTorch] Keep FlashAttention 2 off for ..." · 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
Fixes #3711.
flash-attn's head_dim 256 backward (
run_mha_bwd_hdim256) picks its kernel by opt-in shared memory per block. Below 144 KB it launches no kernel at all when dropout is enabled, and returns without an error, sodq/dk/dvare never written. sm86, sm89, sm120 and sm121 all have 99 KB. Padded head dims 224 and 256 both use this kernel. The flash-attn side is Dao-AILab/flash-attention#3053; the check that used to reject this case was removed in Dao-AILab/flash-attention@bbb21d6.TE's FA2 head_dim > 192 allowlist includes
(12, 0). Training with dropout at a padded head dim in (192, 256] on sm120 therefore selects FA2 and gets unwritten gradients. With flash-attn 2.8.3, a backward withdq/dk/dvpre-filled with NaN leaves them 100% NaN:dropout_p=0.1;This PR disables FA2 in exactly that case:
attention_dropout > 0;(8, 6), (8, 9), (12, 0), (12, 1).Inference, dropout-free training and forward-only calls keep FA2. sm86/sm89/sm121 are already excluded by the allowlist for head_dim > 192. Listing them keeps the gate correct if that list is relaxed later.
Type of change
Changes
get_attention_backend: a separate check right after the existing FA2 head-dim check. It turns FA2 off for the case above and logs the reason at debug level.test_fa2_large_head_dim_dropout_backend_selectionintests/pytorch/attention/test_attention_backend_selection.py, which mocks the compute capability:Testing
utils.py: the three sm120 dropout cases fail; the 5 controls pass.test_attention_backend_selection.py: 36 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