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
[BT] Add Bettertransformer
support for FSMT
#494
[BT] Add Bettertransformer
support for FSMT
#494
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 a lot for starting the PR!
First of all, I can see several "unneeded" files (.idea
, *.xml
files) would you mind removing them as they are not needed at all 🙏
Let me guide you here step by step:
Step 1: I have already identified for you the name of the layer that needs to be replaced. For FSMT the layer is called EncoderLayer
Step 2: In optimum/bettertransformer/models/encoder_models.py
add a new class, here you can call it FSMTEncoderLayerBetterTransformer
and follow the same template / logic as BertEncoderLayerBetterTransformer
for assigning the new keys to the old one. The challenge here is to find out which key corresponds to exactly which part of the TransformerEncoderLayer. This step is described here in the documentation
Step 3: Build the forward pass, again you can follow what is done in BERT and make sure to respect what is said here
Step 4: Import you new class, so here FSMTEncoderLayerBetterTransformer
inside optimum/bettertransformer/models/__init__.py
, and add a new line inside BETTER_TRANFORMER_LAYERS_MAPPING_DICT
, something that would look like: "EncoderLayer":FSMTEncoderLayerBetterTransformer
Step 5: You can check your conversion by doing something like:
from transformers import AutoModel
from optimum.bettertransformer import BetterTransformer
model = AutoModel.from_pretrained("hf-internal-testing/tiny-random-FSMTModel")
print(model)
And make sure your added layers are inside the model!
Let me know if there is anything unclear
Thankyou for the detailed breakdown @younesbelkada. I have followed and added all the things mentioned above.
Kindly review the recent commits @younesbelkada. Thankyou ❤️ |
Hi @Sumanth077 ! |
Thankyou @younesbelkada. Unfortunately Out of 14, 4 Test Cases got passed, 6 Test cases Failed and 4 got ignored. Including a screenshot for reference: I will go through that. Also your assistance would be really great |
Thanks! Could you please share with me the entire error trace? |
@younesbelkada Removed the .gitignorefile and also committed the remaining changes |
The documentation is not available anymore as the PR was closed or merged. |
I have merged #501 , could you merge your branch with the current main branch ? 🙏 Thanks! |
@younesbelkada I have done the suggested changes. Could you kindly confirm it. I can merge the branch if everything is fine. |
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 a lot for your efforts!
It seems that we still need to address few points before merging 💪 Keep it up! And let me know if you face into any issue
@younesbelkada Sorry for the confusion, I have modified the gitignore file and as well as re added the line in "test_better transformer". And regarding the conversion, getting few errors after running the above script. I will go through and try to resolve that |
Hi @Sumanth077 ! |
Hi @younesbelkada I have fixed the changes and the conversion is fine. Now I am not getting any errors while running the above script. Now only 4 test cases are failing, previously it was 6. |
Could you let me know which test is failing? and push your latest changes here? Thanks! |
Hi @younesbelkada could you kindly help me in resolving the above Failed Test Cases. One issue I guess is in the defining of Forward Pass. |
Thanks for your patience @Sumanth077 ! |
Bettertransformer
support for FSMT
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.
Looking great! Thanks a lot for your clean implementation of FSMT
integration for BetterTransformer
! 🎉
Leaving the last review for @fxmarty and/or @michaelbenayoun
@@ -70,7 +70,7 @@ def test_logits(self): | |||
torch.manual_seed(0) | |||
bt_hidden_states = converted_model(**inputs)[0] | |||
|
|||
if "gelu_new" in vars(random_config).values(): | |||
if "gelu_new" in list(random_config.to_dict().values()): |
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.
Great change, but no need to cast to list
here!
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! but I think the to_dict()
is necessary (otherwise I get a VERY weird error from transformers
)
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.
Yes exactly, but accessing the value is enough here
Thankyou so much @younesbelkada. I couldn't have done it, without your Support. Really appreciate it❤️ Looking forward to contribute to more projects 🚀 |
Thanks a lot for your contribution @Sumanth077 ! |
Hi @younesbelkada I have mistakenly called git pull origin local branch, now instead of one change I done in doc file. It is asking me commit all these files again. Could you help me with this. |
It is fine, I have just pushed it to the doc ;) Thanks again! |
What does this PR do?
Fixes # (issue)
Before submitting