Repository navigation
Fix is_causal being ignored by the FLEX attention backend - #15188
Open
davrens101 wants to merge 1 commit into
Open
davrens101 wants to merge 1 commit into
davrens101 wants to merge 1 commit into
Conversation
Contributor
|
Hi @davrens101, thanks for the PR! It does not appear to link an issue it fixes. If this PR addresses an existing issue, please add a closing keyword (e.g. Please note that PRs without a linked issue are likely to be automatically closed 10 days after this notice. Once the PR links an issue (or gets the |
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.
Fixes #15195.
What was wrong
_native_flex_attentionselects the mask first and the causality second:When
attn_mask is Nonethe first branch matches, soblock_maskstaysNoneandis_causal=Trueis silently dropped. The backend then computes full (bidirectional) attention instead of causal attention; no error is raised becauseflex_attentionis called withoutis_causal. Every other backend honoursis_causal, and_check_attn_mask_or_causalexplicitly allowsattn_mask=None, is_causal=True.Reproduced on a CPU torch 2.15 run:
Fix
Build the causal block mask when no mask is passed, before falling back to the
BlockMask/tensor branches.attn_mask+is_causalis already rejected by the backend constraint, so the separateelif is_causalbranch became dead code and is removed.After the fix the same call matches SDPA to ~3e-7.
Tests
Added
TestFlexAttentionCausalintests/models/test_attention_dispatch.py: causal output vsF.scaled_dot_product_attention(..., is_causal=True)for fp32/bf16, and vs an explicit lower-triangular mask.python -m pytest tests/models/test_attention_dispatch.py -k Flex-> 3 passedpython -m ruff check/formaton both files -> cleanAI assistance was used for this change; I reviewed and ran the tests above.
Coordination status
The linked issue includes a fresh upstream CPU reproduction. Maintainer acknowledgment of scope is still pending; no acknowledgment or compiled/GPU verification is claimed.