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

Add AIMv2 to Transformers #35550

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

AlanPonnachan
Copy link

What does this PR do?

Fixes #35351

This PR adds AIMv2 support in Transformers. AIMv2 showed better performance than SigLIP.

TODO

  • Completed almost every steps mentioned in this guide

Who can review?

@qubvel
@Rocketknight1

@AlanPonnachan
Copy link
Author

@qubvel @Rocketknight1 Could you help review this PR ? Let me know if you have any suggestions. Thank you in advance for your time and assistance.

Copy link
Member

@qubvel qubvel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @AlanPonnachan! Thanks for working on the model 🤗

Please see other model implementations in the repo to follow code style and patterns (e.g. how the attention module should be implemented).
It's better to reuse existing blocks rather than defining new ones. You can also utilize modular converter for inheritance.

Please see similar PRs:

Thanks!

docs/source/en/model_doc/aimv2.md Outdated Show resolved Hide resolved
src/transformers/models/aimv2/__init__.py Outdated Show resolved Hide resolved
@@ -0,0 +1,225 @@
# coding=utf-8
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please refactor it to follow mllama model conversion format. It should be a KEY_MAPPING dict instead of create_rename_keys

return image


@torch.no_grad()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need no_grad here? The one is used in the code below

)
query, key, value = qkv.unbind(0)

context_layer = F.scaled_dot_product_attention(query, key, value, attn_mask=mask)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see other models on how the attention module should be structured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Any plans to add AIMv2 in the model?
2 participants