Repository navigation
head_dim 512 attention: leave mask plus is_causal to SDPA, fall back on mask-scan OOM - #14691
Conversation
…ound strided offsets to int32, fall back on mask-scan OOM
|
@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". |
…_offset [skip ci]
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. 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". |
Two edge cases in the head_dim 512 attention router from #13869 (
unsloth/kernels/large_head_attention.py). The common paths (no mask, a causal / packed / padded mask without an explicitis_causal) take the same kernel route as before; the change adds one boolean check per call (about 0.04 us).1. Explicit
is_causal=Truenext to a masktransformers 4.57.6
sdpa_attention_forwardkeeps an explicitis_causalbeside the mask, and SDPA then applies both. The router built its intervals from the mask alone and dropped the causal part, so a call carrying a non-causal mask (all-allowed, or a 4D padding mask) plusis_causal=Truelet early tokens attend to later ones. transformers 5.x dropsis_causalwhenever a mask is present, so the two versions disagree on what that pairing means. The router now hands it to the wrapped function, which keeps each version's own meaning. No transformers model passesis_causalinto the attention interface, and Unsloth's own callers that passis_causal=Truedrop the mask first, so this only affects model code that passes both.2. OOM in the mask scan
intervals_from_maskallocates int32 row chunks (512 MiB at mask batch 8, length 16384) before the kernel's own OOM guard, so an OOM there escaped instead of falling back to SDPA. It now falls back like an OOM in the kernel.The strided-view int32 bound this PR first carried landed on main in #14790 (
_row_span, which bounds only the int32 row offset since batch and head offsets are int64); main's version is kept and the duplicate helper and tests were dropped in the merge.Tests (
tests/test_large_head_attention.py, both fail on main and pass here):test_router_leaves_an_explicit_is_causal_beside_a_mask_to_sdpatest_router_falls_back_to_sdpa_on_mask_scan_oomVerification (B200, torch 2.13, transformers 5.19):
is_causal=Trueprobe with the 4.57.6sdpa_attention_forwardsemantics (repeat_kv, then SDPA with both): main returns 6.81 for row 3 where SDPA gives 2.03 (it reads future tokens, max abs diff 10.19); this branch matches SDPA exactly (max abs diff 0.0).is_causal: one kernel call on both main and this branch, max diff 0 vs SDPA.