[PyTorch] Restore FlashAttention 2 head dim support on sm103 - #3360
Open
kalectory wants to merge 1 commit into
Open
[PyTorch] Restore FlashAttention 2 head dim support on sm103#3360kalectory wants to merge 1 commit into
kalectory wants to merge 1 commit into
Conversation
Signed-off-by: Neil Kale <263453039+kalectory@users.noreply.github.com>
Contributor
Greptile SummaryThis PR restores FlashAttention 2 eligibility for padded Q/V head dimensions up to 256 on sm103 by removing a stale architecture allowlist.
Confidence Score: 5/5The PR appears safe to merge with no concrete blocking or independently actionable non-blocking issues identified. The change narrowly removes an obsolete architecture filter while retaining FlashAttention 2’s padded head-dimension bounds, and the reviewed selection and dispatch paths reveal no established regression. Important Files Changed
Reviews (1): Last reviewed commit: "Restore FlashAttention 2 head dim suppor..." | Re-trigger Greptile |
Collaborator
|
/te-ci L0 |
cyanguwa
approved these changes
Aug 13, 2026
erictang000
added a commit
to NovaSky-AI/SkyRL
that referenced
this pull request
Aug 17, 2026
applying NVIDIA/TransformerEngine#3360 to TE 2.16 <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Changes attention backend selection at Megatron init via `exec` on TE internals; mitigated by SM guards, literal 2.16.0 source matching, and idempotent no-ops on unaffected GPUs, but wrong TE versions or arch-specific FA2 issues could still affect training memory or numerics. > > **Overview** > Backports **NVIDIA/TransformerEngine#3360** for the pinned **transformer-engine 2.16.0** so Megatron training can select **FlashAttention 2** for **head_dim 256** (e.g. Gemma 2/3) on GPUs outside TE’s SM allowlist (notably **sm103** B300/GB300, also sm86/sm89). > > A runtime patch **recompiles and rebinds** TE’s `get_attention_backend` to drop the erroneous `head_dim > 192` + compute-capability gate, keeping only FA2’s real limits (`<= 256`, `% 8 == 0`). It **no-ops** on sm80/90/100/120, when TE isn’t importable, or when TE source no longer matches 2.16.0, and clears TE’s memoized `_attention_backends` after apply. > > **Megatron only:** `patch_fa2_head_dim_allowlist()` runs in `make_megatron_module()` before `provide_distributed_model()` (policy and ref workers). A **verify script** and README document repro and numerics vs unfused attention. > > Remove this patch when the TE pin includes upstream #3360. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 1d9d8c9. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
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
Restore the FlashAttention 2 head-dimension behavior from #2836. #2629 preserved the new padded Q/V head-dimension handling but accidentally reintroduced the exact compute-capability allowlist that #2836 removed.
On B300 (sm103), that allowlist rejects a padded head dimension of 256 and falls back to quadratic unfused attention.
Type of change
Changes
Testing
Status quo
TP=4) and four to rollout inference. Qwen3.6-27B used BF16 THD attention, head dim 256, Transformer Engine 2.11.0, and FlashAttention 2.8.3.sm103) and silently selectedUnfusedDotProductAttentioninstead.torch.OutOfMemoryErrorduring forward.After the fix
forward_backwardtook 413.2s, the Adam optimizer step took 9.6s, and grad norm was finite at 1776.48. This validates FlashAttention 2 and 64k context on the four-B300 trainer configuration.Checklist: