Repository navigation
Skip FA4 for deterministic backward on SM12x - #3595
Merged
sudhakarsingh27 merged 3 commits intoOct 6, 2026
Merged
sudhakarsingh27 merged 3 commits into
sudhakarsingh27 merged 3 commits into
Conversation
Signed-off-by: jbernloehr <jbernloehr@nvidia.com>
Contributor
|
Signed-off-by: jbernloehr <jbernloehr@nvidia.com>
Signed-off-by: jbernloehr <jbernloehr@nvidia.com>
Member
|
/te-ci pytorch L0 L1 L3 |
sudhakarsingh27
approved these changes
Oct 2, 2026
sudhakarsingh27
left a comment
Member
There was a problem hiding this comment.
LGTM. Relevant tests passed in CI
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
Deterministic backward on SM12x can select FlashAttention 4 and fail with
AssertionError: deterministic backward not supported on SM 12.0. This also affects.eval()with autograd enabled, and a cached selection from another device can bypass the restriction. Exclude FA4 when the call may require deterministic backward, allowing the existing selector to choose an enabled compatible fallback or report no available backend.FA4 remains eligible for forward-only calls and nondeterministic backward. Training mode and dropout semantics are unchanged.
Fixes #3594.
Type of change
Changes
.train()/.eval().AttentionParams, so both the scalar and mixed-THD backend caches distinguish these execution contexts. Query compute capability for the input device.Validation
Verified on 2026-09-30 on one RTX 5090, SM120, driver 615.36, Python 3.12.3, PyTorch
2.14.0a0, CUDA 13.4, cuDNN 9.26.0, FA44.0.0b24, and TE2.21.0.dev0at699ed6ec9e9c600c3d0acd3a488c4ca6f339e5d9. The production diff at commit4b0ad76bacross all three Python modules was applied to the affected installation and restored afterward; original and patched file hashes were checked. No native rebuild was needed.Follow-up commit
7bb7230esimplifies the capability lookup to passattention_params.devicedirectly; the helper already handlesNone. Pre-commit, changed-module pylint and the nine supplemental CPU selector/cache cases pass for this cleanup. GPU revalidation of this latest commit on Spark (SM121) is pending.The verified reproducer in #3594 uses a single process with separate contiguous BF16 Q/K/V tensors shaped
(2, 128, 8, 128), BSHD layout, causal masking, dropout 0, seed 0, andout.float().square().mean().backward(). Controls usedNVTE_FLASH_ATTN=1,NVTE_FLASH_ATTN_V2=0,NVTE_FLASH_ATTN_V3=0,NVTE_FLASH_ATTN_V4=1,NVTE_FUSED_ATTN=0,NVTE_UNFUSED_ATTN=1, andNVTE_ALLOW_NONDETERMINISTIC_ALGO=0; backend selection was checked in debug logs. The eval-backward variant changes the module to.eval()while retaining autograd and backward.torch.compile(backend="eager")Training and eval output/dQ/dK/dV passed comparison with an independent float64 causal-attention reference at
atol=rtol=0.02. Maximum absolute errors were 0.01211518 / 0.01729168 / 0.01740309 / 0.02124534; repeated execution with identical inputs and upstream gradients was bitwise equal for all four tensors.The complete
test_attention_backend_selection.pymodule ran through pytest with-v --tb=shortagainst real installed PyTorch/TE. The selector and mixed-THD tests use capability/selector mocks; the two integration tests execute on the real SM120 GPU. The device-cache regression seeds an SM100/other-device selection on that single GPU, so this is not physical mixed-architecture validation. SM121 has selector coverage only.Pre-commit, license, Python 3.12 syntax, diff checks, and pylint on all three changed production modules passed. A supplemental CPU source harness passed all nine selector/cache cases. Full Python lint reports the existing
E1120at unchangedtransformer_engine/common/__init__.py:295.Coverage limits: the branch's newer base was not rebuilt as a complete GPU installation; the full L0 suites were not run. The pytest run reported 29 dependency deprecation/JIT warnings; the compile smoke check also reported Dynamo warnings from the existing NVTX helpers. Inductor and physical multi-GPU execution were not tested. A fallback can be slower than FA4.
Checklist: