Unverified Commit 329771e5 authored by Sayak Paul's avatar Sayak Paul Committed by GitHub
Browse files

[LoRA] improve failure handling for peft. (#10551)



* improve failure handling for peft.

* emppty

* Update src/diffusers/loaders/peft.py
Co-authored-by: default avatarBenjamin Bossan <BenjaminBossan@users.noreply.github.com>

---------
Co-authored-by: default avatarBenjamin Bossan <BenjaminBossan@users.noreply.github.com>
parent f7cb5954
...@@ -300,15 +300,17 @@ class PeftAdapterMixin: ...@@ -300,15 +300,17 @@ class PeftAdapterMixin:
try: try:
inject_adapter_in_model(lora_config, self, adapter_name=adapter_name, **peft_kwargs) inject_adapter_in_model(lora_config, self, adapter_name=adapter_name, **peft_kwargs)
incompatible_keys = set_peft_model_state_dict(self, state_dict, adapter_name, **peft_kwargs) incompatible_keys = set_peft_model_state_dict(self, state_dict, adapter_name, **peft_kwargs)
except RuntimeError as e: except Exception as e:
for module in self.modules(): # In case `inject_adapter_in_model()` was unsuccessful even before injecting the `peft_config`.
if isinstance(module, BaseTunerLayer): if hasattr(self, "peft_config"):
active_adapters = module.active_adapters for module in self.modules():
for active_adapter in active_adapters: if isinstance(module, BaseTunerLayer):
if adapter_name in active_adapter: active_adapters = module.active_adapters
module.delete_adapter(adapter_name) for active_adapter in active_adapters:
if adapter_name in active_adapter:
self.peft_config.pop(adapter_name) module.delete_adapter(adapter_name)
self.peft_config.pop(adapter_name)
logger.error(f"Loading {adapter_name} was unsucessful with the following error: \n{e}") logger.error(f"Loading {adapter_name} was unsucessful with the following error: \n{e}")
raise raise
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment