Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
@@ -1,198 +1,215 @@
|
|
1 |
---
|
2 |
-
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
4 |
|
5 |
-
|
6 |
|
7 |
-
|
8 |
|
|
|
|
|
|
|
|
|
9 |
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
|
13 |
### Model Description
|
14 |
|
15 |
-
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
|
18 |
|
19 |
-
-
|
20 |
-
-
|
21 |
-
- **Shared by [optional]:** [More Information Needed]
|
22 |
-
- **Model type:** [More Information Needed]
|
23 |
-
- **Language(s) (NLP):** [More Information Needed]
|
24 |
-
- **License:** [More Information Needed]
|
25 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
26 |
|
27 |
-
|
|
|
28 |
|
29 |
-
<!-- Provide the basic links for the model. -->
|
30 |
-
|
31 |
-
- **Repository:** [More Information Needed]
|
32 |
-
- **Paper [optional]:** [More Information Needed]
|
33 |
-
- **Demo [optional]:** [More Information Needed]
|
34 |
-
|
35 |
-
## Uses
|
36 |
-
|
37 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
38 |
-
|
39 |
-
### Direct Use
|
40 |
-
|
41 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
42 |
-
|
43 |
-
[More Information Needed]
|
44 |
-
|
45 |
-
### Downstream Use [optional]
|
46 |
-
|
47 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
48 |
-
|
49 |
-
[More Information Needed]
|
50 |
-
|
51 |
-
### Out-of-Scope Use
|
52 |
-
|
53 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
54 |
-
|
55 |
-
[More Information Needed]
|
56 |
-
|
57 |
-
## Bias, Risks, and Limitations
|
58 |
-
|
59 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
60 |
-
|
61 |
-
[More Information Needed]
|
62 |
-
|
63 |
-
### Recommendations
|
64 |
-
|
65 |
-
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
66 |
-
|
67 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
|
68 |
-
|
69 |
-
## How to Get Started with the Model
|
70 |
-
|
71 |
-
Use the code below to get started with the model.
|
72 |
-
|
73 |
-
[More Information Needed]
|
74 |
-
|
75 |
-
## Training Details
|
76 |
-
|
77 |
-
### Training Data
|
78 |
-
|
79 |
-
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
80 |
-
|
81 |
-
[More Information Needed]
|
82 |
-
|
83 |
-
### Training Procedure
|
84 |
-
|
85 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
86 |
-
|
87 |
-
#### Preprocessing [optional]
|
88 |
-
|
89 |
-
[More Information Needed]
|
90 |
-
|
91 |
-
|
92 |
-
#### Training Hyperparameters
|
93 |
-
|
94 |
-
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
95 |
-
|
96 |
-
#### Speeds, Sizes, Times [optional]
|
97 |
-
|
98 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
99 |
-
|
100 |
-
[More Information Needed]
|
101 |
|
102 |
## Evaluation
|
|
|
|
|
|
|
103 |
|
104 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
105 |
|
106 |
-
###
|
107 |
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
-
|
111 |
|
112 |
-
|
|
|
|
|
113 |
|
114 |
-
|
|
|
115 |
|
116 |
-
|
|
|
117 |
|
118 |
-
|
119 |
|
120 |
-
|
|
|
121 |
|
122 |
-
|
123 |
|
124 |
-
|
|
|
|
|
125 |
|
126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
|
128 |
-
|
|
|
|
|
129 |
|
130 |
-
|
131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
|
|
|
|
|
|
|
|
133 |
|
134 |
-
|
|
|
135 |
|
136 |
-
|
|
|
|
|
|
|
137 |
|
138 |
-
[
|
139 |
|
140 |
-
|
|
|
141 |
|
142 |
-
|
143 |
|
144 |
-
|
145 |
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
- **Compute Region:** [More Information Needed]
|
150 |
-
- **Carbon Emitted:** [More Information Needed]
|
151 |
|
152 |
-
|
153 |
|
154 |
-
|
|
|
|
|
155 |
|
156 |
-
|
|
|
|
|
|
|
|
|
|
|
157 |
|
158 |
-
|
159 |
|
160 |
-
[More Information Needed]
|
161 |
|
162 |
-
####
|
163 |
|
164 |
-
|
165 |
|
166 |
-
|
|
|
|
|
167 |
|
168 |
-
|
169 |
|
170 |
-
|
|
|
|
|
171 |
|
172 |
-
|
|
|
|
|
|
|
|
|
|
|
173 |
|
174 |
-
|
175 |
|
176 |
-
[More Information Needed]
|
177 |
|
178 |
-
|
179 |
|
180 |
-
|
181 |
|
182 |
-
|
183 |
|
184 |
-
|
|
|
|
|
|
|
|
|
185 |
|
186 |
-
|
187 |
|
188 |
-
|
189 |
|
190 |
-
|
191 |
|
192 |
-
##
|
193 |
|
194 |
-
|
195 |
|
196 |
-
|
|
|
|
|
|
|
|
|
197 |
|
198 |
-
|
|
|
|
1 |
---
|
2 |
+
license: openrail++
|
3 |
+
tags:
|
4 |
+
- text-to-image
|
5 |
+
- stable-diffusion
|
6 |
---
|
7 |
+
# SD-XL 1.0-base Model Card
|
8 |
+
![row01](01.png)
|
9 |
|
10 |
+
## Model
|
11 |
|
12 |
+
![pipeline](pipeline.png)
|
13 |
|
14 |
+
[SDXL](https://arxiv.org/abs/2307.01952) consists of an [ensemble of experts](https://arxiv.org/abs/2211.01324) pipeline for latent diffusion:
|
15 |
+
In a first step, the base model is used to generate (noisy) latents,
|
16 |
+
which are then further processed with a refinement model (available here: https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/) specialized for the final denoising steps.
|
17 |
+
Note that the base model can be used as a standalone module.
|
18 |
|
19 |
+
Alternatively, we can use a two-stage pipeline as follows:
|
20 |
+
First, the base model is used to generate latents of the desired output size.
|
21 |
+
In the second step, we use a specialized high-resolution model and apply a technique called SDEdit (https://arxiv.org/abs/2108.01073, also known as "img2img")
|
22 |
+
to the latents generated in the first step, using the same prompt. This technique is slightly slower than the first one, as it requires more function evaluations.
|
23 |
|
24 |
+
Source code is available at https://github.com/Stability-AI/generative-models .
|
25 |
|
26 |
### Model Description
|
27 |
|
28 |
+
- **Developed by:** Stability AI
|
29 |
+
- **Model type:** Diffusion-based text-to-image generative model
|
30 |
+
- **License:** [CreativeML Open RAIL++-M License](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/LICENSE.md)
|
31 |
+
- **Model Description:** This is a model that can be used to generate and modify images based on text prompts. It is a [Latent Diffusion Model](https://arxiv.org/abs/2112.10752) that uses two fixed, pretrained text encoders ([OpenCLIP-ViT/G](https://github.com/mlfoundations/open_clip) and [CLIP-ViT/L](https://github.com/openai/CLIP/tree/main)).
|
32 |
+
- **Resources for more information:** Check out our [GitHub Repository](https://github.com/Stability-AI/generative-models) and the [SDXL report on arXiv](https://arxiv.org/abs/2307.01952).
|
33 |
|
34 |
+
### Model Sources
|
35 |
|
36 |
+
For research purposes, we recommend our `generative-models` Github repository (https://github.com/Stability-AI/generative-models), which implements the most popular diffusion frameworks (both training and inference) and for which new functionalities like distillation will be added over time.
|
37 |
+
[Clipdrop](https://clipdrop.co/stable-diffusion) provides free SDXL inference.
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
+
- **Repository:** https://github.com/Stability-AI/generative-models
|
40 |
+
- **Demo:** https://clipdrop.co/stable-diffusion
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
## Evaluation
|
44 |
+
![comparison](comparison.png)
|
45 |
+
The chart above evaluates user preference for SDXL (with and without refinement) over SDXL 0.9 and Stable Diffusion 1.5 and 2.1.
|
46 |
+
The SDXL base model performs significantly better than the previous variants, and the model combined with the refinement module achieves the best overall performance.
|
47 |
|
|
|
48 |
|
49 |
+
### 🧨 Diffusers
|
50 |
|
51 |
+
Make sure to upgrade diffusers to >= 0.19.0:
|
52 |
+
```
|
53 |
+
pip install diffusers --upgrade
|
54 |
+
```
|
55 |
+
|
56 |
+
In addition make sure to install `transformers`, `safetensors`, `accelerate` as well as the invisible watermark:
|
57 |
+
```
|
58 |
+
pip install invisible_watermark transformers accelerate safetensors
|
59 |
+
```
|
60 |
|
61 |
+
To just use the base model, you can run:
|
62 |
|
63 |
+
```py
|
64 |
+
from diffusers import DiffusionPipeline
|
65 |
+
import torch
|
66 |
|
67 |
+
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
|
68 |
+
pipe.to("cuda")
|
69 |
|
70 |
+
# if using torch < 2.0
|
71 |
+
# pipe.enable_xformers_memory_efficient_attention()
|
72 |
|
73 |
+
prompt = "An astronaut riding a green horse"
|
74 |
|
75 |
+
images = pipe(prompt=prompt).images[0]
|
76 |
+
```
|
77 |
|
78 |
+
To use the whole base + refiner pipeline as an ensemble of experts you can run:
|
79 |
|
80 |
+
```py
|
81 |
+
from diffusers import DiffusionPipeline
|
82 |
+
import torch
|
83 |
|
84 |
+
# load both base & refiner
|
85 |
+
base = DiffusionPipeline.from_pretrained(
|
86 |
+
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
|
87 |
+
)
|
88 |
+
base.to("cuda")
|
89 |
+
refiner = DiffusionPipeline.from_pretrained(
|
90 |
+
"stabilityai/stable-diffusion-xl-refiner-1.0",
|
91 |
+
text_encoder_2=base.text_encoder_2,
|
92 |
+
vae=base.vae,
|
93 |
+
torch_dtype=torch.float16,
|
94 |
+
use_safetensors=True,
|
95 |
+
variant="fp16",
|
96 |
+
)
|
97 |
+
refiner.to("cuda")
|
98 |
|
99 |
+
# Define how many steps and what % of steps to be run on each experts (80/20) here
|
100 |
+
n_steps = 40
|
101 |
+
high_noise_frac = 0.8
|
102 |
|
103 |
+
prompt = "A majestic lion jumping from a big stone at night"
|
104 |
|
105 |
+
# run both experts
|
106 |
+
image = base(
|
107 |
+
prompt=prompt,
|
108 |
+
num_inference_steps=n_steps,
|
109 |
+
denoising_end=high_noise_frac,
|
110 |
+
output_type="latent",
|
111 |
+
).images
|
112 |
+
image = refiner(
|
113 |
+
prompt=prompt,
|
114 |
+
num_inference_steps=n_steps,
|
115 |
+
denoising_start=high_noise_frac,
|
116 |
+
image=image,
|
117 |
+
).images[0]
|
118 |
+
```
|
119 |
|
120 |
+
When using `torch >= 2.0`, you can improve the inference speed by 20-30% with torch.compile. Simple wrap the unet with torch compile before running the pipeline:
|
121 |
+
```py
|
122 |
+
pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
|
123 |
+
```
|
124 |
|
125 |
+
If you are limited by GPU VRAM, you can enable *cpu offloading* by calling `pipe.enable_model_cpu_offload`
|
126 |
+
instead of `.to("cuda")`:
|
127 |
|
128 |
+
```diff
|
129 |
+
- pipe.to("cuda")
|
130 |
+
+ pipe.enable_model_cpu_offload()
|
131 |
+
```
|
132 |
|
133 |
+
For more information on how to use Stable Diffusion XL with `diffusers`, please have a look at [the Stable Diffusion XL Docs](https://huggingface.co/docs/diffusers/api/pipelines/stable_diffusion/stable_diffusion_xl).
|
134 |
|
135 |
+
### Optimum
|
136 |
+
[Optimum](https://github.com/huggingface/optimum) provides a Stable Diffusion pipeline compatible with both [OpenVINO](https://docs.openvino.ai/latest/index.html) and [ONNX Runtime](https://onnxruntime.ai/).
|
137 |
|
138 |
+
#### OpenVINO
|
139 |
|
140 |
+
To install Optimum with the dependencies required for OpenVINO :
|
141 |
|
142 |
+
```bash
|
143 |
+
pip install optimum[openvino]
|
144 |
+
```
|
|
|
|
|
145 |
|
146 |
+
To load an OpenVINO model and run inference with OpenVINO Runtime, you need to replace `StableDiffusionXLPipeline` with Optimum `OVStableDiffusionXLPipeline`. In case you want to load a PyTorch model and convert it to the OpenVINO format on-the-fly, you can set `export=True`.
|
147 |
|
148 |
+
```diff
|
149 |
+
- from diffusers import StableDiffusionXLPipeline
|
150 |
+
+ from optimum.intel import OVStableDiffusionXLPipeline
|
151 |
|
152 |
+
model_id = "stabilityai/stable-diffusion-xl-base-1.0"
|
153 |
+
- pipeline = StableDiffusionXLPipeline.from_pretrained(model_id)
|
154 |
+
+ pipeline = OVStableDiffusionXLPipeline.from_pretrained(model_id)
|
155 |
+
prompt = "A majestic lion jumping from a big stone at night"
|
156 |
+
image = pipeline(prompt).images[0]
|
157 |
+
```
|
158 |
|
159 |
+
You can find more examples (such as static reshaping and model compilation) in optimum [documentation](https://huggingface.co/docs/optimum/main/en/intel/inference#stable-diffusion-xl).
|
160 |
|
|
|
161 |
|
162 |
+
#### ONNX
|
163 |
|
164 |
+
To install Optimum with the dependencies required for ONNX Runtime inference :
|
165 |
|
166 |
+
```bash
|
167 |
+
pip install optimum[onnxruntime]
|
168 |
+
```
|
169 |
|
170 |
+
To load an ONNX model and run inference with ONNX Runtime, you need to replace `StableDiffusionXLPipeline` with Optimum `ORTStableDiffusionXLPipeline`. In case you want to load a PyTorch model and convert it to the ONNX format on-the-fly, you can set `export=True`.
|
171 |
|
172 |
+
```diff
|
173 |
+
- from diffusers import StableDiffusionXLPipeline
|
174 |
+
+ from optimum.onnxruntime import ORTStableDiffusionXLPipeline
|
175 |
|
176 |
+
model_id = "stabilityai/stable-diffusion-xl-base-1.0"
|
177 |
+
- pipeline = StableDiffusionXLPipeline.from_pretrained(model_id)
|
178 |
+
+ pipeline = ORTStableDiffusionXLPipeline.from_pretrained(model_id)
|
179 |
+
prompt = "A majestic lion jumping from a big stone at night"
|
180 |
+
image = pipeline(prompt).images[0]
|
181 |
+
```
|
182 |
|
183 |
+
You can find more examples in optimum [documentation](https://huggingface.co/docs/optimum/main/en/onnxruntime/usage_guides/models#stable-diffusion-xl).
|
184 |
|
|
|
185 |
|
186 |
+
## Uses
|
187 |
|
188 |
+
### Direct Use
|
189 |
|
190 |
+
The model is intended for research purposes only. Possible research areas and tasks include
|
191 |
|
192 |
+
- Generation of artworks and use in design and other artistic processes.
|
193 |
+
- Applications in educational or creative tools.
|
194 |
+
- Research on generative models.
|
195 |
+
- Safe deployment of models which have the potential to generate harmful content.
|
196 |
+
- Probing and understanding the limitations and biases of generative models.
|
197 |
|
198 |
+
Excluded uses are described below.
|
199 |
|
200 |
+
### Out-of-Scope Use
|
201 |
|
202 |
+
The model was not trained to be factual or true representations of people or events, and therefore using the model to generate such content is out-of-scope for the abilities of this model.
|
203 |
|
204 |
+
## Limitations and Bias
|
205 |
|
206 |
+
### Limitations
|
207 |
|
208 |
+
- The model does not achieve perfect photorealism
|
209 |
+
- The model cannot render legible text
|
210 |
+
- The model struggles with more difficult tasks which involve compositionality, such as rendering an image corresponding to “A red cube on top of a blue sphere”
|
211 |
+
- Faces and people in general may not be generated properly.
|
212 |
+
- The autoencoding part of the model is lossy.
|
213 |
|
214 |
+
### Bias
|
215 |
+
While the capabilities of image generation models are impressive, they can also reinforce or exacerbate social biases.
|