(model, adapter_name)
| 214 | |
| 215 | |
| 216 | def delete_adapter_layers(model, adapter_name): |
| 217 | from peft.tuners.tuners_utils import BaseTunerLayer |
| 218 | |
| 219 | for module in model.modules(): |
| 220 | if isinstance(module, BaseTunerLayer): |
| 221 | if hasattr(module, "delete_adapter"): |
| 222 | module.delete_adapter(adapter_name) |
| 223 | else: |
| 224 | raise ValueError( |
| 225 | "The version of PEFT you are using is not compatible, please use a version that is greater than 0.6.1" |
| 226 | ) |
| 227 | |
| 228 | # For transformers integration - we need to pop the adapter from the config |
| 229 | if getattr(model, "_hf_peft_config_loaded", False) and hasattr(model, "peft_config"): |
| 230 | model.peft_config.pop(adapter_name, None) |
| 231 | # In case all adapters are deleted, we need to delete the config |
| 232 | # and make sure to set the flag to False |
| 233 | if len(model.peft_config) == 0: |
| 234 | del model.peft_config |
| 235 | model._hf_peft_config_loaded = None |
| 236 | |
| 237 | |
| 238 | def set_weights_and_activate_adapters(model, adapter_names, weights): |
no test coverage detected