Skip to content

[Question] Adding several peft adapters and ensuring unsloth takes them into account #2411

Closed

Description

@tcarta

Adding several peft adapters
I would like to add several peft adapters to my LLM. Since unsloth does not override the add_adapter function in PEFT I currently use the following:

config = LoraConfig(
                r=self._r,
                lora_alpha=self._alpha,
                target_modules=target_modules,
                lora_dropout=0,
                bias="none"
            )
unsloth_peft_config = config.to_dict()
del unsloth_peft_config["task_type"]
peft_model =  FastLanguageModel.get_peft_model(
                    llm_module,
                    **unsloth_peft_config,
                    use_gradient_checkpointing="unsloth" if not self._use_cache else False
                )
peft_model.add_adapter("new_adapter_1", config)
peft_model.add_adapter("new_adapter_2", config)
peft_model.add_adapter("new_adapter_3", config)

I am wondering if it is the correct method to adopt or if there is a better way to do it? Are the new adapters taken into account by unsloth?

Activity

  1. changed the title [-][Question][/-] [+][Question] Adding several peft adpaters[/+] on Apr 25, 2025
  2. changed the title [-][Question] Adding several peft adpaters[/-] [+][Question] Adding several peft adapters[/+] on Apr 25, 2025
  3. changed the title [-][Question] Adding several peft adapters[/-] [+][Question] Adding several peft adapters and ensuring unsloth takes them into account[/+] on Apr 26, 2025
  4. rolandtannous commented on May 23, 2025

    @rolandtannous
    Contributor

    @tcarta add adapter is a no-op operation.

    If you mean to add already finetuned adapters so you can use them, you need to use load_adapter and set_adapter.

    here is an example:
    1- update unsloth-zoo and unsloth :

    pip install --upgrade unsloth-zoo unsloth
    
    1. Load the Base Model. Using Qwe2.5-VL-7B-Instruct as an example:
    model_id = "unsloth/Qwen2.5-VL-7B-Instruct"
    
    base_model, model_processor = FastVisionModel.from_pretrained(
        model_id,
        load_in_4bit=False,
    )
    
    1. Load the first adapter on top of the base model:
    base_model.load_adapter("/path/to_adapter/", adapter_name="adapter_1")
    
    1. Load second adapter on top of the base model
    base_model.load_adapter("/path/to_adapter/", adapter_name="adapter_2")
    

    You can repeat step number 4 as many times as you like.

    1. Activate an adapter to use it. Let's say i want to use adapter 1:
    base_model.set_adapter("adapter_1")
    

    To activate adapter 2 and use it , do the same:

    base_model.set("adapter_2")
    

    Hope this helps.

    Let me know if it works out for you or not.

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