Repository navigation
Conversation
Only the cuDNN backend implements score_mod. With cuDNN frontend 1.31.0 to 1.32.1 from PyPI, the frontend does not see the callback on sdpa(), so its Python SDPA engine can serve the graph as plain attention. The score modifier is dropped without an error, which gives wrong results. Exclude the Python SDPA engines from these graphs. Raise an error if a Python engine is still selected, so that a later frontend cannot silently drop the modifier again. Signed-off-by: Bruno Volpato <brunocvcunha@gmail.com>
This was referenced Nov 3, 2026
bvolpato
marked this pull request as ready for review
November 3, 2026 02:53
Contributor
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryKeeps PyTorch Flex Attention
Acknowledgment: Reviews (1) · Last reviewed commit: "[PyTorch] Keep Flex Attention score_mod ..." · Reviewed by Greptile |
This branch has not been deployed
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
Fix silently wrong results from Flex Attention
score_modwithnvidia-cudnn-frontend1.31.0 and newer.Only the cuDNN backend implements
score_mod. The frontend decides whether a graph has a score modifier by reading the record keyfn, which is the argument name ofsdpa_fp8(), whilesdpa()names itscore_mod. So the frontend does not see the modifier on these graphs. From 1.31.0, its Python enginesdpa_fwd_prefill_sm100also accepts 64-dimension heads, so it can serve a Transformer Engine graph as plain attention and drop the modifier without an error.NVIDIA/cudnn-frontend#1960 fixes the frontend, and the
v1.32.1tag contains that fix. Thenvidia-cudnn-frontend==1.32.1wheel on PyPI does not, so>=1.29.0still installs the affected code. This PR therefore protects Transformer Engine on all of these versions, without a version pin.Type of change
Changes
score_modgraphs, so that the cuDNN backend serves them.Before and after
test_dot_product_attention_score_modran on one NVIDIA B200 with each PyPI frontend release.softcapandpost_scale_biasgraphs. Output differs from the reference: up to 38.8% of elements are outside toleranceValueError: cudnn.sdpa: q: this plan was built for 4 heads of dim 64; got (2, 16, 4, 64)Validation
test_dot_product_attention_score_modis the regression test: it fails on the affected frontends without this change. The plan names on the run above confirm that backend engines (for exampleeng7_k24=2_...) do not match the excludedsdpa_fwdandsdpa_bwdnames.The L0 PyTorch commands ran against an untouched tree of
b0219803on B200, with CUDA 13.2, PyTorch 2.15.0+cu132, and frontend 1.32.1. No test failed only with this change. That run also included #3795 and #3797.JAX is not changed. It builds the same kind of graph, but in a JAX-only environment with frontend 1.32.1 the graph at this shape was served by the backend, with or without the exclusion. A JAX environment that also has PyTorch installed was not tested. A100, H100, and SM120 were not tested. #3693 rewrites this path, so this check needs to move if that PR lands first.
Checklist: