Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/diffusers/loaders/lora_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,17 +698,23 @@ def unfuse_lora(self, components: list[str] | None = None, **kwargs):
def set_adapters(
self,
adapter_names: list[str] | str,
adapter_weights: float | dict | list[float] | list[dict] | None = None,
adapter_weights: (
float | dict[str, float | dict | None] | list[float | dict[str, float | dict | None] | None] | None
) = None,
):
"""
Set the currently active adapters for use in the pipeline.

Args:
adapter_names (`list[str]` or `str`):
The names of the adapters to use.
adapter_weights (`list[float, float]`, *optional*):
The adapter(s) weights to use with the UNet. If `None`, the weights are set to `1.0` for all the
adapters.
adapter_weights (`float`, `dict` or `list`, *optional*):
Weights for the adapters. A scalar scales all LoRA-compatible components. A dictionary maps component
names (e.g. `"unet"`, `"transformer"` or `"text_encoder"`) to weights; a UNet component's weight can
also be a nested dictionary of block scales. A single scalar or dictionary is applied to every adapter.
A list must contain one scalar, dictionary or `None` per adapter, in the order of `adapter_names`.
`None` defaults to `1.0`, including list entries and component weights. Unspecified components and UNet
blocks also default to `1.0`.

Example:

Expand All @@ -722,8 +728,14 @@ def set_adapters(
pipeline.load_lora_weights(
"jbilcke-hf/sdxl-cinematic-1", weight_name="pytorch_lora_weights.safetensors", adapter_name="cinematic"
)
pipeline.load_lora_weights("nerijs/pixel-art-xl", weight_name="pixel-art-xl.safetensors", adapter_name="pixel")
pipeline.set_adapters(["cinematic", "pixel"], adapter_weights=[0.5, 0.5])
pipeline.load_lora_weights(
"troveski/sdxl-lora", weight_name="pytorch_lora_weights.safetensors", adapter_name="illustration"
)
pipeline.set_adapters(["cinematic", "illustration"], adapter_weights=[0.5, 0.5])
pipeline.set_adapters(
["cinematic", "illustration"],
adapter_weights=[{"unet": 0.5}, {"unet": 0.8, "text_encoder": 0.6}],
)
```
"""
if isinstance(adapter_weights, dict):
Expand Down
Loading