diff --git a/src/diffusers/loaders/lora_base.py b/src/diffusers/loaders/lora_base.py index 07f8db170844..3ffc0f3b056c 100644 --- a/src/diffusers/loaders/lora_base.py +++ b/src/diffusers/loaders/lora_base.py @@ -698,7 +698,9 @@ 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. @@ -706,9 +708,13 @@ def set_adapters( 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: @@ -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):