Skip to content
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

Merged
merged 5 commits into from
Dec 20, 2024
Merged

Cleaner attention interfaces #35342

merged 5 commits into from
Dec 20, 2024

Conversation

Cyrilvallez
Copy link
Member

What does this PR do?

Improve the attention interfaces with comments/dtype fix

@HuggingFaceDocBuilderDev

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.

Copy link
Collaborator

@ArthurZucker ArthurZucker left a 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

Comment on lines 51 to 56
# 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()
Copy link
Collaborator

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!

Copy link
Contributor

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

Copy link
Contributor

@vasqu vasqu left a 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).

Comment on lines 51 to 56
# 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()
Copy link
Contributor

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

@ArthurZucker
Copy link
Collaborator

LGTM

@Cyrilvallez Cyrilvallez merged commit 0d51d65 into main Dec 20, 2024
26 checks passed
@Cyrilvallez Cyrilvallez deleted the attention-interface branch December 20, 2024 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants