Skip to content

Simplify GQA conditions in sdpa_attention.py#41699

Merged
vasqu merged 1 commit intohuggingface:mainfrom
justinchuby:patch-3
Oct 17, 2025
Merged

Simplify GQA conditions in sdpa_attention.py#41699
vasqu merged 1 commit intohuggingface:mainfrom
justinchuby:patch-3

Conversation

@justinchuby
Copy link
Copy Markdown
Contributor

Removed unnecessary checks for key being a torch.fx.Proxy in GQA conditions because fx tracing is no longer supported, and torch.export supports enable_gqa.

Removed unnecessary checks for key being a torch.fx.Proxy in GQA conditions because fx tracing is no longer supported, and torch.export supports enable_gqa.
Copy link
Copy Markdown
Contributor

@vasqu vasqu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thank you! Makes more sense esp since we removed fx support explicitly in #41683

@vasqu vasqu enabled auto-merge (squash) October 17, 2025 16:27
@@ -32,13 +32,11 @@ def use_gqa_in_sdpa(attention_mask: Optional[torch.Tensor], key: torch.Tensor) -
# 1.cuda or Ascend NPU
# - torch version >= 2.5
# - attention_mask is None (otherwise it will fall back to the math kernel)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it required that attention_mask is None? Just wanting to check it the situation has changed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, at least on older versions it is! Was only recently relaxed

Copy link
Copy Markdown
Contributor

@vasqu vasqu Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the description here https://docs.pytorch.org/docs/2.5/generated/torch.nn.functional.scaled_dot_product_attention.html (under gqa --> supports only flash and math --> flash only works without a mask)

We want to avoid the math kernel

@vasqu vasqu merged commit 347a0f9 into huggingface:main Oct 17, 2025
22 checks passed
@HuggingFaceDocBuilderDev
Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

ngazagna-qc pushed a commit to ngazagna-qc/transformers that referenced this pull request Oct 23, 2025
Removed unnecessary checks for key being a torch.fx.Proxy in GQA conditions because fx tracing is no longer supported, and torch.export supports enable_gqa.
SangbumChoi pushed a commit to SangbumChoi/transformers that referenced this pull request Jan 23, 2026
Removed unnecessary checks for key being a torch.fx.Proxy in GQA conditions because fx tracing is no longer supported, and torch.export supports enable_gqa.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants