Skip to content

[PyTorch] Fix unlimited attention window handling for FlashAttention 4 - #3570

Closed
yashaswikarnati wants to merge 1 commit into
NVIDIA:mainfrom
yashaswikarnati:codex/fa4-window-normalization
Closed

yashaswikarnati wants to merge 1 commit into
NVIDIA:mainfrom
yashaswikarnati:codex/fa4-window-normalization

Conversation

@yashaswikarnati

@yashaswikarnati yashaswikarnati commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Summary

FlashAttention 4 changed its window handling in 4.0.0b30: (-1, 0) is now treated as an effectively empty local window rather than an unlimited causal window. Transformer Engine still uses -1 as its unlimited-window sentinel.

FA4 version / TE behavior Value passed to FA4 Interpretation
FA4 < 4.0.0b30 (-1, 0) Unlimited causal attention
FA4 >= 4.0.0b30 without this PR (-1, 0) Effectively empty local window
FA4 >= 4.0.0b30 with this PR (None, 0) Unlimited causal attention

This PR converts TE's -1 sentinel to FA4's None convention in standard and context-parallel forward and backward paths.

Tests

  • Added a unit test for the sentinel conversion, including None and finite windows.
  • Added a BSHD/THD causal forward and backward comparison against PyTorch SDPA while forcing FA4.
  • AGA 905211 passed the helper unit test against the matching internal TE extension.
  • AGA 906233 passed head-256 causal BSHD and THD FA4 b32 forward/backward comparisons with PyTorch SDPA using the cherry-picked TE commit in a full NGC-base image.

Translate Transformer's -1 unlimited-window sentinel to FA4's None convention for direct and context-parallel calls. Cover the non-CP tuple argument and raw CP window kwargs with focused tests.

Signed-off-by: ykarnati <ykarnati@nvidia.com>
@github-actions github-actions Bot added the community-contribution PRs from external contributor outside the core maintainers, representing community-driven work. label Sep 28, 2026
@yashaswikarnati yashaswikarnati changed the title [PyTorch] Normalize FA4 unlimited attention windows [PyTorch] Fix unlimited attention window handling for FlashAttention 4 Sep 29, 2026
@yashaswikarnati
yashaswikarnati marked this pull request as ready for review September 29, 2026 19:09
@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] Fixes attention window handling for FlashAttention 4.

The PR appears safe to merge; no actionable defect was established.

Summary

The PR translates Transformer Engine’s unlimited-window sentinel to FA4’s None convention in standard and context-parallel attention.

  • Adds helper tests and a forced-FA4 causal forward/backward comparison against PyTorch SDPA.

Reviews (1) · Last reviewed commit: "[PyTorch] Normalize FA4 unlimited attent..."

@denera

denera commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

Closing because the fix was merged with #3540.

@denera denera closed this Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

attention community-contribution PRs from external contributor outside the core maintainers, representing community-driven work.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants