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

Add support for loading checkpoints with newly added tokens. #272

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions unsloth/models/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def from_pretrained(
fix_tokenizer = True,
trust_remote_code = False,
use_gradient_checkpointing = True,
new_token_num = 0,
*args, **kwargs,
):
old_model_name = model_name
Expand Down Expand Up @@ -144,6 +145,10 @@ def from_pretrained(
*args, **kwargs,
)

# Add support for newly added tokens.
model.config.vocab_size = model.config.vocab_size + new_token_num
model.resize_token_embeddings(model.config.vocab_size)

# In case the model supports tagging, add the unsloth tag.
if hasattr(model, "add_model_tags"):
model.add_model_tags(["unsloth",])
Expand Down