renyuxi commited on
Commit
ed14162
1 Parent(s): ddce910

update readme

Browse files
Files changed (1) hide show
  1. README.md +146 -0
README.md CHANGED
@@ -1,3 +1,149 @@
1
  ---
2
  license: openrail++
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: openrail++
3
+ library_name: diffusers
4
+ tags:
5
+ - lora
6
+ - text-to-image
7
+ - stable-diffusion
8
  ---
9
+
10
+ # Hyper-SD
11
+ Official Repository of the paper: *[Hyper-SD](https://arxiv.org/abs/2310.04378)*.
12
+
13
+ Project Page: https://hyper-sd.github.io/
14
+
15
+ ![](./hypersd_tearser.jpg)
16
+
17
+ ## Try our Hugging Face demos:
18
+ AI-Doole demo host on [🤗 space]()
19
+
20
+ One-step Text-to-Image demo host on [🤗 T2I]()
21
+
22
+ ## Introduction
23
+
24
+ Hyper-SD is one of the new State-of-the-Art diffusion model acceleration technique.
25
+ In this repository, we release the models distilled from [SDXL Base 1.0](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0) and [Stable-Diffusion v1-5](https://huggingface.co/runwayml/stable-diffusion-v1-5)。
26
+
27
+ ## Checkpoints
28
+
29
+ * `Hyper-SDXL-Nstep-lora.safetensors`: Lora checkpoint, for SDXL-related models.
30
+ * `Hyper-SD15-Nstep-lora.safetensors`: Lora checkpoint, for SD1.5-related models.
31
+ * `Hyper-SDXL-1step-unet.safetensors`: Unet checkpoint distilled from SDXL-Base.
32
+
33
+ ## SDXL-related models Usage
34
+
35
+ ### 2-Steps, 4-Steps, 8-steps LoRA
36
+ ```python
37
+ import torch
38
+ from diffusers import DiffusionPipeline, DDIMScheduler
39
+ from huggingface_hub import hf_hub_download
40
+ base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
41
+ repo_name = "ByteDance/Hyper-SD"
42
+ # Take 2-steps lora as an example
43
+ ckpt_name = "Hyper-SDXL-2steps-lora.safetensors"
44
+ # Load model.
45
+ pipe = DiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16, variant="fp16").to("cuda")
46
+ pipe.load_lora_weights(hf_hub_download(repo_name, ckpt_name))
47
+ pipe.fuse_lora()
48
+ # Ensure ddim scheduler timestep spacing set as trailing
49
+ pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
50
+ # lower eta results in more detail
51
+ prompt="a photo of a cat"
52
+ image=pipe(prompt=prompt, num_inference_steps=2, guidance_scale=0).images[0]
53
+ ```
54
+
55
+ ### Unified LoRA
56
+ ```python
57
+ import torch
58
+ from diffusers import DiffusionPipeline, TCDScheduler
59
+ from huggingface_hub import hf_hub_download
60
+ base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
61
+ repo_name = "ByteDance/Hyper-SD"
62
+ ckpt_name = "Hyper-SDXL-1step-lora.safetensors"
63
+ # Load model.
64
+ pipe = DiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16, variant="fp16").to("cuda")
65
+ pipe.load_lora_weights(hf_hub_download(repo_name, ckpt_name))
66
+ pipe.fuse_lora()
67
+ # Use TCD scheduler to achieve better image quality
68
+ pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
69
+ # lower eta results in more detail
70
+ eta=1.0
71
+ prompt="a photo of a cat"
72
+ image=pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0, eta=eta).images[0]
73
+ ```
74
+
75
+
76
+ ### 1-step SDXL Unet
77
+
78
+ ```python
79
+ import torch
80
+ from diffusers import DiffusionPipeline, UNet2DConditionModel, LCMScheduler
81
+ from huggingface_hub import hf_hub_download
82
+ from safetensors.torch import load_file
83
+ base_model_id = "stabilityai/stable-diffusion-xl-base-1.0"
84
+ repo_name = "ByteDance/Hyper-SD"
85
+ ckpt_name = "Hyper-SDXL-1step-Unet.safetensors"
86
+ # Load model.
87
+ unet = UNet2DConditionModel.from_config(base_model_id, subfolder="unet").to("cuda", torch.float16)
88
+ unet.load_state_dict(load_file(hf_hub_download(repo_name, ckpt_name), device="cuda"))
89
+ pipe = DiffusionPipeline.from_pretrained(base_model_id, unet=unet, torch_dtype=torch.float16, variant="fp16").to("cuda")
90
+ # Use LCM scheduler instead of ddim scheduler to support specific timestep number inputs
91
+ pipe.scheduler = LCMScheduler.from_config(pipe.scheduler.config)
92
+ # Set start timesteps to 800 in the one-step inference to get better results
93
+ prompt="a photo of a cat"
94
+ image=pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0, timesteps=[800]).images[0]
95
+ ```
96
+
97
+
98
+
99
+ ## SD1.5-related models Usage
100
+
101
+ ### 2-Steps, 4-Steps, 8-steps LoRA
102
+ ```python
103
+ import torch
104
+ from diffusers import DiffusionPipeline, DDIMScheduler
105
+ from huggingface_hub import hf_hub_download
106
+ base_model_id = "stabilityai/stable-diffusion-v1-5"
107
+ repo_name = "ByteDance/Hyper-SD"
108
+ # Take 2-steps lora as an example
109
+ ckpt_name = "Hyper-SD15-2steps-lora.safetensors"
110
+ # Load model.
111
+ pipe = DiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16, variant="fp16").to("cuda")
112
+ pipe.load_lora_weights(hf_hub_download(repo_name, ckpt_name))
113
+ pipe.fuse_lora()
114
+ # Ensure ddim scheduler timestep spacing set as trailing
115
+ pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config, timestep_spacing="trailing")
116
+ prompt="a photo of a cat"
117
+ image=pipe(prompt=prompt, num_inference_steps=2, guidance_scale=0).images[0]
118
+ ```
119
+
120
+
121
+ ### Unified LoRA
122
+ ```python
123
+ import torch
124
+ from diffusers import DiffusionPipeline, TCDScheduler
125
+ from huggingface_hub import hf_hub_download
126
+ base_model_id = "stabilityai/stable-diffusion-v1-5"
127
+ repo_name = "ByteDance/Hyper-SD"
128
+ ckpt_name = "Hyper-SD15-1step-lora.safetensors"
129
+ # Load model.
130
+ pipe = DiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16, variant="fp16").to("cuda")
131
+ pipe.load_lora_weights(hf_hub_download(repo_name, ckpt_name))
132
+ pipe.fuse_lora()
133
+ # Use TCD scheduler to achieve better image quality
134
+ pipe.scheduler = TCDScheduler.from_config(pipe.scheduler.config)
135
+ # Lower eta results in more detail
136
+ eta=1.0
137
+ prompt="a photo of a cat"
138
+ image=pipe(prompt=prompt, num_inference_steps=1, guidance_scale=0, eta=eta).images[0]
139
+ ```
140
+
141
+ ## Citation
142
+ ```bibtex
143
+ @article{ren2024hypersd,
144
+ title={Hyper-SD: Trajectory Segmented Consistency Model for Efficient Image Synthesis},
145
+ author={Ren Yuxi, Xia Xin, Lu Yanzuo, Jiacheng, Wu Jie, Xie Pan, Wang Xin, Xiao Xuefeng},
146
+ year={2024},
147
+ journal={arXiv:2404.03407},
148
+ }
149
+ ```