Repository navigation
head_dim 512 attention: use the kernel for masks made under inference mode - #14202
Merged
Merged
Conversation
…d of sending them to SDPA
Member
Author
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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
#13977 made the head_dim 512 attention router send every attention mask created under
torch.inference_mode()to SDPA. An inference tensor has no version counter, so the mask verdict cannot be cached across layers, and the change avoided rescanning it per layer. Butgenerate()and evaluation build their masks under inference mode, so every masked Gemma-4 prefill lost the kernel. SDPA then repeats the KV heads and keeps the dense mask: at[1, 8, 4096, 512]with 2 KV heads, about 128 to 160 MiB more temporary memory, and a reproducible OOM at 8192 tokens under an allocator cap where the kernel fits. The bool mask case was also about 10% slower.Inference masks now go through the same scan as any other mask. They are rescanned on every call, as
intervals_from_maskalready does for them, which costs one host sync per global attention layer. That only happens at prefill, because decode (one query token) never reaches the kernel. Masks made outside inference mode, compiled graphs and the failed self check path are unchanged.Tests
tests/test_large_head_attention.py(GPU):test_router_uses_the_kernel_for_masks_made_under_inference_mode: a causal mask made under inference mode now runs the kernel, with output equal to the maskless causal call. Fails on main (falls back to SDPA).test_router_skips_the_mask_scan_when_it_cannot_use_the_resultkeeps the failed self check case and drops the inference mask one.All 50 tests in the file pass.
Not covered here
generatetiming; the memory and OOM numbers above come from a kernel-level repro on B200.