-
Notifications
You must be signed in to change notification settings - Fork 27.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleaner attention interfaces #35342
Cleaner attention interfaces #35342
Conversation
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool thanks for updating, thanks @vasqu for the review
# SDPA with memory-efficient backend is bugged with non-contiguous inputs and custom attn_mask for some torch versions | ||
# Reference: https://github.com/pytorch/pytorch/issues/112577. | ||
if _needs_contiguous_inputs: | ||
query = query.contiguous() | ||
key = key.contiguous() | ||
value = value.contiguous() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could also just always apply contiguous!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, calling contiguous doesn't affect performance much either way so the comment clarification suffices imo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as a heads up, maybe it would be nice to doc what attn type supports what feature, e.g. sdpa and fa cannot output attn weights or use head mask while flex attn cannot use dropout.
Which brings me to the point to ask if these things have been considered (flex attn dropout not supported for example).
# SDPA with memory-efficient backend is bugged with non-contiguous inputs and custom attn_mask for some torch versions | ||
# Reference: https://github.com/pytorch/pytorch/issues/112577. | ||
if _needs_contiguous_inputs: | ||
query = query.contiguous() | ||
key = key.contiguous() | ||
value = value.contiguous() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, calling contiguous doesn't affect performance much either way so the comment clarification suffices imo
LGTM |
What does this PR do?
Improve the attention interfaces with comments/dtype fix