MCPcopy
hub / github.com/huggingface/peft / add_adapter

Method add_adapter

src/peft/peft_model.py:2621–2661  ·  view source on GitHub ↗

Add an adapter to the model based on the passed configuration. This adapter is not trained. To load a trained adapter, check out [`PeftModel.load_adapter`]. The name for the new adapter should be unique. The new adapter is not automatically set as the active adapt

(
        self,
        adapter_name: str,
        peft_config: PeftConfig,
        low_cpu_mem_usage: bool = False,
        autocast_adapter_dtype: bool = True,
    )

Source from the content-addressed store, hash-verified

2619 )
2620
2621 def add_adapter(
2622 self,
2623 adapter_name: str,
2624 peft_config: PeftConfig,
2625 low_cpu_mem_usage: bool = False,
2626 autocast_adapter_dtype: bool = True,
2627 ) -> None:
2628 """
2629 Add an adapter to the model based on the passed configuration.
2630
2631 This adapter is not trained. To load a trained adapter, check out [`PeftModel.load_adapter`].
2632
2633 The name for the new adapter should be unique.
2634
2635 The new adapter is not automatically set as the active adapter. Use [`PeftModel.set_adapter`] to set the active
2636 adapter.
2637
2638 Args:
2639 adapter_name (`str`):
2640 The name of the adapter to be added.
2641 peft_config ([`PeftConfig`]):
2642 The configuration of the adapter to be added.
2643 low_cpu_mem_usage (`bool`, `optional`, defaults to `False`):
2644 Create empty adapter weights on meta device. Useful to speed up the process when loading saved
2645 adapters. Don't use this option when creating a new PEFT adapter for training.
2646 autocast_adapter_dtype (`bool`, *optional*, defaults to `True`):
2647 Whether to autocast the adapter dtype. Defaults to `True`. Right now, this will only cast adapter
2648 weights using float16 and bfloat16 to float32, as this is typically required for stable training, and
2649 only affect select PEFT tuners. If set to `False`, the dtypes will stay the same as those of the
2650 corresponding layer.
2651
2652 """
2653 # ensure that additional adapters also add the classifier layer to modules_to_save
2654 if hasattr(peft_config, "modules_to_save"):
2655 classifier_module_names = ["classifier", "score"]
2656 if peft_config.modules_to_save is None:
2657 peft_config.modules_to_save = classifier_module_names[:]
2658 else:
2659 peft_config.modules_to_save.extend(classifier_module_names)
2660
2661 return super().add_adapter(adapter_name, peft_config, low_cpu_mem_usage=low_cpu_mem_usage)
2662
2663 def forward(
2664 self,

Callers

nothing calls this directly

Calls 1

add_adapterMethod · 0.45

Tested by

no test coverage detected