David Burnett
commited on
Commit
•
debbdf6
1
Parent(s):
afea186
add unet from LCM SDXL
Browse files- unet/README.md +75 -0
- unet/config.json +73 -0
- unet/diffusion_pytorch_model.fp16.safetensors +3 -0
- unet/diffusion_pytorch_model.safetensors +3 -0
- unet/image.png +3 -0
unet/README.md
ADDED
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
library_name: diffusers
|
3 |
+
base_model: stabilityai/stable-diffusion-xl-base-1.0
|
4 |
+
tags:
|
5 |
+
- text-to-image
|
6 |
+
license: openrail++
|
7 |
+
inference: false
|
8 |
+
---
|
9 |
+
|
10 |
+
# Latent Consistency Model (LCM): SDXL
|
11 |
+
|
12 |
+
Latent Consistency Model (LCM) was proposed in [Latent Consistency Models: Synthesizing High-Resolution Images with Few-Step Inference](https://arxiv.org/abs/2310.04378)
|
13 |
+
by *Simian Luo, Yiqin Tan et al.* and [Simian Luo](https://huggingface.co/SimianLuo), [Suraj Patil](https://huggingface.co/valhalla), and [Daniel Gu](https://huggingface.co/dg845)
|
14 |
+
succesfully applied the same approach to create LCM for SDXL.
|
15 |
+
|
16 |
+
This checkpoint is a LCM distilled version of [`stable-diffusion-xl-base-1.0`](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0) that allows
|
17 |
+
to reduce the number of inference steps to only between **2 - 8 steps**.
|
18 |
+
|
19 |
+
|
20 |
+
## Usage
|
21 |
+
|
22 |
+
LCM SDXL is supported in 🤗 Hugging Face Diffusers library from version v0.23.0 onwards. To run the model, first
|
23 |
+
install the latest version of the Diffusers library as well as `peft`, `accelerate` and `transformers`.
|
24 |
+
audio dataset from the Hugging Face Hub:
|
25 |
+
|
26 |
+
```bash
|
27 |
+
pip install --upgrade pip
|
28 |
+
pip install --upgrade diffusers transformers accelerate peft
|
29 |
+
```
|
30 |
+
|
31 |
+
### Text-to-Image
|
32 |
+
|
33 |
+
The model can be loaded with it's base pipeline `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.
|
34 |
+
Please make sure to either disable `guidance_scale` or use values between 1.0 and 2.0.
|
35 |
+
|
36 |
+
```python
|
37 |
+
from diffusers import UNet2DConditionModel, DiffusionPipeline, LCMScheduler
|
38 |
+
import torch
|
39 |
+
|
40 |
+
unet = UNet2DConditionModel.from_pretrained("latent-consistency/lcm-sdxl", torch_dtype=torch.float16, variant="fp16")
|
41 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", unet=unet, torch_dtype=torch.float16, variant="fp16")
|
42 |
+
|
43 |
+
pipe.scheduler = LCMScheduler.from_config(sd_pipe.scheduler.config)
|
44 |
+
pipe.to("cuda")
|
45 |
+
|
46 |
+
prompt = "a close-up picture of an old man standing in the rain"
|
47 |
+
|
48 |
+
image = pipe(prompt, num_inference_steps=4, guidance_scale=8.0).images[0]
|
49 |
+
```
|
50 |
+
|
51 |
+
![](./image.png)
|
52 |
+
|
53 |
+
### Image-to-Image
|
54 |
+
|
55 |
+
Works as well! TODO docs
|
56 |
+
|
57 |
+
### Inpainting
|
58 |
+
|
59 |
+
Works as well! TODO docs
|
60 |
+
|
61 |
+
### ControlNet
|
62 |
+
|
63 |
+
Works as well! TODO docs
|
64 |
+
|
65 |
+
### T2I Adapter
|
66 |
+
|
67 |
+
Works as well! TODO docs
|
68 |
+
|
69 |
+
## Speed Benchmark
|
70 |
+
|
71 |
+
TODO
|
72 |
+
|
73 |
+
## Training
|
74 |
+
|
75 |
+
TODO
|
unet/config.json
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_class_name": "UNet2DConditionModel",
|
3 |
+
"_diffusers_version": "0.23.0.dev0",
|
4 |
+
"_name_or_path": "/home/patrick/lcm-sdxl-base-1.0",
|
5 |
+
"act_fn": "silu",
|
6 |
+
"addition_embed_type": "text_time",
|
7 |
+
"addition_embed_type_num_heads": 64,
|
8 |
+
"addition_time_embed_dim": 256,
|
9 |
+
"attention_head_dim": [
|
10 |
+
5,
|
11 |
+
10,
|
12 |
+
20
|
13 |
+
],
|
14 |
+
"attention_type": "default",
|
15 |
+
"block_out_channels": [
|
16 |
+
320,
|
17 |
+
640,
|
18 |
+
1280
|
19 |
+
],
|
20 |
+
"center_input_sample": false,
|
21 |
+
"class_embed_type": null,
|
22 |
+
"class_embeddings_concat": false,
|
23 |
+
"conv_in_kernel": 3,
|
24 |
+
"conv_out_kernel": 3,
|
25 |
+
"cross_attention_dim": 2048,
|
26 |
+
"cross_attention_norm": null,
|
27 |
+
"down_block_types": [
|
28 |
+
"DownBlock2D",
|
29 |
+
"CrossAttnDownBlock2D",
|
30 |
+
"CrossAttnDownBlock2D"
|
31 |
+
],
|
32 |
+
"downsample_padding": 1,
|
33 |
+
"dropout": 0.0,
|
34 |
+
"dual_cross_attention": false,
|
35 |
+
"encoder_hid_dim": null,
|
36 |
+
"encoder_hid_dim_type": null,
|
37 |
+
"flip_sin_to_cos": true,
|
38 |
+
"freq_shift": 0,
|
39 |
+
"in_channels": 4,
|
40 |
+
"layers_per_block": 2,
|
41 |
+
"mid_block_only_cross_attention": null,
|
42 |
+
"mid_block_scale_factor": 1,
|
43 |
+
"mid_block_type": "UNetMidBlock2DCrossAttn",
|
44 |
+
"norm_eps": 1e-05,
|
45 |
+
"norm_num_groups": 32,
|
46 |
+
"num_attention_heads": null,
|
47 |
+
"num_class_embeds": null,
|
48 |
+
"only_cross_attention": false,
|
49 |
+
"out_channels": 4,
|
50 |
+
"projection_class_embeddings_input_dim": 2816,
|
51 |
+
"resnet_out_scale_factor": 1.0,
|
52 |
+
"resnet_skip_time_act": false,
|
53 |
+
"resnet_time_scale_shift": "default",
|
54 |
+
"reverse_transformer_layers_per_block": null,
|
55 |
+
"sample_size": 128,
|
56 |
+
"time_cond_proj_dim": 256,
|
57 |
+
"time_embedding_act_fn": null,
|
58 |
+
"time_embedding_dim": null,
|
59 |
+
"time_embedding_type": "positional",
|
60 |
+
"timestep_post_act": null,
|
61 |
+
"transformer_layers_per_block": [
|
62 |
+
1,
|
63 |
+
2,
|
64 |
+
10
|
65 |
+
],
|
66 |
+
"up_block_types": [
|
67 |
+
"CrossAttnUpBlock2D",
|
68 |
+
"CrossAttnUpBlock2D",
|
69 |
+
"UpBlock2D"
|
70 |
+
],
|
71 |
+
"upcast_attention": null,
|
72 |
+
"use_linear_projection": true
|
73 |
+
}
|
unet/diffusion_pytorch_model.fp16.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:e906040f7a2f484cf6c4fcef93bfa3cead8c245a87d02c825a1554bad9c7204a
|
3 |
+
size 5135313712
|
unet/diffusion_pytorch_model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dce0636b11d99c1d960608bb6fa71923f1ae2365b89a38b49e1a0193a0fc1c43
|
3 |
+
size 10270405520
|
unet/image.png
ADDED
Git LFS Details
|