Skip to content

[BetterTransformer] Add MobileBERT support for BetterTransformer#506

Closed
raghavanone wants to merge 10 commits into
huggingface:mainfrom
raghavanone:add_mobilebert_layer
Closed

[BetterTransformer] Add MobileBERT support for BetterTransformer#506
raghavanone wants to merge 10 commits into
huggingface:mainfrom
raghavanone:add_mobilebert_layer

Conversation

@raghavanone

Copy link
Copy Markdown

What does this PR do?

Adds mobilebertlayer

@younesbelkada younesbelkada left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks a lot for your great work @raghavanone and for start adding BetterTransformer support for MobileBert!
I left few comments, several points needs to be addressed before merging. Starting from the naming of the new class. We prefer to call the new class as xxxLayerBetterTransformer to be able to correctly trace whether the conversion has been successfull or not.
Also could you make sure this implementation is tested by adding hf-internal-testing/tiny-random-MobileBertModel here
Let us know if you face into any issue here!

Comment thread optimum/bettertransformer/models/__init__.py Outdated
Comment thread optimum/bettertransformer/models/__init__.py Outdated
Comment thread optimum/bettertransformer/models/encoder_models.py Outdated
Comment thread optimum/bettertransformer/models/__init__.py
@younesbelkada younesbelkada changed the title Add mobilebertlayer [BetterTransformer] Add MobileBERT support for BetterTransformer Nov 23, 2022
@younesbelkada

Copy link
Copy Markdown
Contributor

hey @raghavanone !
do you need any help converting the model? It seems that you did forget to add hf-internal-testing/tiny-random-MobileBertModel in the testing suite?

@raghavanone

Copy link
Copy Markdown
Author

hey @raghavanone ! do you need any help converting the model? It seems that you did forget to add hf-internal-testing/tiny-random-MobileBertModel in the testing suite?

Done


self.validate_bettertransformer()

def forward(self, hidden_states, attention_mask, *_):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is the purpose of *_ in the end of the arguments?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I was not sure, I saw *_ in every other forward call definition.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Alright, maybe we should also add **__ or something to handle potential keyword arguments?
@younesbelkada

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I saw both some forward def having both *_ and **_ . We should possibly add more information about it in the guide published.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes basically it is to "handle" potential arguments that were passed to the original forward function, by allowing this forward function to get them, but ignoring them right after.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

great remark, the guide will be updated ;)

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint.

@younesbelkada

younesbelkada commented Nov 24, 2022

Copy link
Copy Markdown
Contributor

The test is failing for few reasons, firstly MobileBERT uses a special mechanism called bottleneck_attention and botteneck, if these are enabled it seems that the conversion criteras are not met. Therefore I made a special model here: ybelkada/tiny-mobilebertmodel that you can replace on the testing suite and hopefully the test will pass!

also, it would be cool to add a sanity check on the __init__ of the MobileBertBetterTransformerLayer to check if these values are correctly set on the config file.

Comment thread optimum/bettertransformer/models/__init__.py
@raghavanone

Copy link
Copy Markdown
Author

@younesbelkada let me know what needs to be done to merge this .

@michaelbenayoun

Copy link
Copy Markdown
Member

There are conflicts, you need to fetch on the main branch and merge / rebase on this branch.

@github-actions

github-actions Bot commented Jul 8, 2025

Copy link
Copy Markdown

This PR has been marked as stale because it has been open for 90 days with no activity. This thread will be automatically closed in 30 days if no further activity occurs.

@github-actions github-actions Bot added the Stale label Jul 8, 2025
@github-actions github-actions Bot closed this Aug 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants