add causal_upper_left mask option to scaled_dot_product_attention#3254
Open
mm65x wants to merge 2 commits intoml-explore:mainfrom
Open
add causal_upper_left mask option to scaled_dot_product_attention#3254mm65x wants to merge 2 commits intoml-explore:mainfrom
mm65x wants to merge 2 commits intoml-explore:mainfrom
Conversation
7693beb to
6b2d587
Compare
670373d to
a435cd1
Compare
Collaborator
|
Can you fix the lint error? |
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.
Proposed changes
#2835
adds
"causal_upper_left"and"causal_lower_right"as explicit mask optionsto
mx.fast.scaled_dot_product_attention."causal"stays as an alias for"causal_lower_right", so nothing breaks.when
S_Q != S_KV, lower-right aligns the last query with the last key,while upper-left aligns query
iwith keys0..i(matching PyTorch'sis_causal=True). whenS_Q == S_KVthey're identical.on Metal, the full-attention kernels already parameterize the causal diagonal
via
qL_offinAttnParams, so the change is just passing0instead ofkL - qLfor upper-left. the vector kernels previously hardcoded the offsetinline, so a
causal_offsetbuffer argument was added instead. on CUDA, thecuDNN path uses
set_causal_maskvsset_causal_mask_bottom_right, and thevector kernels use a
causal_offsetfield inAttnParams(same approach asMetal).
Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes