Add SDPA fallback for sliding-window attention#161
Open
fayerman-source wants to merge 1 commit intokarpathy:masterfrom
Open
Add SDPA fallback for sliding-window attention#161fayerman-source wants to merge 1 commit intokarpathy:masterfrom
fayerman-source wants to merge 1 commit intokarpathy:masterfrom
Conversation
Owner
|
i don't think i'll merge this (too bloating), but i will leave the PR up. |
svlandeg
reviewed
Mar 11, 2026
| from kernels import get_kernel | ||
| cap = torch.cuda.get_device_capability() | ||
| # varunneal's FA3 is Hopper only, use kernels-community on non-Hopper GPUs | ||
| repo = "varunneal/flash-attention-3" if cap == (9, 0) else "kernels-community/flash-attn3" |
Collaborator
There was a problem hiding this comment.
For Ada/Ampere, it's still nice to use "kernels-community/flash-attn3". I had some improvements using it on an A100.
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.
Summary
is_causal=Truewhen no explicit sliding-window mask is neededWhy
The current non-Hopper path still routes through FA3, which fails on RTX 5070-class hardware. This keeps the Hopper path unchanged, but makes the same model runnable on non-Hopper GPUs and avoids repeated
T x Tmask construction on the SDPA path.This was motivated by the non-Hopper discussion in #36 and the SDPA-focused follow-up in #108.
Benchmark note
RTX 5070, CUDA SDPA microbenchmark, batch 8, seq 2048, 4-layer test model:
I also smoke-tested a tiny GPU forward pass on the SDPA path after this change.