r""" Fuses the LoRA parameters into the original parameters of the corresponding blocks. This is an experimental API. Args: components: (`List[str]`): List of LoRA-injectable components to fuse the LoRAs into.
(
self,
components: List[str] = [],
lora_scale: float = 1.0,
safe_fusing: bool = False,
adapter_names: Optional[List[str]] = None,
**kwargs,
)
| 377 | _remove_text_encoder_monkey_patch(model) |
| 378 | |
| 379 | def fuse_lora( |
| 380 | self, |
| 381 | components: List[str] = [], |
| 382 | lora_scale: float = 1.0, |
| 383 | safe_fusing: bool = False, |
| 384 | adapter_names: Optional[List[str]] = None, |
| 385 | **kwargs, |
| 386 | ): |
| 387 | r""" |
| 388 | Fuses the LoRA parameters into the original parameters of the corresponding blocks. |
| 389 | |
| 390 | <Tip warning={true}> |
| 391 | |
| 392 | This is an experimental API. |
| 393 | |
| 394 | </Tip> |
| 395 | |
| 396 | Args: |
| 397 | components: (`List[str]`): List of LoRA-injectable components to fuse the LoRAs into. |
| 398 | lora_scale (`float`, defaults to 1.0): |
| 399 | Controls how much to influence the outputs with the LoRA parameters. |
| 400 | safe_fusing (`bool`, defaults to `False`): |
| 401 | Whether to check fused weights for NaN values before fusing and if values are NaN not fusing them. |
| 402 | adapter_names (`List[str]`, *optional*): |
| 403 | Adapter names to be used for fusing. If nothing is passed, all active adapters will be fused. |
| 404 | |
| 405 | Example: |
| 406 | |
| 407 | ```py |
| 408 | from diffusers import DiffusionPipeline |
| 409 | import torch |
| 410 | |
| 411 | pipeline = DiffusionPipeline.from_pretrained( |
| 412 | "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16 |
| 413 | ).to("cuda") |
| 414 | pipeline.load_lora_weights("nerijs/pixel-art-xl", weight_name="pixel-art-xl.safetensors", adapter_name="pixel") |
| 415 | pipeline.fuse_lora(lora_scale=0.7) |
| 416 | ``` |
| 417 | """ |
| 418 | if "fuse_unet" in kwargs: |
| 419 | depr_message = "Passing `fuse_unet` to `fuse_lora()` is deprecated and will be ignored. Please use the `components` argument and provide a list of the components whose LoRAs are to be fused. `fuse_unet` will be removed in a future version." |
| 420 | deprecate( |
| 421 | "fuse_unet", |
| 422 | "1.0.0", |
| 423 | depr_message, |
| 424 | ) |
| 425 | if "fuse_transformer" in kwargs: |
| 426 | depr_message = "Passing `fuse_transformer` to `fuse_lora()` is deprecated and will be ignored. Please use the `components` argument and provide a list of the components whose LoRAs are to be fused. `fuse_transformer` will be removed in a future version." |
| 427 | deprecate( |
| 428 | "fuse_transformer", |
| 429 | "1.0.0", |
| 430 | depr_message, |
| 431 | ) |
| 432 | if "fuse_text_encoder" in kwargs: |
| 433 | depr_message = "Passing `fuse_text_encoder` to `fuse_lora()` is deprecated and will be ignored. Please use the `components` argument and provide a list of the components whose LoRAs are to be fused. `fuse_text_encoder` will be removed in a future version." |
| 434 | deprecate( |
| 435 | "fuse_text_encoder", |
| 436 | "1.0.0", |
nothing calls this directly
no test coverage detected