Skip to content

LORA merge not working #1929

Closed
Closed

Description

@KenR22

Hi I am finetuning the qwen model using the grpo notebook. I tried merging the model with save_pretrained and loading it using this

from unsloth import FastLanguageModel, PatchFastRL
PatchFastRL("GRPO", FastLanguageModel)
model, tokenizer = FastLanguageModel.from_pretrained(
    model_name = "model",
    max_seq_length = 200,
    load_in_4bit = False, # False for LoRA 16bit
    fast_inference = True, # Enable vLLM fast inference

    gpu_memory_utilization = 0.9, # Reduce if out of memory
)

Resetting the model to original performance on the strawberry question.
Any pointer on how to merge lora adapter? I also want to hook the models for activation later.

Thanks

Activity

  1. FloLey commented on Mar 7, 2025

    @FloLey

    #1670
    #1763
    #1877

    I think all this issues are the same.

  2. Cgrandjean commented on Mar 7, 2025

    @Cgrandjean

    yeah seems those issues are all related. I can confirm got not only the issue i described in #1877, but also this one with 16 bit adapter merging. I could not find the thing in our configuration causing that .

  3. shimmyshimmer commented on Mar 18, 2025

    @shimmyshimmer
    Member

    Hi guys we have likely resolved the issue. Please update unsloth and let us know if it works! Thank you

  4. added
    fixed - pending confirmation
    on Mar 18, 2025
  5. zzz1YAO commented on Mar 20, 2025

    @zzz1YAO

    I have a same question

  6. rolandtannous commented on Jun 6, 2025

    @rolandtannous
    Contributor

    @BY571 @FloLey @Joinn99 @K1nght @Mtrya @SpaceHunterInf @Xiaohan-Tian @Yangt524 @canrertugrul @fullstackwebdev @janpf @juli2807 @kjm981995 @liuchengyuan123 @lucky-bai @maopian2333 @matthewchung74 @mingqing431 @mominabbass @saadi297 @vasqu @whiskyboy @wofeishenling @wooozihui @yuimo @yuiseki

    A fix has now been merged into pypi for both vision and language models and extensively tested.
    reference:
    unslothai/unsloth-zoo#135
    unslothai/unsloth-zoo#158
    #2673
    Merging and saving should work now.

    Best Practice is save to 16bits (which is the default operation if you do not specify anything), and load in 4 bits if you have to.
    For production systems, you might wanna consider post training quantization methods with calibration. These take longer but can also be more reliable.
    Saving and merging to 4bits might degrade performance of the model.

    To access this recent fix, and if you're running this in a local python environment, please make sure to upgrade your python environment using

    pip install --upgrade unsloth_zoo
    pip install --upgrade unsloth
    

    If you're in colab, the notebooks install cell will also be updated shortly but should be something like

    %%capture
    import os
    if "COLAB_" not in "".join(os.environ.keys()):
        !pip install unsloth
    else:
        # Do this only in Colab notebooks! Otherwise use pip install unsloth
        !pip install --no-deps bitsandbytes accelerate xformers==0.0.29.post3 peft trl triton transformers cut_cross_entropy unsloth_zoo
        !pip install sentencepiece protobuf "datasets>=3.4.1" huggingface_hub hf_transfer
        !pip install --no-deps unsloth
    

    as we're no longer pinning transformers or trl.

    Also note that whenever you need to merge while saving or while pushing to hub, make sure to use

    save_pretrained_merged()
    

    and

    push_to_hub_merged()
    

    If you are not merging at all, use

    save_pretrained
    

    and

    push_to_hub
    

    instead.

    I'll close this for now. Feel free to comment if you face any problems.
    Happy finetuning.

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

    fixed - pending confirmation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions