-
Notifications
You must be signed in to change notification settings - Fork 69
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
[WIP] Patch for CLIP #21
base: main
Are you sure you want to change the base?
[WIP] Patch for CLIP #21
Conversation
Hi @FrancescoSaverioZuppichini! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
1 similar comment
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Hi thanks for trying this out. Yeah the native timm implementation for Attention is not very efficient. There are two things we need from attn:
The problem, as you've discovered, is that getting / setting those values from For 1, we have the Neither 1 or 2 are strict requirements, though, but of course they make the result more accurate. First, I would try what happens if you use |
Hi, I used this implementation partially fixed some issues and addressed performance problem that comes from an unnecessary permutation of tensor dimensions. I applied it to OpenCLIP models. Please find my implementation here. Any feedback is appreciated. |
is it faster? |
yes, it is especially if you run inference on CPU where there is not such much compute. |
Hi @AlexKoff88, sounds great! Do you know how the zero-shot accuracy of your implementation compares? E.g., on imagenet val. |
Hi, it depends on the number of tokens you merge from block to block. I found that the accuracy degrades significantly on COCO Captions if I want to achieve 2x speedup. My hope is that some lightweight fine-tuning can help here. Working on it. |
Hi 👋
Thanks for the amazing work on ToMe. I am trying to create a patch for CLIP. The main issue is that I cannot use PyTorch optimized attention implementation because I cannot edit the source code to weight the attention matrix with the log of the size. This results in slower forward pass.
This is the code I've used to benchmark the patch
Resulting in
Original CLIP
ToMe CLIP
Any idea how to use ToMe when nn.MultiHead or anything else (like stuff from
xformers
) is used?From my benchmarks it looks like somebody would be better off to just use the build in implementation in
torch
than to useToMe
Thanks a lot,
Fra