Skip to content
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

Allow AdapterModels to have custom tokens #306

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mapmeld
Copy link

@mapmeld mapmeld commented Sep 14, 2024

PEFT has a feature for adapters to add tokens to a model: https://github.com/huggingface/peft/blob/main/examples/causal_language_modeling/peft_lora_clm_with_additional_tokens.ipynb

When using an AdapterModel with new tokens in LightEval, the script fails because:

  • AdapterModel._create_auto_tokenizer always uses the base model path, without checking config.tokenizer
  • the new tokenizer and base model will have a mismatched number of embeddings

Notebook with error: https://colab.research.google.com/drive/1AMJ6_MiZGFTBf8KdRn-zj7soKyZrzpbf?usp=sharing

This PR would create the tokenizer from config.tokenizer or config.base_model
and run base.resize_token_embeddings(...) before PeftModel.from_pretrained(base, adapter_weights)
This is based on my fix for llm-evaluation-harness: EleutherAI/lm-evaluation-harness#1828

Notes:

@clefourrier
Copy link
Member

Hi!
That works for me, but I would add a more detailed hlog message at the resize step: if you're adding tokens, we need to know how many, since they are likely to behave weirdly, and if you're removing tokens from the vocab, we would want to know which ones.
So a log like "You're using the adapter model's tokenizer, which has less/more tokens than its base: adding/removing X tokens" + in case of removing specifying which, would be useful.

You'll also need to run ruff to fix the style.

@clefourrier
Copy link
Member

Re your comment, adapter_weights and delta_weights should be skippable by default, what's the error message you're getting when not specifying them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants