Text-to-Image
Diffusers
stable-diffusion
jrjyc1 commited on
Commit
1ba9789
·
1 Parent(s): 56412d0

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +155 -134
README.md CHANGED
@@ -1,5 +1,4 @@
1
- ---
2
- license: openrail
3
  datasets:
4
  - ProGamerGov/StableDiffusion-v1-5-Regularization-Images
5
  - dnlpy/Stable-Diffusion
@@ -19,196 +18,218 @@ tags:
19
  language:
20
  - aa
21
  ---
22
- # Model Card for Model ID
23
-
24
- <!-- Provide a quick summary of what the model is/does. -->
25
-
26
- This modelcard aims to be a base template for new models. It has been generated using [this raw template](https://github.com/huggingface/huggingface_hub/blob/main/src/huggingface_hub/templates/modelcard_template.md?plain=1).
27
-
28
- ## Model Details
29
-
30
- ### Model Description
31
-
32
- <!-- Provide a longer summary of what this model is. -->
33
-
34
-
35
-
36
- - **Developed by:** [More Information Needed]
37
- - **Shared by [optional]:** [More Information Needed]
38
- - **Model type:** StableDiffusion-v1-5-Regularization-Images
39
- - **Language(s) (NLP):** [More Information Needed]
40
- - **License:** open rail
41
- - **Finetuned from model [optional]:** [More Information Needed]
42
-
43
- ### Model Sources [optional]
44
-
45
- <!-- Provide the basic links for the model. -->
46
-
47
- - **Repository:** [More Information Needed]
48
- - **Paper [optional]:** [More Information Needed]
49
- - **Demo [optional]:** [More Information Needed]
50
-
51
- ## Uses
52
-
53
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
54
-
55
- ### Direct Use
56
-
57
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
58
-
59
- [More Information Needed]
60
-
61
- ### Downstream Use [optional]
62
-
63
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
64
 
65
- [More Information Needed]
66
-
67
- ### Out-of-Scope Use
68
-
69
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
70
-
71
- [More Information Needed]
72
-
73
- ## Bias, Risks, and Limitations
74
-
75
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
76
-
77
- [More Information Needed]
78
-
79
- ### Recommendations
80
-
81
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
82
-
83
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
84
-
85
- ## How to Get Started with the Model
86
-
87
- Use the code below to get started with the model.
88
-
89
- [More Information Needed]
90
-
91
- ## Training Details
92
-
93
- ### Training Data
94
-
95
- <!-- This should link to a Data 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. -->
96
 
97
- [More Information Needed]
98
 
99
- ### Training Procedure
100
 
101
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
 
 
 
102
 
103
- #### Preprocessing [optional]
 
 
 
104
 
105
- [More Information Needed]
106
 
 
107
 
108
- #### Training Hyperparameters
 
 
 
 
109
 
110
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
111
 
112
- #### Speeds, Sizes, Times [optional]
 
113
 
114
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
 
115
 
116
- [More Information Needed]
117
 
118
  ## Evaluation
 
 
 
119
 
120
- <!-- This section describes the evaluation protocols and provides the results. -->
121
 
122
- ### Testing Data, Factors & Metrics
123
 
124
- #### Testing Data
 
 
 
 
 
 
 
 
125
 
126
- <!-- This should link to a Data Card if possible. -->
127
 
128
- [More Information Needed]
 
 
129
 
130
- #### Factors
 
131
 
132
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
 
133
 
134
- [More Information Needed]
135
 
136
- #### Metrics
 
137
 
138
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
139
 
140
- [More Information Needed]
 
 
141
 
142
- ### Results
 
 
 
 
 
 
 
 
 
 
 
 
 
143
 
144
- [More Information Needed]
 
 
145
 
146
- #### Summary
147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
 
 
 
 
 
149
 
150
- ## Model Examination [optional]
 
151
 
152
- <!-- Relevant interpretability work for the model goes here -->
 
 
 
153
 
154
- [More Information Needed]
155
 
156
- ## Environmental Impact
 
157
 
158
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
159
 
160
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
161
 
162
- - **Hardware Type:** [More Information Needed]
163
- - **Hours used:** [More Information Needed]
164
- - **Cloud Provider:** [More Information Needed]
165
- - **Compute Region:** [More Information Needed]
166
- - **Carbon Emitted:** [More Information Needed]
167
 
168
- ## Technical Specifications [optional]
169
 
170
- ### Model Architecture and Objective
 
 
171
 
172
- [More Information Needed]
 
 
 
 
 
173
 
174
- ### Compute Infrastructure
175
 
176
- [More Information Needed]
177
 
178
- #### Hardware
179
 
180
- [More Information Needed]
181
 
182
- #### Software
 
 
183
 
184
- [More Information Needed]
185
 
186
- ## Citation [optional]
 
 
187
 
188
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
 
 
 
 
 
189
 
190
- **BibTeX:**
191
 
192
- [More Information Needed]
193
 
194
- **APA:**
195
 
196
- [More Information Needed]
197
 
198
- ## Glossary [optional]
199
 
200
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
 
 
 
 
201
 
202
- [More Information Needed]
203
 
204
- ## More Information [optional]
205
 
206
- [More Information Needed]
207
 
208
- ## Model Card Authors [optional]
209
 
210
- [More Information Needed]
211
 
212
- ## Model Card Contact
 
 
 
 
213
 
214
- [More Information Needed]
 
 
1
+ --license: openrail
 
2
  datasets:
3
  - ProGamerGov/StableDiffusion-v1-5-Regularization-Images
4
  - dnlpy/Stable-Diffusion
 
18
  language:
19
  - aa
20
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ license: openrail++
23
+ tags:
24
+ - text-to-image
25
+ - stable-diffusion
26
+ ---
27
+ # SD-XL 1.0-base Model Card
28
+ ![row01](01.png)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
+ ## Model
31
 
32
+ ![pipeline](pipeline.png)
33
 
34
+ [SDXL](https://arxiv.org/abs/2307.01952) consists of an [ensemble of experts](https://arxiv.org/abs/2211.01324) pipeline for latent diffusion:
35
+ In a first step, the base model is used to generate (noisy) latents,
36
+ 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.
37
+ Note that the base model can be used as a standalone module.
38
 
39
+ Alternatively, we can use a two-stage pipeline as follows:
40
+ First, the base model is used to generate latents of the desired output size.
41
+ 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")
42
+ 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.
43
 
44
+ Source code is available at https://github.com/Stability-AI/generative-models .
45
 
46
+ ### Model Description
47
 
48
+ - **Developed by:** Stability AI
49
+ - **Model type:** Diffusion-based text-to-image generative model
50
+ - **License:** [CreativeML Open RAIL++-M License](https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/blob/main/LICENSE.md)
51
+ - **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)).
52
+ - **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).
53
 
54
+ ### Model Sources
55
 
56
+ 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.
57
+ [Clipdrop](https://clipdrop.co/stable-diffusion) provides free SDXL inference.
58
 
59
+ - **Repository:** https://github.com/Stability-AI/generative-models
60
+ - **Demo:** https://clipdrop.co/stable-diffusion
61
 
 
62
 
63
  ## Evaluation
64
+ ![comparison](comparison.png)
65
+ The chart above evaluates user preference for SDXL (with and without refinement) over SDXL 0.9 and Stable Diffusion 1.5 and 2.1.
66
+ The SDXL base model performs significantly better than the previous variants, and the model combined with the refinement module achieves the best overall performance.
67
 
 
68
 
69
+ ### 🧨 Diffusers
70
 
71
+ Make sure to upgrade diffusers to >= 0.19.0:
72
+ ```
73
+ pip install diffusers --upgrade
74
+ ```
75
+
76
+ In addition make sure to install `transformers`, `safetensors`, `accelerate` as well as the invisible watermark:
77
+ ```
78
+ pip install invisible_watermark transformers accelerate safetensors
79
+ ```
80
 
81
+ To just use the base model, you can run:
82
 
83
+ ```py
84
+ from diffusers import DiffusionPipeline
85
+ import torch
86
 
87
+ pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, use_safetensors=True, variant="fp16")
88
+ pipe.to("cuda")
89
 
90
+ # if using torch < 2.0
91
+ # pipe.enable_xformers_memory_efficient_attention()
92
 
93
+ prompt = "An astronaut riding a green horse"
94
 
95
+ images = pipe(prompt=prompt).images[0]
96
+ ```
97
 
98
+ To use the whole base + refiner pipeline as an ensemble of experts you can run:
99
 
100
+ ```py
101
+ from diffusers import DiffusionPipeline
102
+ import torch
103
 
104
+ # load both base & refiner
105
+ base = DiffusionPipeline.from_pretrained(
106
+ "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
107
+ )
108
+ base.to("cuda")
109
+ refiner = DiffusionPipeline.from_pretrained(
110
+ "stabilityai/stable-diffusion-xl-refiner-1.0",
111
+ text_encoder_2=base.text_encoder_2,
112
+ vae=base.vae,
113
+ torch_dtype=torch.float16,
114
+ use_safetensors=True,
115
+ variant="fp16",
116
+ )
117
+ refiner.to("cuda")
118
 
119
+ # Define how many steps and what % of steps to be run on each experts (80/20) here
120
+ n_steps = 40
121
+ high_noise_frac = 0.8
122
 
123
+ prompt = "A majestic lion jumping from a big stone at night"
124
 
125
+ # run both experts
126
+ image = base(
127
+ prompt=prompt,
128
+ num_inference_steps=n_steps,
129
+ denoising_end=high_noise_frac,
130
+ output_type="latent",
131
+ ).images
132
+ image = refiner(
133
+ prompt=prompt,
134
+ num_inference_steps=n_steps,
135
+ denoising_start=high_noise_frac,
136
+ image=image,
137
+ ).images[0]
138
+ ```
139
 
140
+ 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:
141
+ ```py
142
+ pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
143
+ ```
144
 
145
+ If you are limited by GPU VRAM, you can enable *cpu offloading* by calling `pipe.enable_model_cpu_offload`
146
+ instead of `.to("cuda")`:
147
 
148
+ ```diff
149
+ - pipe.to("cuda")
150
+ + pipe.enable_model_cpu_offload()
151
+ ```
152
 
153
+ 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).
154
 
155
+ ### Optimum
156
+ [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/).
157
 
158
+ #### OpenVINO
159
 
160
+ To install Optimum with the dependencies required for OpenVINO :
161
 
162
+ ```bash
163
+ pip install optimum[openvino]
164
+ ```
 
 
165
 
166
+ 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`.
167
 
168
+ ```diff
169
+ - from diffusers import StableDiffusionPipeline
170
+ + from optimum.intel import OVStableDiffusionPipeline
171
 
172
+ model_id = "stabilityai/stable-diffusion-xl-base-1.0"
173
+ - pipeline = StableDiffusionPipeline.from_pretrained(model_id)
174
+ + pipeline = OVStableDiffusionPipeline.from_pretrained(model_id)
175
+ prompt = "A majestic lion jumping from a big stone at night"
176
+ image = pipeline(prompt).images[0]
177
+ ```
178
 
179
+ 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).
180
 
 
181
 
182
+ #### ONNX
183
 
184
+ To install Optimum with the dependencies required for ONNX Runtime inference :
185
 
186
+ ```bash
187
+ pip install optimum[onnxruntime]
188
+ ```
189
 
190
+ 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`.
191
 
192
+ ```diff
193
+ - from diffusers import StableDiffusionPipeline
194
+ + from optimum.onnxruntime import ORTStableDiffusionPipeline
195
 
196
+ model_id = "stabilityai/stable-diffusion-xl-base-1.0"
197
+ - pipeline = StableDiffusionPipeline.from_pretrained(model_id)
198
+ + pipeline = ORTStableDiffusionPipeline.from_pretrained(model_id)
199
+ prompt = "A majestic lion jumping from a big stone at night"
200
+ image = pipeline(prompt).images[0]
201
+ ```
202
 
203
+ You can find more examples in optimum [documentation](https://huggingface.co/docs/optimum/main/en/onnxruntime/usage_guides/models#stable-diffusion-xl).
204
 
 
205
 
206
+ ## Uses
207
 
208
+ ### Direct Use
209
 
210
+ The model is intended for research purposes only. Possible research areas and tasks include
211
 
212
+ - Generation of artworks and use in design and other artistic processes.
213
+ - Applications in educational or creative tools.
214
+ - Research on generative models.
215
+ - Safe deployment of models which have the potential to generate harmful content.
216
+ - Probing and understanding the limitations and biases of generative models.
217
 
218
+ Excluded uses are described below.
219
 
220
+ ### Out-of-Scope Use
221
 
222
+ 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.
223
 
224
+ ## Limitations and Bias
225
 
226
+ ### Limitations
227
 
228
+ - The model does not achieve perfect photorealism
229
+ - The model cannot render legible text
230
+ - 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”
231
+ - Faces and people in general may not be generated properly.
232
+ - The autoencoding part of the model is lossy.
233
 
234
+ ### Bias
235
+ While the capabilities of image generation models are impressive, they can also reinforce or exacerbate social biases.