Skip to content

Commit 7bc0a07

Browse files
authored
[lora] only remove hooks that we add back (#11768)
up
1 parent 9254271 commit 7bc0a07

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/diffusers/loaders/lora_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ def _func_optionally_disable_offloading(_pipeline):
453453
logger.info(
454454
"Accelerate hooks detected. Since you have called `load_lora_weights()`, the previous hooks will be first removed. Then the LoRA parameters will be loaded and the hooks will be applied again."
455455
)
456-
remove_hook_from_module(component, recurse=is_sequential_cpu_offload)
456+
if is_sequential_cpu_offload or is_model_cpu_offload:
457+
remove_hook_from_module(component, recurse=is_sequential_cpu_offload)
457458

458459
return (is_model_cpu_offload, is_sequential_cpu_offload)
459460

src/diffusers/loaders/textual_inversion.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,8 @@ def load_textual_inversion(
427427
logger.info(
428428
"Accelerate hooks detected. Since you have called `load_textual_inversion()`, the previous hooks will be first removed. Then the textual inversion parameters will be loaded and the hooks will be applied again."
429429
)
430-
remove_hook_from_module(component, recurse=is_sequential_cpu_offload)
430+
if is_sequential_cpu_offload or is_model_cpu_offload:
431+
remove_hook_from_module(component, recurse=is_sequential_cpu_offload)
431432

432433
# 7.2 save expected device and dtype
433434
device = text_encoder.device

0 commit comments

Comments
 (0)