You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Resize embeddings, tokenizers - adding new tokens don't work #1108
From Twitter - adding new tokens to Qwen don't work?
# Add special tokens to the tokenizernum_added_tokens=tokenizer.add_special_tokens({"additional_special_tokens": special_tokens})
# Resize token embeddings of the modelmodel.resize_token_embeddings(len(tokenizer))
I looked, and AFAIK, Qwen uses a different tokenization method (BPE on UTF-8 bytes) and has a specific way of handling unique tokens. Also, Qwen has extra special tokens from <|extra_0|> to <|extra_204|> for custom use.
Unsloth has a function called add_new_tokens which allows you to add new tokens to your finetune. For example if you want to add <CHARACTER_1>, <THINKING> and <SCRATCH_PAD> we can do the following:
I add new tokens and fine tuned but in inferance I get error with torch size. My checkpoint torch.Size([128259, 4096]), my model size torch.Size([128256, 4096]), how to fix this
This should be fixed now - sorry on the delay - please update with uv pip install --upgrade unsloth unsloth_zoo --force-reinstall --no-cache-dir - if it's not fixed yet, it'll be in the next pip / PyPI release - if it's still not working after that, please open another issue - appreciate it again!
Activity
Selich commentedon Oct 17, 2024
First time here,
I looked, and AFAIK, Qwen uses a different tokenization method (BPE on UTF-8 bytes) and has a specific way of handling unique tokens. Also, Qwen has extra special tokens from
<|extra_0|>to<|extra_204|>for custom use.https://github.com/QwenLM/Qwen/blob/main/tokenization_note.md
danielhanchen commentedon Oct 18, 2024
I just added a new way to add new tokens - see https://github.com/unslothai/unsloth/wiki#adding-new-tokens
Unsloth has a function called
add_new_tokenswhich allows you to add new tokens to your finetune. For example if you want to add<CHARACTER_1>,<THINKING>and<SCRATCH_PAD>we can do the following:Note - you MUST always call
add_new_tokensbeforeFastLanguageModel.get_peft_model!risqaliyevds commentedon Oct 19, 2024
I add new tokens and fine tuned but in inferance I get error with torch size. My checkpoint torch.Size([128259, 4096]), my model size torch.Size([128256, 4096]), how to fix this
danielhanchen commentedon Jun 18, 2026
This should be fixed now - sorry on the delay - please update with
uv pip install --upgrade unsloth unsloth_zoo --force-reinstall --no-cache-dir- if it's not fixed yet, it'll be in the next pip / PyPI release - if it's still not working after that, please open another issue - appreciate it again!