Skip to content

Commit 19f3161

Browse files
sayakpaulstevhliu
andauthored
[Docs] improve the LoRA doc. (#4838)
* improve the LoRA doc. * include fuse_lora and unfuse_lora * Apply suggestions from code review Co-authored-by: Steven Liu <[email protected]> --------- Co-authored-by: Steven Liu <[email protected]>
1 parent a1fdfca commit 19f3161

File tree

1 file changed

+53
-14
lines changed

1 file changed

+53
-14
lines changed

docs/source/en/training/lora.md

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -276,20 +276,40 @@ Note that the use of [`~diffusers.loaders.LoraLoaderMixin.load_lora_weights`] is
276276

277277
* LoRA parameters that have separate identifiers for the UNet and the text encoder such as: [`"sayakpaul/dreambooth"`](https://huggingface.co/sayakpaul/dreambooth).
278278

279-
**Note** that it is possible to provide a local directory path to [`~diffusers.loaders.LoraLoaderMixin.load_lora_weights`] as well as [`~diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs`]. To know about the supported inputs,
280-
refer to the respective docstrings.
279+
<Tip>
280+
281+
You can also provide a local directory path to [`~diffusers.loaders.LoraLoaderMixin.load_lora_weights`] as well as [`~diffusers.loaders.UNet2DConditionLoadersMixin.load_attn_procs`].
282+
283+
</Tip>
284+
285+
## Stable Diffusion XL
286+
287+
We support fine-tuning with [Stable Diffusion XL](https://huggingface.co/papers/2307.01952). Please refer to the following docs:
288+
289+
* [text_to_image/README_sdxl.md](https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/README_sdxl.md)
290+
* [dreambooth/README_sdxl.md](https://github.com/huggingface/diffusers/blob/main/examples/dreambooth/README_sdxl.md)
281291

282292
## Unloading LoRA parameters
283293

284294
You can call [`~diffusers.loaders.LoraLoaderMixin.unload_lora_weights`] on a pipeline to unload the LoRA parameters.
285295

286-
## Supporting A1111 themed LoRA checkpoints from Diffusers
296+
## Fusing LoRA parameters
297+
298+
You can call [`~diffusers.loaders.LoraLoaderMixin.fuse_lora`] on a pipeline to merge the LoRA parameters with the original parameters of the underlying model(s). This can lead to a potential speedup in the inference latency.
299+
300+
## Unfusing LoRA parameters
301+
302+
To undo `fuse_lora`, call [`~diffusers.loaders.LoraLoaderMixin.unfuse_lora`] on a pipeline.
303+
304+
## Supporting different LoRA checkpoints from Diffusers
305+
306+
🤗 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.
307+
308+
### Kohya
287309

288-
This support was made possible because of our amazing contributors: [@takuma104](https://github.com/takuma104) and [@isidentical](https://github.com/isidentical).
310+
This support was made possible because of the amazing contributors: [@takuma104](https://github.com/takuma104) and [@isidentical](https://github.com/isidentical).
289311

290-
To provide seamless interoperability with A1111 to our users, we support loading A1111 formatted
291-
LoRA checkpoints using [`~diffusers.loaders.LoraLoaderMixin.load_lora_weights`] in a limited capacity.
292-
In this section, we explain how to load an A1111 formatted LoRA checkpoint from [CivitAI](https://civitai.com/)
312+
We support loading Kohya LoRA checkpoints using [`~diffusers.loaders.LoraLoaderMixin.load_lora_weights`]. In this section, we explain how to load such a checkpoint from [CivitAI](https://civitai.com/)
293313
in Diffusers and perform inference with it.
294314

295315
First, download a checkpoint. We'll use
@@ -356,9 +376,9 @@ lora_filename = "light_and_shadow.safetensors"
356376
pipeline.load_lora_weights(lora_model_id, weight_name=lora_filename)
357377
```
358378

359-
### Supporting Stable Diffusion XL LoRAs trained using the Kohya-trainer
379+
### Kohya + Stable Diffusion XL
360380

361-
With this [PR](https://github.com/huggingface/diffusers/pull/4287), there should now be better support for loading Kohya-style LoRAs trained on Stable Diffusion XL (SDXL).
381+
After the release of [Stable Diffusion XL](https://huggingface.co/papers/2307.01952), the community contributed some amazing LoRA checkpoints trained on top of it with the Kohya trainer.
362382

363383
Here are some example checkpoints we tried out:
364384

@@ -399,14 +419,33 @@ If you notice carefully, the inference UX is exactly identical to what we presen
399419

400420
Thanks to [@isidentical](https://github.com/isidentical) for helping us on integrating this feature.
401421

402-
### Known limitations specific to the Kohya-styled LoRAs
422+
<Tip warning={true}>
423+
424+
**Known limitations specific to the Kohya LoRAs**:
403425

404426
* When images don't looks similar to other UIs, such as ComfyUI, it can be because of multiple reasons, as explained [here](https://github.com/huggingface/diffusers/pull/4287/#issuecomment-1655110736).
405427
* We don't fully support [LyCORIS checkpoints](https://github.com/KohakuBlueleaf/LyCORIS). To the best of our knowledge, our current `load_lora_weights()` should support LyCORIS checkpoints that have LoRA and LoCon modules but not the other ones, such as Hada, LoKR, etc.
406428

407-
## Stable Diffusion XL
429+
</Tip>
408430

409-
We support fine-tuning with [Stable Diffusion XL](https://huggingface.co/papers/2307.01952). Please refer to the following docs:
431+
### TheLastBen
410432

411-
* [text_to_image/README_sdxl.md](https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/README_sdxl.md)
412-
* [dreambooth/README_sdxl.md](https://github.com/huggingface/diffusers/blob/main/examples/dreambooth/README_sdxl.md)
433+
Here is an example:
434+
435+
```python
436+
from diffusers import DiffusionPipeline
437+
import torch
438+
439+
pipeline_id = "Lykon/dreamshaper-xl-1-0"
440+
441+
pipe = DiffusionPipeline.from_pretrained(pipeline_id, torch_dtype=torch.float16)
442+
pipe.enable_model_cpu_offload()
443+
444+
lora_model_id = "TheLastBen/Papercut_SDXL"
445+
lora_filename = "papercut.safetensors"
446+
pipe.load_lora_weights(lora_model_id, weight_name=lora_filename)
447+
448+
prompt = "papercut sonic"
449+
image = pipe(prompt=prompt, num_inference_steps=20, generator=torch.manual_seed(0)).images[0]
450+
image
451+
```

0 commit comments

Comments
 (0)