Skip to content

How to use Yi-34b? #51

Closed
Closed

Description

@C00reNUT

Hello,
I am trying to use Yi-34b model using this code

model_name = 'chargoddard/Yi-34B-Llama'
max_seq_length = 2048
learning_rate = 2e-4
weight_decay = 0.01
warmup_steps = 10
batch_size = 1
gradient_accumulation_steps = 16
lr_scheduler_type = "linear"
optimizer = "adamw_8bit"
use_gradient_checkpointing = True
random_state = 3407

from unsloth import FastLlamaModel
import torch
dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
HAS_BFLOAT16 = torch.cuda.is_bf16_supported()

model, tokenizer = FastLlamaModel.from_pretrained(
    model_name = model_name,
    max_seq_length = max_seq_length,
    dtype = dtype,
    load_in_4bit = load_in_4bit,
    # token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf
)

but I am getting the following error


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[23], line 7
      4 load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
      5 HAS_BFLOAT16 = torch.cuda.is_bf16_supported()
----> 7 model, tokenizer = FastLlamaModel.from_pretrained(
      8     model_name = model_name,
      9     max_seq_length = max_seq_length,
     10     dtype = dtype,
     11     load_in_4bit = load_in_4bit,
     12     # token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf
     13 )

File /mnt/a0b764eb-cdc5-4f46-9a2e-e2f11deba631/PYTHON_CACHE/unsloth/lib/python3.11/site-packages/unsloth/models/llama.py:658, in FastLlamaModel.from_pretrained(model_name, max_seq_length, dtype, load_in_4bit, token, device_map, rope_scaling)
    643     bnb_config = BitsAndBytesConfig(
    644         load_in_4bit              = True,
    645         bnb_4bit_use_double_quant = True,
    646         bnb_4bit_quant_type       = "nf4",
    647         bnb_4bit_compute_dtype    = dtype,
    648     )
    650 model = AutoModelForCausalLM.from_pretrained(
    651     model_name,
    652     device_map = device_map,
   (...)
    656     rope_scaling = rope_scaling,
    657 )
--> 658 tokenizer = AutoTokenizer.from_pretrained(
    659     model_name,
    660     model_max_length = max_seq_length,
    661     padding_side = "right",
    662     token = token,
    663 )
    665 model, tokenizer = patch_tokenizer(model, tokenizer)
    666 model = FastLlamaModel.post_patch(model)

File /mnt/a0b764eb-cdc5-4f46-9a2e-e2f11deba631/PYTHON_CACHE/unsloth/lib/python3.11/site-packages/transformers/models/auto/tokenization_auto.py:784, in AutoTokenizer.from_pretrained(cls, pretrained_model_name_or_path, *inputs, **kwargs)
    782         tokenizer_class = tokenizer_class_from_name(tokenizer_class_candidate)
    783     if tokenizer_class is None:
--> 784         raise ValueError(
    785             f"Tokenizer class {tokenizer_class_candidate} does not exist or is not currently imported."
    786         )
    787     return tokenizer_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
    789 # Otherwise we have to be creative.
    790 # if model is an encoder decoder, the encoder tokenizer class is used by default

ValueError: Tokenizer class YiTokenizer does not exist or is not currently imported.

Could you tell me what I am doing wrong? Thank you!

Activity

  1. danielhanchen commented on Dec 24, 2023

    @danielhanchen
    Member

    @C00reNUT Does loading that specific tokenizer work normally via AutoTokenizer.from_pretrained?

  2. C00reNUT commented on Dec 24, 2023

    @C00reNUT
    Author

    Well, when I was finetuning Mistral using FastMistralModel class everything worked just fine. I didn't try to finetune other Llama model yet.

  3. C00reNUT commented on Dec 24, 2023

    @C00reNUT
    Author

    @C00reNUT Does loading that specific tokenizer work normally via AutoTokenizer.from_pretrained?

    If you mean this

    from transformers import AutoTokenizer
    
    tokenizer = AutoTokenizer.from_pretrained(
        'chargoddard/Yi-34B-Llama',
        model_max_length = max_seq_length,
        padding_side = "right",
    )
    

    I am getting the same error

    
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    Cell In[8], line 3
          1 from transformers import AutoTokenizer
    ----> 3 tokenizer = AutoTokenizer.from_pretrained(
          4     'chargoddard/Yi-34B-Llama',
          5     model_max_length = max_seq_length,
          6     padding_side = "right",
          7     # token = token,
          8 )
    
    File /mnt/a0b764eb-cdc5-4f46-9a2e-e2f11deba631/PYTHON_CACHE/unsloth/lib/python3.11/site-packages/transformers/models/auto/tokenization_auto.py:784, in AutoTokenizer.from_pretrained(cls, pretrained_model_name_or_path, *inputs, **kwargs)
        782         tokenizer_class = tokenizer_class_from_name(tokenizer_class_candidate)
        783     if tokenizer_class is None:
    --> 784         raise ValueError(
        785             f"Tokenizer class {tokenizer_class_candidate} does not exist or is not currently imported."
        786         )
        787     return tokenizer_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
        789 # Otherwise we have to be creative.
        790 # if model is an encoder decoder, the encoder tokenizer class is used by default
    
    ValueError: Tokenizer class YiTokenizer does not exist or is not currently imported.
    
  4. danielhanchen commented on Dec 24, 2023

    @danielhanchen
    Member

    @C00reNUT That seems like a Huggingface error :(

  5. danielhanchen commented on Dec 24, 2023

    @danielhanchen
    Member
  6. danielhanchen commented on Dec 24, 2023

    @danielhanchen
    Member

    Wait, can't you just use https://huggingface.co/01-ai/Yi-34B directly? Ie 01-ai/Yi-34B. I'm pretty sure Unsloth supports Yi since its a Llama arch

  7. C00reNUT commented on Dec 24, 2023

    @C00reNUT
    Author

    thank you now, it works

  8. danielhanchen commented on Dec 25, 2023

    @danielhanchen
    Member

    @C00reNUT Great! If you need any help - ask away!

  9. C00reNUT commented on Dec 26, 2023

    @C00reNUT
    Author

    @danielhanchen thank you, I am able to get 2048 context on 3090, while on axolotl I was able to do cca 1500. Also the speed is maybe 30 percent better.

    I was hoping for full context after seeing some of your benchmarks but, I am probably too demanding :) Hopefully you will allow to buy some more powerful pro licensed version soon...

  10. danielhanchen commented on Dec 26, 2023

    @danielhanchen
    Member

    @C00reNUT Have you tried batch size = 1 maybe? (Or I'm assuming it's that?) Oh 30% better than Axolotl? That's pretty sick! (Packing no packing? :) )

    We're still figuring stuff out, but glad at least you got a bit more context and it's faster :)

  11. C00reNUT commented on Dec 26, 2023

    @C00reNUT
    Author

    @danielhanchen Yes, comparing to axolotl and using batch size = 1.

    Thank you for providing at least some functionality for free. From business perspective it will be interesting to see, how you will structure those pro licenses. You will need to have to some recurring fees to sustain the costs of development for yourself...

  12. danielhanchen commented on Dec 26, 2023

    @danielhanchen
    Member

    Thanks @C00reNUT ! Extremely appreciate it! Your comment made my day! :) I will definitely get back to you in the near future on licensing :) Thanks again!

  13. added a commit that references this issue on Jun 8, 2025
  14. added a commit that references this issue on Jun 25, 2025
  15. added a commit that references this issue on Jul 7, 2025
  16. 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