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

Method add_adapter

src/peft/peft_model.py:1728–1767  ·  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

1726 )
1727
1728 def add_adapter(
1729 self,
1730 adapter_name: str,
1731 peft_config: PeftConfig,
1732 low_cpu_mem_usage: bool = False,
1733 autocast_adapter_dtype: bool = True,
1734 ) -> None:
1735 """
1736 Add an adapter to the model based on the passed configuration.
1737
1738 This adapter is not trained. To load a trained adapter, check out [`PeftModel.load_adapter`].
1739
1740 The name for the new adapter should be unique.
1741
1742 The new adapter is not automatically set as the active adapter. Use [`PeftModel.set_adapter`] to set the active
1743 adapter.
1744
1745 Args:
1746 adapter_name (`str`):
1747 The name of the adapter to be added.
1748 peft_config ([`PeftConfig`]):
1749 The configuration of the adapter to be added.
1750 low_cpu_mem_usage (`bool`, `optional`, defaults to `False`):
1751 Create empty adapter weights on meta device. Useful to speed up the process when loading saved
1752 adapters. Don't use this option when creating a new PEFT adapter for training.
1753 autocast_adapter_dtype (`bool`, *optional*, defaults to `True`):
1754 Whether to autocast the adapter dtype. Defaults to `True`. Right now, this will only cast adapter
1755 weights using float16 and bfloat16 to float32, as this is typically required for stable training, and
1756 only affect select PEFT tuners. If set to `False`, the dtypes will stay the same as those of the
1757 corresponding layer.
1758 """
1759 # ensure that additional adapters also add the classifier layer to modules_to_save
1760 if hasattr(peft_config, "modules_to_save"):
1761 classifier_module_names = ["classifier", "score"]
1762 if peft_config.modules_to_save is None:
1763 peft_config.modules_to_save = classifier_module_names[:]
1764 else:
1765 peft_config.modules_to_save.extend(classifier_module_names)
1766
1767 return super().add_adapter(adapter_name, peft_config, low_cpu_mem_usage=low_cpu_mem_usage)
1768
1769 def forward(
1770 self,

Callers

nothing calls this directly

Calls 1

add_adapterMethod · 0.45

Tested by

no test coverage detected