FIX Correctly determine word embeddings on Deberta#2257
Merged
BenjaminBossan merged 1 commit intohuggingface:mainfrom Dec 4, 2024
Merged
FIX Correctly determine word embeddings on Deberta#2257BenjaminBossan merged 1 commit intohuggingface:mainfrom
BenjaminBossan merged 1 commit intohuggingface:mainfrom
Conversation
Description After a recent change in transformers (huggingface/transformers#22105), PEFT could no longer determine the word embeddings from Deberta. This PR provides a very minimal fix that correctly determines the word embeddings again. Details Previously, the word embeddings were determined in the following manner: 1. Find the transformers_backbone by checking the base model's children for PreTrainedModel instances 2. If not found, the model itself is considered the transformers backbone. 3. On the backbone, check for modules whose weight has the same size as the vocab size. This module is now assumed to be the word embeddings. Before the mentioned transformers PR, 1. did not find anything, so 2. was applied. After the PR, however, the DebertaEncoder is now an instance of PreTrainedModel (asked internally, this is intended). Therefore, the encoder is now considered the transformer backbone. But the encoder does not have the word embeddings attribute, therefore step 3. fails. The fix of this PR is to first explicitly check for model.embeddings.word_embeddings and if this attribute is found, use it as the word embeddings. Only when it's not found do we use the other method described above. This way, we can successfully determine the word embeddings on models like Deberta. This whole code is a bit messy and could probably be improved. However, changing the logic too much could inadvertently break for some existing models that are not included in the tests. Therefore, I chose this method which leaves the existing logic mostly intact.
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
githubnemo
approved these changes
Dec 4, 2024
Guy-Bilitski
pushed a commit
to Guy-Bilitski/peft
that referenced
this pull request
May 13, 2025
After a recent change in transformers (huggingface/transformers#22105), PEFT could no longer determine the word embeddings from Deberta. This PR provides a very minimal fix that correctly determines the word embeddings again. Details Previously, the word embeddings were determined in the following manner: 1. Find the transformers_backbone by checking the base model's children for PreTrainedModel instances 2. If not found, the model itself is considered the transformers backbone. 3. On the backbone, check for modules whose weight has the same size as the vocab size. This module is now assumed to be the word embeddings. Before the mentioned transformers PR, 1. did not find anything, so 2. was applied. After the PR, however, the DebertaEncoder is now an instance of PreTrainedModel (asked internally, this is intended). Therefore, the encoder is now considered the transformer backbone. But the encoder does not have the word embeddings attribute, therefore step 3. fails. The fix of this PR is to first explicitly check for model.embeddings.word_embeddings and if this attribute is found, use it as the word embeddings. Only when it's not found do we use the other method described above. This way, we can successfully determine the word embeddings on models like Deberta. This whole code is a bit messy and could probably be improved. However, changing the logic too much could inadvertently break for some existing models that are not included in the tests. Therefore, I chose this method which leaves the existing logic mostly intact.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
After a recent change in transformers, PEFT could no longer determine the word embeddings from Deberta. This PR provides a very minimal fix that correctly determines the word embeddings again.
Failing CI
To reproduce, run:
pytest tests/test_feature_extraction_models.py -k "prompt_tuning and deberta" -vDetails
Previously, the word embeddings were determined in the following manner:
transformers_backboneby checking the base model's children forPreTrainedModelinstances(code)
Before the mentioned transformers PR, 1. did not find anything, so 2. was applied. After the PR, however, the
DebertaEncoderis now an instance ofPreTrainedModel(asked internally, this is intended). Therefore, the encoder is now considered the transformer backbone. But the encoder does not have the word embeddings attribute, therefore step 3. fails.The fix of this PR is to first explicitly check for
model.embeddings.word_embeddingsand if this attribute is found, use it as the word embeddings. Only when it's not found do we use the other method described above. This way, we can successfully determine the word embeddings on models like Deberta.This whole code is a bit messy and could probably be improved. However, changing the logic too much could inadvertently break for some existing model architectures that are not included in the tests. Therefore, I chose this method which leaves the existing logic mostly intact.
For reviewers: Note that the previous logic has not been changed, just moved into an
ifblock. The actual diff is thus much smaller than it appears at first glance.