Fix: support PEFT/LoRA with added tokens #1828
Merged
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.
PEFT supports adding tokens/embeddings: https://github.com/huggingface/peft/blob/main/examples/causal_language_modeling/peft_lora_clm_with_additional_tokens.ipynb
When loading a pretrained model, tokenizer, and PEFT including new tokens, the model fails because the model and adapter have a different number of embeddings:
In this case we want to run
self._model.resize_token_embeddings(len(self.tokenizer))
The core fix is:
The other change is moving initialization of
self.tokenizer
earlier in the script, so we have access to the tokenizer at this point in time.CoLab proof of concept:
https://colab.research.google.com/drive/12NaNeDHRCMVhyIHL4_Z6AZQq6q_E2cP8