Skip to content

Commit e40390d

Browse files
Reviewer feedback: version check, TODO comment
1 parent a715559 commit e40390d

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/diffusers/loaders/peft.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,14 +326,14 @@ def load_lora_adapter(
326326
peft_kwargs["low_cpu_mem_usage"] = low_cpu_mem_usage
327327

328328
if hotswap:
329-
try:
329+
if is_peft_version(">", "0.14.0"):
330330
from peft.utils.hotswap import check_hotswap_configs_compatible, hotswap_adapter_from_state_dict
331-
except ImportError as exc:
331+
else:
332332
msg = (
333333
"Hotswapping requires PEFT > v0.14. Please upgrade PEFT to a higher version or install it "
334334
"from source."
335335
)
336-
raise ImportError(msg) from exc
336+
raise ImportError(msg)
337337

338338
if hotswap:
339339

src/diffusers/loaders/unet.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,14 @@ def _process_lora(
378378
peft_kwargs["low_cpu_mem_usage"] = low_cpu_mem_usage
379379

380380
if hotswap:
381-
try:
381+
if is_peft_version(">", "0.14.0"):
382382
from peft.utils.hotswap import check_hotswap_configs_compatible, hotswap_adapter_from_state_dict
383-
except ImportError as exc:
383+
else:
384384
msg = (
385385
"Hotswapping requires PEFT > v0.14. Please upgrade PEFT to a higher version or install it "
386386
"from source."
387387
)
388-
raise ImportError(msg) from exc
388+
raise ImportError(msg)
389389

390390
if hotswap:
391391

@@ -418,6 +418,8 @@ def map_state_dict_for_hotswap(sd):
418418
inject_adapter_in_model(lora_config, self, adapter_name=adapter_name, **peft_kwargs)
419419
incompatible_keys = set_peft_model_state_dict(self, state_dict, adapter_name, **peft_kwargs)
420420
except Exception as e:
421+
# TODO: add test in line with:
422+
# https://github.com/huggingface/diffusers/pull/10188/files#diff-b544edcc938e163009735ef4fa963abd0a41615c175552160c9e0f94ceb7f552
421423
# In case `inject_adapter_in_model()` was unsuccessful even before injecting the `peft_config`.
422424
if hasattr(self, "peft_config"):
423425
for module in self.modules():

0 commit comments

Comments
 (0)