Repository navigation
[PyTorch] Backport #3540: translate TE's -1 window sentinel for FA4 - #3
Merged
Merged
Conversation
… FA4 FA4 treats -1 as a literal window offset, so TE's causal (-1, 0) became a local window: wrong attention at every head dim and an assert in the SM100 head_dim=256 backward.
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.
Backport of the FA4 window-sentinel adapter from NVIDIA#3540 (
backends.pyonly).Problem
check_set_window_sizeturns a causal mask intowindow_size=(-1, 0), and TE passes it to FA4 unchanged. FA4's_resolve_causal_local_windowtreats-1as a literal offset unless both sides are negative, so causal(-1, 0)becomeslocal=Truewith left offset -1:AssertionError: SM100 backward with head_dim=256 does not support local attentionin the SM100 hd256 backward, which blocks every Qwen3.5 (head_dim 256) training run on B200/GB300 with--attention-backend flashFix
Wrap the two FA4 entry points that 2.17 uses (
flash_attn_func,flash_attn_varlen_func) so that-1maps toNone. Other negative offsets are preserved. The adapter is copied unchanged from NVIDIA#3540; its other two wrapped entry points (_flash_attn_fwd/_bwd) are only used by the CP path, which doesn't use FA4 in 2.17.Not backported from NVIDIA#3540:
Validation (B200, flash-attn-4 4.0.0b35, patched TE overlaid on the miles image)
TE
DotProductAttention, thdpadding_causal,NVTE_FLASH_ATTN=1, max abs error against an fp32 reference:Full-param Qwen3.5-4B GRPO (miles, TP2, 4×B200): before, it crashed at the first backward; after, step 0 completes with loss -2.55e-5, grad_norm 0.583, train_rollout_logprob_abs_diff 0.0066.