Skip to content

Finetune Yi model: RuntimeError: Unsloth: Extra special token <|startoftext|> with id=64000 exceeds the maximum vocabulary size of 64000 #61

Closed

Description

@IvoryTower800

I saw unsloth support finetune qlora model of Yi. So I tried using below script to finetune Yi-34B-Chat. Then I encountered blow error.
Could you please tell me how to fix it?

Thank you!

CUDA_VISIBLE_DEVICES=0 deepspeed --num_gpus=1 /root/LLaMA-Factory/src/train_bash.py
--model_name_or_path /root/download/01ai/Yi-34B-Chat
--dataset_dir /root/LLaMA-Factory/data
--output_dir /root/output/Yi-34B-Chat
--use_unsloth
--dataset alpaca_gpt4_en
--stage sft
--sft_packing True
--do_train True
--finetuning_type lora
--quantization_bit 4
--template yi
--cutoff_len 4096
--learning_rate 1e-4
--preprocessing_num_workers 8
--num_train_epochs 1.0
--max_samples 1000000
--per_device_train_batch_size 1
--gradient_accumulation_steps 8
--lr_scheduler_type cosine
--max_grad_norm 1.0
--logging_steps 1
--save_steps 100
--warmup_steps 0
--neftune_noise_alpha 5
--lora_rank 128
--lora_alpha 256
--lora_dropout 0
--lora_target all
--fp16 True
--plot_loss True
--overwrite_output_dir True
--deepspeed ds_config_zero2.json

[INFO|tokenization_utils_base.py:2024] 2024-01-03 12:45:42,955 >> loading file tokenizer.model
[INFO|tokenization_utils_base.py:2024] 2024-01-03 12:45:42,956 >> loading file tokenizer.json
[INFO|tokenization_utils_base.py:2024] 2024-01-03 12:45:42,956 >> loading file added_tokens.json
[INFO|tokenization_utils_base.py:2024] 2024-01-03 12:45:42,956 >> loading file special_tokens_map.json
[INFO|tokenization_utils_base.py:2024] 2024-01-03 12:45:42,956 >> loading file tokenizer_config.json
Traceback (most recent call last):
File "/root/LLaMA-Factory/src/train_bash.py", line 14, in
main()
File "/root/LLaMA-Factory/src/train_bash.py", line 5, in main
run_exp()
File "/root/LLaMA-Factory/src/llmtuner/train/tuner.py", line 26, in run_exp
run_sft(model_args, data_args, training_args, finetuning_args, generating_args, callbacks)
File "/root/LLaMA-Factory/src/llmtuner/train/sft/workflow.py", line 29, in run_sft
model, tokenizer = load_model_and_tokenizer(model_args, finetuning_args, training_args.do_train)
File "/root/LLaMA-Factory/src/llmtuner/model/loader.py", line 75, in load_model_and_tokenizer
model, _ = FastLlamaModel.from_pretrained(**unsloth_kwargs)
File "/root/.local/conda/envs/cpp/lib/python3.10/site-packages/unsloth/models/llama.py", line 717, in from_pretrained
check_tokenizer(model, tokenizer)
File "/root/.local/conda/envs/cpp/lib/python3.10/site-packages/unsloth/models/_utils.py", line 131, in check_tokenizer
raise RuntimeError(
RuntimeError: Unsloth: Extra special token <|startoftext|> with id=64000 exceeds the maximum vocabulary size of 64000. You must fix the tokenizer or else out of bounds memory accesses will occur.
[2024-01-03 12:45:50,260] [INFO] [launch.py:315:sigkill_handler] Killing subprocess 27792

Activity

  1. danielhanchen commented on Jan 3, 2024

    @danielhanchen
    Member

    @IvoryTower800 Maybe updating Unsloth might work?

    image

    For me it works fine for Yi-34b

  2. IvoryTower800 commented on Jan 3, 2024

    @IvoryTower800
    Author

    @danielhanchen Thank you for your reply. I was running the same version of unsloth with you (I installed with pip install "unsloth[cu118] @ git+https://github.com/unslothai/unsloth.git").

    Also, I tried create a new virtual environment with python 3.10+torch 2.1.0 + unsloth (pip install "unsloth[cu118] @ git+https://github.com/unslothai/unsloth.git"). the error still exists.

    The model I'm trying to finetune is Yi-34B-Chat, not Yi-34B. I saw they have different tokenizer config. will this cause the issue I encountered?
    Thank you!

  3. danielhanchen commented on Jan 3, 2024

    @danielhanchen
    Member

    @IvoryTower800 Oh yes that could be the reason - let me check the Chat version and get back to you

  4. AIlaowong commented on Jan 4, 2024

    @AIlaowong

    After updating today, I also encountered this issue when training yi-6b-chat.

  5. danielhanchen commented on Jan 4, 2024

    @danielhanchen
    Member

    @IvoryTower800 @AIlaowong Just solved it with the latest patch! It'll be cool if you can try it out! It turns out using a FastTokenizer broke some of the chat models, so instead of an error, I use a SlowTokenizer to bypass the error.

    Hope it works!

  6. IvoryTower800 commented on Jan 4, 2024

    @IvoryTower800
    Author

    @danielhanchen Thank you so much. I just tried with latest code. It works! no errors any more!

  7. danielhanchen commented on Jan 5, 2024

    @danielhanchen
    Member
  8. danielhanchen commented on Jan 6, 2024

    @danielhanchen
    Member

    Closing since solved!

  9. added a commit that references this issue on Jun 8, 2025
  10. added a commit that references this issue on Jun 25, 2025
  11. added a commit that references this issue on Jul 7, 2025
  12. added a commit that references this issue on Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions