← Back to Pull requests

[PyT] Check FA3 backward compatibility during backend selection #3490

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Sep 07, 2026 04:05 UTC
Author

Description

Related to #3481.

Check FA3 backward compatibility when selecting the attention backend for training:

  • Value head dimensions above 256 require a fallback. Existing forward eligibility checks already bound the QK dimension to 256.

  • Unequal QK/V dimensions also require the loaded FA3 backward implementation to accept their shapes. Older implementations fall back; supported newer implementations retain FA3.
  • Unequal-dimension backward support was added in flash-attention#1604. Builds before and after that change can both report package version 3.0.0b1 and expose the same Python signature. The original unconditional unequal-dimension restriction was too broad for newer builds, while checking only V > 256 re-enabled the original backward crash on older builds.

    Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Changes

  • Register the active FA3 backward callable after a successful import.

  • For otherwise eligible unequal-dimension training, call that implementation with empty dense sequences. The native shape checks execute before the empty-work fast path; no attention kernels run. Cache the result by callable, device, dtype, and dimension pair without retaining tensors. A rejected shape or incompatible API selects another eligible backend.

  • Preserve the V > 256 training restriction and forward-supported inference configurations. Equal-dimension configurations do not need this compatibility probe.

  • Document the compatibility behavior and why the package version is insufficient.

  • Test selector behavior, real outputs and Q/K/V gradients, and cold-cache capability queries in eager execution, torch.compile, and CUDA Graph capture.
  • Validation

    Validated on 2026-10-09 using 8 H200 GPUs (SM90), distributing cases among independent GPU workers. Both real FA3 installations report package version 3.0.0b1.

    | FA3 implementation / variant | Passed | Expected backward failures |
    | --- | ---: | ---: |
    | v2.8.3/hopper, compatibility check enabled | 91 | 0 |
    | 75f90d60f348af768625b6ab6ce13e800c5bc48a (parent of #1604), compatibility check enabled | 91 | 0 |
    | Same legacy build, remove only the compatibility check | 12 | 12 |

    All 206 cases ran with no skips, collection errors, or unexpected outcomes. Each fixed variant includes:

  • 24 selector cases plus one unavailable-backward case.

  • 18 capability-query cases: FP16/BF16, QK/V dimensions 192/128, 64/128, and 64/256, with eager execution, cold-cache torch.compile(..., backend="eager", fullgraph=True), and cold-cache CUDA Graph capture. These also check unchanged RNG state and cache reuse.

  • 48 numerical cases: FP16/BF16, bshd/sbhd, training/inference, dimensions 192/128, 64/128, 64/256, 64/264, 64/512, and 128/128. Outputs and Q/K/V gradients are compared with an independent FP32 attention reference using unchanged tolerances, then the selected backend is asserted. FA3 and UnfusedAttention are enabled for this comparison.
  • Expected support is established independently through the public FA3 autograd interface with nonempty tensors. It is not inferred from the new empty-sequence probe. The legacy control reproduces native out must have shape errors in all 12 unequal-dimension training cases; the corresponding 12 inference cases pass.

    A separate probe profile on the modern build recorded zero CUDA kernels, unchanged allocated CUDA storage, and unchanged RNG state. The compatibility check targets the native backward shape contract; this validation does not cover every custom FA3 build configuration.

    Environment and source identity:

  • Python 3.12; PyTorch 2.9.1+cu128; CUDA 12.8 / nvcc 12.8.61; cuDNN 9.12.0.46; NCCL 2.27.5; driver 595.58.03.

  • Reused the previously validated runtime without changing it. This retains the previously approved cuDNN 9.12 replacement for the PyTorch wheel's cuDNN 9.10.2.21 pin.

  • Reused identical validated TE common/PyTorch native extensions because this revision changes only Python and documentation. Checked the staged Git tree, Python source hashes, import paths, loaded libraries, and native-library hashes for each variant.

  • Built the legacy FA3 source against its pinned CUTLASS revision 62750a2b75c802660e4894434dc55e839f322277 with the same CUDA/PyTorch runtime. Native and interface sources were unchanged; the offline setup adjustment only avoids re-downloading the pinned submodule. The legacy build retained the tested SM90 forward/backward paths while disabling optional SM80, FP8, paged-KV, append-KV, local, and softcap paths.
  • The focused tests can be run on an SM90 device with either FA3 implementation and the repository's attention-test dependencies:

    NVTE_FLASH_ATTN=1 NVTE_FLASH_ATTN_V3=1 python -m pytest -v \
      tests/pytorch/attention/test_attention.py::test_fa3_mismatched_head_dims_mode_selection \
      tests/pytorch/attention/test_attention.py::test_fa3_backward_unavailable \
      tests/pytorch/attention/test_attention.py::test_fa3_backward_capability_query \
      tests/pytorch/attention/test_attention.py::test_dpa_fa3_mla
    

    Changed-file pre-commit, L0_license, and the Python portion of L0_pytorch_lint passed. The full TE test suites were not run. These results cover numerical correctness, backend selection, and capability-query execution behavior; distributed communication and performance were not evaluated.

    Checklist

  • I have read the contributing guidelines.

  • The change and its regression tests are complete.

  • Backward limits and compatibility behavior are documented.

  • Focused numerical, gradient, and backend-selection tests pass with both FA3 implementations.

  • Changed-file pre-commit, license, and Python lint checks pass.

  • Full TE test suites have been run.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: yuweih205 Review duration: 48208m
    All Vouch review confidence checks passed
    Residual risk 0.35 = Change Risk (0.59) × (1 − Review Confidence (0.41)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.59 · 650 lines diff across 8 files
    0.59
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    40%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #3490"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 40.9% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 59% (MEDIUM) · Higher = larger blast radius
    59%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 40.9% · Lower = rushed or shallow review
    40.9%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 34.8% · Safe to merge
    34.8%