Skip to content

[PyTorch][CP] Support D=256 THD metadata with FA4 b33 - #3540

Merged
sudhakarsingh27 merged 10 commits into
NVIDIA:mainfrom
sudhakarsingh27:sudhakars/compact-fa-metadata-no-load-balance
Oct 12, 2026
Merged

sudhakarsingh27 merged 10 commits into
NVIDIA:mainfrom
sudhakarsingh27:sudhakars/compact-fa-metadata-no-load-balance

Conversation

@sudhakarsingh27

@sudhakarsingh27 sudhakarsingh27 commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Summary

FlashAttention 4 b33 adds backward support for D=256 THD attention with per-sequence length metadata on SM100/SM110. This PR selects FA4 only when the installed version supports the requested direction: b31–b32 for forward, b33+ for forward and backward. Earlier versions fall back, and deterministic D=256 backward remains excluded.

Transformer Engine uses -1 for an unbounded attention window, while FA4 expects None. This PR translates that sentinel at the FA4 entry points without changing other negative window offsets.

The SM100+ L3 test lane uses FA4 b33 with CUTLASS DSL 4.8.0. It covers D=256 no-load-balance context parallelism and window handling, and runs the full backend-selection test module for FA4.

Validation

H100 FA3 and B200 FA4 b33 L3 tests passed. The expanded B200 CP run (NVTE_TEST_ESSENTIAL=0) recorded 1,389 passes, 54,489 skips, and no failures. Focused reruns passed the backend-selection module and D=128/D=256 no-load-balance cases. The final test-only skip/assertion edit passed Python 3.12 compilation and git diff --check; it has not had another GPU run.

@greptile-apps

greptile-apps Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no outstanding correctness, security, or repository-rule violations were identified.

Summary

This PR enables version-aware FA4 selection for SM100/SM110 D=256 THD attention and adapts Transformer Engine’s unbounded-window sentinel at FA4 entry points.

  • Requires FA4 b31+ for D=256 seqused_q/k forward and b33+ for backward.
  • Excludes deterministic D=256 FA4 backward where the kernel does not support it.
  • Updates the SM100+ L3 lane to FA4 b33 and CUTLASS DSL 4.8.0.
  • Adds backend-selection, sentinel-normalization, and D=256 context-parallel coverage.
  • The two previous review findings were resolved by adding focused D=256 no-load-balance coverage and running the complete backend-selection module in the FA4 lane.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Attention request] --> B{FA4 otherwise eligible?}
    B -- No --> F[Try another backend]
    B -- Yes --> C{SM100/SM110 D=256 with seqused metadata?}
    C -- No --> G[Use FA4]
    C -- Yes --> D{Forward or backward?}
    D -- Forward --> E{FA4 >= b31?}
    D -- Backward --> H{FA4 >= b33 and non-deterministic?}
    E -- Yes --> G
    E -- No --> F
    H -- Yes --> G
    H -- No --> F
    G --> I[Translate window bound -1 to None]
    I --> J[Invoke FA4]
Loading

Reviews (16) · Last reviewed commit: "Keep full CP model catalogs for focused ..." · Reviewed by Greptile

@sudhakarsingh27
sudhakarsingh27 force-pushed the sudhakars/compact-fa-metadata-no-load-balance branch from 1b363bb to fd8b678 Compare September 17, 2026 21:24
@sudhakarsingh27

Copy link
Copy Markdown
Member Author

/te-ci pytorch L3

1 similar comment
@sudhakarsingh27

Copy link
Copy Markdown
Member Author

/te-ci pytorch L3

@sudhakarsingh27
sudhakarsingh27 force-pushed the sudhakars/compact-fa-metadata-no-load-balance branch from e2f2d2f to ee0265a Compare September 28, 2026 18:12
@sudhakarsingh27
sudhakarsingh27 force-pushed the sudhakars/compact-fa-metadata-no-load-balance branch from ee0265a to f4655fb Compare September 28, 2026 18:38
@sudhakarsingh27

Copy link
Copy Markdown
Member Author

/te-ci pytorch L3

@sudhakarsingh27 sudhakarsingh27 changed the title [PyTorch][CP] Support compact metadata with FA4 [PyTorch][CP] Support D=256 THD metadata with FA4 b33 Oct 1, 2026
FA4 b31 added seqused_q/k forward support for the SM100 D=256 kernel, while b33 added backward support. Select FA4 by the installed release and actual backward eligibility, retain the deterministic backward guard, and exercise the released b33 dependency stack in L3.

Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
Protect the release boundary with focused selector cases and extend the existing no-load-balance CP test to run D=256. This verifies the existing all-gather metadata path without adding strategy-specific production plumbing.

Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
@sudhakarsingh27
sudhakarsingh27 force-pushed the sudhakars/compact-fa-metadata-no-load-balance branch from 72241c0 to 1afbbc2 Compare October 6, 2026 23:08
FA4 b33 treats TE's -1 unbounded window sentinel as a literal offset, so
the D=256 coverage in this PR needs the adapter from NVIDIA#3532 at all four FA4
entry points. Bring that final adapter change into this branch instead of
leaving the new FA4 path dependent on another open PR.

Keep the regression tests in test_attention_backend_selection.py alongside
the focused FA4 tests. Cover both window argument forms and preserved
negative offsets, compare every batch and head with a float64 reference,
and run these cases under the FA4 b33 L3 lane.

Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
Keep the adapter comment focused on the sentinel contract and the FA4-only boundary. Name the numerical test for its independent reference and remove the redundant all-zero assertion, which singled out one symptom already caught by the full-output comparison.

Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
The standalone D=128 BSHD comparison does not exercise the D=256 THD path added by this PR. Keep the direct window-sentinel regression in L3; existing attention tests provide numerical comparisons.

Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
Comment thread qa/L3_pytorch_FA_versions_test/test.sh Resolved
The argument-only sentinel test cannot prove the adapted FA4 call produces correct attention; generic cross-backend comparisons may skip. Restore the independent reference check and keep only representative left, right, and non-sentinel cases for both window argument forms.

Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
@sudhakarsingh27

Copy link
Copy Markdown
Member Author

/te-ci pytorch L1 L3

Comment thread qa/L3_pytorch_FA_versions_test/test.sh Resolved
Comment thread qa/L3_pytorch_FA_versions_test/test.sh Resolved
CUTLASS DSL 4.8.0 recognizes SM107 while the previous pin does not, so keep the FA4 L3 dependency and installation guidance aligned. Running the small backend-selection module directly covers its eligibility and window-sentinel cases without a bespoke node list. Clarify that non-all-gather THD metadata depends on pad_between_seqs.

Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
A dedicated D=256 model preserves separate QK and V dimensions without a one-off runner override. Exclude it from the broad CP matrix because the no-load-balance test already exercises the intended path. The L3 causal cross-backend cases cover numerical behavior, so retain the sentinel unit test and remove the redundant standalone reference test.

Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
Query backend availability before deciding whether to skip the D=256 case. Supported FA4 b33 configurations should fail when FA4 is unexpectedly unavailable, while unsupported configurations still skip. Keep the general no-Flash skip separate from the D=256 assertion.

Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
The earlier D=256 broad-matrix exclusion kept cp_2_4 in the essential FlashAttention catalog solely for the focused no-load-balance case. That mixes model availability with test selection. Keep the full FlashAttention and FusedAttention catalogs available to the runner and focused tests, and narrow only the essential broad CP parametrizations. Non-essential broad runs continue to use the full catalog.

Signed-off-by: Sudhakar Singh <sudhakars@nvidia.com>
@sudhakarsingh27

Copy link
Copy Markdown
Member Author

/te-ci pytorch L1 L3

@sudhakarsingh27
sudhakarsingh27 merged commit 1c9f6f8 into NVIDIA:main Oct 12, 2026
22 of 31 checks passed
yueming-yuan added a commit to radixark/TransformerEngine that referenced this pull request Oct 31, 2026
… FA4 (#3)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants