[feat] introduce `unload_lora()`. (#6451) · fpgaminer/diffusers@ae060fc · GitHub
Skip to content

Commit ae060fc

Browse files
authored
[feat] introduce unload_lora(). (huggingface#6451)
* introduce unload_lora. * fix-copies
1 parent 9d945b2 commit ae060fc

4 files changed

Lines changed: 38 additions & 10 deletions

File tree

‎src/diffusers/models/unet_2d_condition.py‎

Lines changed: 11 additions & 0 deletions

‎src/diffusers/models/unet_3d_condition.py‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from ..configuration_utils import ConfigMixin, register_to_config
2424
from ..loaders import UNet2DConditionLoadersMixin
25-
from ..utils import BaseOutput, logging
25+
from ..utils import BaseOutput, deprecate, logging
2626
from .activations import get_activation
2727
from .attention_processor import (
2828
ADDED_KV_ATTENTION_PROCESSORS,
@@ -503,6 +503,18 @@ def disable_freeu(self):
503503
if hasattr(upsample_block, k) or getattr(upsample_block, k, None) is not None:
504504
setattr(upsample_block, k, None)
505505

506+
# Copied from diffusers.models.unet_2d_condition.UNet2DConditionModel.unload_lora
507+
def unload_lora(self):
508+
"""Unloads LoRA weights."""
509+
deprecate(
510+
"unload_lora",
511+
"0.28.0",
512+
"Calling `unload_lora()` is deprecated and will be removed in a future version. Please install `peft` and then call `disable_adapters().",
513+
)
514+
for module in self.modules():
515+
if hasattr(module, "set_lora_layer"):
516+
module.set_lora_layer(None)
517+
506518
def forward(
507519
self,
508520
sample: torch.FloatTensor,

‎src/diffusers/pipelines/deprecated/versatile_diffusion/modeling_text_unet.py‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,17 @@ def unfuse_qkv_projections(self):
10341034
if self.original_attn_processors is not None:
10351035
self.set_attn_processor(self.original_attn_processors)
10361036

1037+
def unload_lora(self):
1038+
"""Unloads LoRA weights."""
1039+
deprecate(
1040+
"unload_lora",
1041+
"0.28.0",
1042+
"Calling `unload_lora()` is deprecated and will be removed in a future version. Please install `peft` and then call `disable_adapters().",
1043+
)
1044+
for module in self.modules():
1045+
if hasattr(module, "set_lora_layer"):
1046+
module.set_lora_layer(None)
1047+
10371048
def forward(
10381049
self,
10391050
sample: torch.FloatTensor,

‎tests/lora/test_lora_layers_old_backend.py‎

Lines changed: 3 additions & 9 deletions

0 commit comments

Comments
 (0)