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