patrickvonplaten
commited on
Commit
·
b7cca8c
1
Parent(s):
23c96ee
add
Browse files
README.md
CHANGED
@@ -1,28 +1,80 @@
|
|
1 |
---
|
2 |
-
library_name:
|
|
|
3 |
tags:
|
4 |
- lora
|
|
|
|
|
5 |
---
|
6 |
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
import torch
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
pipe =
|
12 |
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
|
|
|
13 |
|
14 |
# load and fuse lcm lora
|
15 |
-
pipe.load_lora_weights(
|
16 |
pipe.fuse_lora()
|
17 |
|
18 |
-
# NOTE, you can also optionally load other LoRAs into the model
|
19 |
-
pipe.load_lora_weights("TheLastBen/Papercut_SDXL")
|
20 |
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
# set `guidance_scale=1.0` to disable CFG
|
27 |
-
image = pipe(prompt=prompt, num_inference_steps=4, guidance_scale=1.0).images[0]
|
28 |
-
```
|
|
|
1 |
---
|
2 |
+
library_name: diffusers
|
3 |
+
base_model: stabilityai/stable-diffusion-xl-base-1.0
|
4 |
tags:
|
5 |
- lora
|
6 |
+
- text-to-image
|
7 |
+
license: openrail++
|
8 |
---
|
9 |
|
10 |
+
# Latent Consistency Model (LCM) LoRA: SDXL
|
11 |
+
|
12 |
+
Latent Consistency Model (LCM) LoRA was proposed in [LCM-LoRA: A universal Stable-Diffusion Acceleration Module](TODO:)
|
13 |
+
by *Simian Luo, Yiqin Tan, Suraj Patil, Daniel Gu et al.*
|
14 |
+
|
15 |
+
It is a distilled consistency adapter for [`stable-diffusion-xl-base-1.0`](stabilityai/stable-diffusion-xl-base-1.0) that allows
|
16 |
+
to reduce the number of inference steps to only between **2 - 8 steps**.
|
17 |
+
|
18 |
+
| Model | Params / M |
|
19 |
+
|----------------------------------------------------------------------------|------------|
|
20 |
+
| [lcm-lora-sdv1-5](https://huggingface.co/latent-consistency/lcm-lora-sdv1-5) | 67.5 |
|
21 |
+
| [lcm-lora-ssd-1b](https://huggingface.co/latent-consistency/lcm-lora-ssd-1b) | 105 |
|
22 |
+
| [**lcm-lora-sdxl**](https://huggingface.co/latent-consistency/lcm-lora-sdxl) | **197M** |
|
23 |
+
|
24 |
+
## Usage
|
25 |
+
|
26 |
+
LCM-LoRA is supported in 🤗 Hugging Face Diffusers library from version v0.23.0 onwards. To run the model, first
|
27 |
+
install the latest version of the Diffusers library as well as `peft`, `accelerate` and `transformers`.
|
28 |
+
audio dataset from the Hugging Face Hub:
|
29 |
+
|
30 |
+
```bash
|
31 |
+
pip install --upgrade pip
|
32 |
+
pip install --upgrade diffusers transformers accelerate peft
|
33 |
+
```
|
34 |
+
|
35 |
+
### Text-to-Image
|
36 |
+
|
37 |
+
The adapter can be loaded with it's base model `stabilityai/stable-diffusion-xl-base-1.0`. Next, the scheduler needs to be changed to [`LCMScheduler`](https://huggingface.co/docs/diffusers/v0.22.3/en/api/schedulers/lcm#diffusers.LCMScheduler) and we can reduce the number of inference steps to just 2 to 8 steps.
|
38 |
+
Please make sure to either disable `guidance_scale` or use values between 1.0 and 2.0.
|
39 |
+
|
40 |
+
```python
|
41 |
import torch
|
42 |
+
from diffusers import LCMScheduler, AutoPipelineForText2Image
|
43 |
+
|
44 |
+
model_id = "stabilityai/stable-diffusion-xl-base-1.0"
|
45 |
+
adapter_id = "latent-consistency/lcm-lora-sdxl"
|
46 |
|
47 |
+
pipe = AutoPipelineForText2Image.from_pretrained(model_id, torch_dtype=torch.float16, variant="fp16")
|
48 |
pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
|
49 |
+
pipe.to("cuda")
|
50 |
|
51 |
# load and fuse lcm lora
|
52 |
+
pipe.load_lora_weights(adapter_id)
|
53 |
pipe.fuse_lora()
|
54 |
|
|
|
|
|
55 |
|
56 |
+
prompt = "Self-portrait oil painting, a beautiful cyborg with golden hair, 8k"
|
57 |
+
|
58 |
+
# disable guidance_scale by passing 0
|
59 |
+
image = pipe(prompt=prompt, num_inference_steps=4, guidance_scale=0).images[0]
|
60 |
+
```
|
61 |
+
|
62 |
+
### Image-to-Image
|
63 |
+
|
64 |
+
Works as well! TODO docs
|
65 |
+
|
66 |
+
### Inpainting
|
67 |
+
|
68 |
+
Works as well! TODO docs
|
69 |
+
|
70 |
+
### ControlNet
|
71 |
+
|
72 |
+
Works as well! TODO docs
|
73 |
+
|
74 |
+
### T2I Adapter
|
75 |
+
|
76 |
+
Works as well! TODO docs
|
77 |
|
78 |
+
## Training
|
79 |
|
80 |
+
TODO
|
|
|
|
|
|