Skip to content

Add AIMv2 to Transformers#35550

Open
AlanPonnachan wants to merge 4 commits intohuggingface:mainfrom
AlanPonnachan:add_aimv2_b2
Open

Add AIMv2 to Transformers#35550
AlanPonnachan wants to merge 4 commits intohuggingface:mainfrom
AlanPonnachan:add_aimv2_b2

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
Contributor

@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!

@@ -0,0 +1,225 @@
# coding=utf-8
Copy link
Contributor

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
Contributor

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
Contributor

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.

@yaswanth19
Copy link
Contributor

@AlanPonnachan Are you still working on this and if you don't have the bandwidth then I can take it from here and refine the code.

@AlanPonnachan
Copy link
Author

@yaswanth19 you can try to do modular converter part. I am facing some issues on that part. Further I can help you

@yaswanth19 yaswanth19 mentioned this pull request Mar 10, 2025
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?

3 participants