-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
Sdpa dino v2 #33403
Sdpa dino v2 #33403
Conversation
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.
Thanks for adding!
Before merge we'll need to run the slow model tests. Could you push an empty commit with the message [run-slow] dinov2
?
The currently failing tests will also need to be resolved
@amyeroberts how should i resolve the failing tests? |
@avishaiElmakies You'll need to look at the CI logs and debug to figure out the problem based on the error message. First step is to make sure you can replicate the errors locally. You can also inspect other PRs which added SDPA e.g. #30555 to see if there's a common pattern of fixes which need to be applied |
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. |
@amyeroberts thanks for the reply from what i understand, those are the tests that are failing:
from what I understand, those are related to the fact that sdpa doesn't return output_attentions. so i would love to know how to handle those. if output_attentions == True should i send them to eager?
Those are very weird to me. I am able to replicate them, but something is weird. It seems someone changed the |
@amyeroberts |
For the first four tests - refer to the linked PR and the adaptations to the tests made there. You'll see that "eager" is indeed selected. The diffs will show how this should be done. For the other tests -- re the comment "It seems someone changed the Dinov2Embeddings class, and it is different from the main branch.". The version of DinoV2 on this branch will depend on which commit from main you branch off from. You can see all the changes to the dino v2 model here: https://github.com/huggingface/transformers/commits/ce62a41880b5b70a304d068eb58f55894a5a7af8/src/transformers/models/dinov2/modeling_dinov2.py. Any PR should be in sync and up-to-date with the main branch. To make sure this is the case, you'll need to do frequent merges from main into this branch or rebases of this branch onto main. If the branches are up-to-date and there still remains a differences between tests passing on |
@amyeroberts fixed the 7 tests (at least on my machine). |
@avishaiElmakies Thanks for running the tests and adding this feature! Can confirm |
@avishaiElmakies Thanks for you good contribution, this new features help us a lot! BTW, could you share an example or update doc on how to use this new features? |
@amyeroberts great to hear, thanks for the guidance! @lezhang7 I don't understand, this is sdpa in dinov2 |
Thank you! @NielsRogge , I use following for loading the model:
However, I didn't find accelerated inference speed compared to original code without explicitly flag spda, is there anything wrong with my code? |
I believe that after adding sdpa implementation, the default implementation is sdpa(at least for dinov2). So you don't need to use the flag to get sdpa implementation. You should compare attn_implementation="eager" vs attn_implementation="sdpa" |
* add sdpa to dinov2 * fixup * add dinov2 to sdpa doc * update doc order * [run-slow] dinov2 * common to eager * [run-slow] dinov2 * update attn implementation in common * update test_modeling_dinov2 to have mask_ration, num_masks and mask_length similar to vit * [run-slow] dinov2 --------- Co-authored-by: Avishai Elmakies <avishai.elma@cs.huji.ac.il>
adds SDPA to dinov2
copy from VIT
address #28005
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@amyeroberts @fxmarty
notes
output_attentions=True
. but sdpa doesn't support it. when i added to OPT, ifoutput_attentions==True
then you send to eager mode. but ViT didn't have it. so i didn't add it here. can add if needed