Skip to content

[Feature] Hope the Initalization could be faster #2586

Closed

Description

@charliedream1

Initialization of loading model is too slow, it can take up to 2 mintes, even I'm using H800 server, it's still very slow. Much slower compared transformers library. Hope it will be optimized

Activity

  1. added
    feature request
    on May 20, 2025
  2. rolandtannous commented on May 20, 2025

    @rolandtannous
    Contributor

    @charliedream1 what initialization code are you talking about?
    1- importing the unsloth library, or
    2- loading a model using FastModel/FastLanguageModel/FastVisualModel?

    I am using an A100 here and it's not slow

  3. charliedream1 commented on May 20, 2025

    @charliedream1
    Author
    model, tokenizer = FastLanguageModel.from_pretrained(
        model_name = mdl_path,
        max_seq_length = 32768,   # Context length - can be longer, but uses more memory
        load_in_4bit = True,     # 4bit uses much less memory
        load_in_8bit = False,    # A bit more accurate, uses 2x memory
        full_finetuning = False, # We have full finetuning now!
        # token = "hf_...",      # use one if using gated models
    )
    
    model = FastLanguageModel.get_peft_model(
        model,
        r = 32,           # Choose any number > 0! Suggested 8, 16, 32, 64, 128
        target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",
                          "gate_proj", "up_proj", "down_proj",],
        lora_alpha = 32,  # Best to choose alpha = rank or rank*2
        lora_dropout = 0, # Supports any, but = 0 is optimized
        bias = "none",    # Supports any, but = "none" is optimized
        # [NEW] "unsloth" uses 30% less VRAM, fits 2x larger batch sizes!
        use_gradient_checkpointing = "unsloth", # True or "unsloth" for very long context
        random_state = 3407,
        use_rslora = True,   # We support rank stabilized LoRA
        loftq_config = None,  # And LoftQ
    )

    This code on H800, it takes about more than 1 mintes to complete

  4. rolandtannous commented on May 20, 2025

    @rolandtannous
    Contributor

    @charliedream1 , unsloth isn't just wrapping around the transformers library and is applying quite a few optimizations at all stages of a model's lifecycle, which allows finetuning faster and better hence comparison with transformers isn't exactly an Apple to Apple comparison. This looks like an normal thing for me. Thank you for your observation. We appreciate it

  5. shimmyshimmer commented on Jun 7, 2025

    @shimmyshimmer
    Member

    @charliedream1 it might be because we utilize torch.compile under the hood so loading is slightly slower however in the longrun after 5mins or so, you should experience speed boosts and time savings

  6. charliedream1 commented on Jun 7, 2025

    @charliedream1
    Author
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

    feature request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions