Skip to content

Commit bfc6063

Browse files
add doc around fusing multiple loras. (huggingface#5056)
* add doc around fusing multiple loras. * Apply suggestions from code review Co-authored-by: apolinário <[email protected]> * address poli's comments. --------- Co-authored-by: apolinário <[email protected]>
1 parent 6886e28 commit bfc6063

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

docs/source/en/training/lora.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,56 @@ images_fusion = pipe(
378378
).images
379379
```
380380

381+
## Working with multiple LoRA checkpoints
382+
383+
With the `fuse_lora()` method as described above, it's possible to load multiple LoRA checkpoints. Let's work through a complete example. First we load the base pipeline:
384+
385+
```python
386+
from diffusers import StableDiffusionXLPipeline, AutoencoderKL
387+
import torch
388+
389+
vae = AutoencoderKL.from_pretrained("madebyollin/sdxl-vae-fp16-fix", torch_dtype=torch.float16)
390+
pipe = StableDiffusionXLPipeline.from_pretrained(
391+
"stabilityai/stable-diffusion-xl-base-1.0",
392+
vae=vae,
393+
torch_dtype=torch.float16,
394+
)
395+
pipe.to("cuda")
396+
```
397+
398+
Then let's two LoRA checkpoints and fuse them with specific `lora_scale` values:
399+
400+
```python
401+
# LoRA one.
402+
pipe.load_lora_weights("goofyai/cyborg_style_xl")
403+
pipe.fuse_lora(lora_scale=0.7)
404+
405+
# LoRA two.
406+
pipe.load_lora_weights("TheLastBen/Pikachu_SDXL")
407+
pipe.fuse_lora(lora_scale=0.7)
408+
```
409+
410+
<Tip>
411+
412+
Play with the `lora_scale` parameter when working with multiple LoRAs to control the amount of their influence on the final outputs.
413+
414+
</Tip>
415+
416+
Let's see them in action:
417+
418+
```python
419+
prompt = "cyborg style pikachu"
420+
image = pipe(prompt, num_inference_steps=30, guidance_scale=7.5).images[0]
421+
```
422+
423+
![cyborg_pikachu](https://huggingface.co/datasets/diffusers/docs-images/resolve/main/cyborg_pikachu.png)
424+
425+
<Tip warning={true}>
426+
427+
Currently, unfusing multiple LoRA checkpoints is not possible.
428+
429+
</Tip>
430+
381431
## Supporting different LoRA checkpoints from Diffusers
382432

383433
🤗 Diffusers supports loading checkpoints from popular LoRA trainers such as [Kohya](https://github.com/kohya-ss/sd-scripts/) and [TheLastBen](https://github.com/TheLastBen/fast-stable-diffusion). In this section, we outline the current API's details and limitations.

0 commit comments

Comments
 (0)