README.md
14.1 KB · 202 lines · markdown Raw
1 ---
2 license: creativeml-openrail-m
3 tags:
4 - stable-diffusion
5 - stable-diffusion-diffusers
6 - text-to-image
7 inference: true
8 ---
9
10 # Stable Diffusion v1-5 Model Card
11
12 ### ⚠️ This repository is a mirror of the now deprecated `ruwnayml/stable-diffusion-v1-5`, this repository or organization are not affiliated in any way with RunwayML.
13 Modifications to the original model card are in <span style="color:crimson">red</span> or <span style="color:darkgreen">green</span>
14
15 Stable Diffusion is a latent text-to-image diffusion model capable of generating photo-realistic images given any text input.
16 For more information about how Stable Diffusion functions, please have a look at [🤗's Stable Diffusion blog](https://huggingface.co/blog/stable_diffusion).
17
18 The **Stable-Diffusion-v1-5** checkpoint was initialized with the weights of the [Stable-Diffusion-v1-2](https:/steps/huggingface.co/CompVis/stable-diffusion-v1-2)
19 checkpoint and subsequently fine-tuned on 595k steps at resolution 512x512 on "laion-aesthetics v2 5+" and 10% dropping of the text-conditioning to improve [classifier-free guidance sampling](https://arxiv.org/abs/2207.12598).
20
21 You can use this both with the [🧨Diffusers library](https://github.com/huggingface/diffusers) and [RunwayML GitHub repository](https://github.com/runwayml/stable-diffusion) (<span style="color:crimson">now deprecated</span>), <span style="color:darkgreen">ComfyUI, Automatic1111, SD.Next, InvokeAI</span>.
22
23 ### Use with Diffusers
24 ```py
25 from diffusers import StableDiffusionPipeline
26 import torch
27
28 model_id = "sd-legacy/stable-diffusion-v1-5"
29 pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
30 pipe = pipe.to("cuda")
31
32 prompt = "a photo of an astronaut riding a horse on mars"
33 image = pipe(prompt).images[0]
34
35 image.save("astronaut_rides_horse.png")
36 ```
37 For more detailed instructions, use-cases and examples in JAX follow the instructions [here](https://github.com/huggingface/diffusers#text-to-image-generation-with-stable-diffusion)
38
39 ### Use with GitHub Repository <span style="color:crimson">(now deprecated)</span>, <span style="color:darkgreen">ComfyUI or Automatic1111</span>
40
41 1. Download the weights
42 - [v1-5-pruned-emaonly.safetensors](https://huggingface.co/sd-legacy/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors) - ema-only weight. uses less VRAM - suitable for inference
43 - [v1-5-pruned.safetensors](https://huggingface.co/sd-legacy/stable-diffusion-v1-5/resolve/main/v1-5-pruned.safetensors) - ema+non-ema weights. uses more VRAM - suitable for fine-tuning
44
45 2. Follow instructions [here](https://github.com/runwayml/stable-diffusion). <span style="color:crimson">(now deprecated)</span>
46
47 3. <span style="color:darkgreen">Use locally with <a href="https://github.com/comfyanonymous/ComfyUI">ComfyUI</a>, <a href="https://github.com/AUTOMATIC1111/stable-diffusion-webui">AUTOMATIC1111</a>, <a href="https://github.com/vladmandic/automatic">SD.Next</a>, <a href="https://github.com/invoke-ai/InvokeAI">InvokeAI</a></span>
48
49 ## Model Details
50 - **Developed by:** Robin Rombach, Patrick Esser
51 - **Model type:** Diffusion-based text-to-image generation model
52 - **Language(s):** English
53 - **License:** [The CreativeML OpenRAIL M license](https://huggingface.co/spaces/CompVis/stable-diffusion-license) is an [Open RAIL M license](https://www.licenses.ai/blog/2022/8/18/naming-convention-of-responsible-ai-licenses), adapted from the work that [BigScience](https://bigscience.huggingface.co/) and [the RAIL Initiative](https://www.licenses.ai/) are jointly carrying in the area of responsible AI licensing. See also [the article about the BLOOM Open RAIL license](https://bigscience.huggingface.co/blog/the-bigscience-rail-license) on which our license is based.
54 - **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 a fixed, pretrained text encoder ([CLIP ViT-L/14](https://arxiv.org/abs/2103.00020)) as suggested in the [Imagen paper](https://arxiv.org/abs/2205.11487).
55 - **Resources for more information:** [GitHub Repository](https://github.com/CompVis/stable-diffusion), [Paper](https://arxiv.org/abs/2112.10752).
56 - **Cite as:**
57
58 @InProceedings{Rombach_2022_CVPR,
59 author = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj\"orn},
60 title = {High-Resolution Image Synthesis With Latent Diffusion Models},
61 booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
62 month = {June},
63 year = {2022},
64 pages = {10684-10695}
65 }
66
67 # Uses
68
69 ## Direct Use
70 The model is intended for research purposes only. Possible research areas and
71 tasks include
72
73 - Safe deployment of models which have the potential to generate harmful content.
74 - Probing and understanding the limitations and biases of generative models.
75 - Generation of artworks and use in design and other artistic processes.
76 - Applications in educational or creative tools.
77 - Research on generative models.
78
79 Excluded uses are described below.
80
81 ### Misuse, Malicious Use, and Out-of-Scope Use
82 _Note: This section is taken from the [DALLE-MINI model card](https://huggingface.co/dalle-mini/dalle-mini), but applies in the same way to Stable Diffusion v1_.
83
84
85 The model should not be used to intentionally create or disseminate images that create hostile or alienating environments for people. This includes generating images that people would foreseeably find disturbing, distressing, or offensive; or content that propagates historical or current stereotypes.
86
87 #### Out-of-Scope Use
88 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.
89
90 #### Misuse and Malicious Use
91 Using the model to generate content that is cruel to individuals is a misuse of this model. This includes, but is not limited to:
92
93 - Generating demeaning, dehumanizing, or otherwise harmful representations of people or their environments, cultures, religions, etc.
94 - Intentionally promoting or propagating discriminatory content or harmful stereotypes.
95 - Impersonating individuals without their consent.
96 - Sexual content without consent of the people who might see it.
97 - Mis- and disinformation
98 - Representations of egregious violence and gore
99 - Sharing of copyrighted or licensed material in violation of its terms of use.
100 - Sharing content that is an alteration of copyrighted or licensed material in violation of its terms of use.
101
102 ## Limitations and Bias
103
104 ### Limitations
105
106 - The model does not achieve perfect photorealism
107 - The model cannot render legible text
108 - The model does not perform well on more difficult tasks which involve compositionality, such as rendering an image corresponding to “A red cube on top of a blue sphere”
109 - Faces and people in general may not be generated properly.
110 - The model was trained mainly with English captions and will not work as well in other languages.
111 - The autoencoding part of the model is lossy
112 - The model was trained on a large-scale dataset
113 [LAION-5B](https://laion.ai/blog/laion-5b/) which contains adult material
114 and is not fit for product use without additional safety mechanisms and
115 considerations.
116 - No additional measures were used to deduplicate the dataset. As a result, we observe some degree of memorization for images that are duplicated in the training data.
117 The training data can be searched at [https://rom1504.github.io/clip-retrieval/](https://rom1504.github.io/clip-retrieval/) to possibly assist in the detection of memorized images.
118
119 ### Bias
120
121 While the capabilities of image generation models are impressive, they can also reinforce or exacerbate social biases.
122 Stable Diffusion v1 was trained on subsets of [LAION-2B(en)](https://laion.ai/blog/laion-5b/),
123 which consists of images that are primarily limited to English descriptions.
124 Texts and images from communities and cultures that use other languages are likely to be insufficiently accounted for.
125 This affects the overall output of the model, as white and western cultures are often set as the default. Further, the
126 ability of the model to generate content with non-English prompts is significantly worse than with English-language prompts.
127
128 ### Safety Module
129
130 The intended use of this model is with the [Safety Checker](https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/safety_checker.py) in Diffusers.
131 This checker works by checking model outputs against known hard-coded NSFW concepts.
132 The concepts are intentionally hidden to reduce the likelihood of reverse-engineering this filter.
133 Specifically, the checker compares the class probability of harmful concepts in the embedding space of the `CLIPTextModel` *after generation* of the images.
134 The concepts are passed into the model with the generated image and compared to a hand-engineered weight for each NSFW concept.
135
136
137 ## Training
138
139 **Training Data**
140 The model developers used the following dataset for training the model:
141
142 - LAION-2B (en) and subsets thereof (see next section)
143
144 **Training Procedure**
145 Stable Diffusion v1-5 is a latent diffusion model which combines an autoencoder with a diffusion model that is trained in the latent space of the autoencoder. During training,
146
147 - Images are encoded through an encoder, which turns images into latent representations. The autoencoder uses a relative downsampling factor of 8 and maps images of shape H x W x 3 to latents of shape H/f x W/f x 4
148 - Text prompts are encoded through a ViT-L/14 text-encoder.
149 - The non-pooled output of the text encoder is fed into the UNet backbone of the latent diffusion model via cross-attention.
150 - The loss is a reconstruction objective between the noise that was added to the latent and the prediction made by the UNet.
151
152 Currently six Stable Diffusion checkpoints are provided, which were trained as follows.
153 - [`stable-diffusion-v1-1`](https://huggingface.co/CompVis/stable-diffusion-v1-1): 237,000 steps at resolution `256x256` on [laion2B-en](https://huggingface.co/datasets/laion/laion2B-en).
154 194,000 steps at resolution `512x512` on [laion-high-resolution](https://huggingface.co/datasets/laion/laion-high-resolution) (170M examples from LAION-5B with resolution `>= 1024x1024`).
155 - [`stable-diffusion-v1-2`](https://huggingface.co/CompVis/stable-diffusion-v1-2): Resumed from `stable-diffusion-v1-1`.
156 515,000 steps at resolution `512x512` on "laion-improved-aesthetics" (a subset of laion2B-en,
157 filtered to images with an original size `>= 512x512`, estimated aesthetics score `> 5.0`, and an estimated watermark probability `< 0.5`. The watermark estimate is from the LAION-5B metadata, the aesthetics score is estimated using an [improved aesthetics estimator](https://github.com/christophschuhmann/improved-aesthetic-predictor)).
158 - [`stable-diffusion-v1-3`](https://huggingface.co/CompVis/stable-diffusion-v1-3): Resumed from `stable-diffusion-v1-2` - 195,000 steps at resolution `512x512` on "laion-improved-aesthetics" and 10 % dropping of the text-conditioning to improve [classifier-free guidance sampling](https://arxiv.org/abs/2207.12598).
159 - [`stable-diffusion-v1-4`](https://huggingface.co/CompVis/stable-diffusion-v1-4) Resumed from `stable-diffusion-v1-2` - 225,000 steps at resolution `512x512` on "laion-aesthetics v2 5+" and 10 % dropping of the text-conditioning to improve [classifier-free guidance sampling](https://arxiv.org/abs/2207.12598).
160 - [`stable-diffusion-v1-5`](https://huggingface.co/sd-legacy/stable-diffusion-v1-5) Resumed from `stable-diffusion-v1-2` - 595,000 steps at resolution `512x512` on "laion-aesthetics v2 5+" and 10 % dropping of the text-conditioning to improve [classifier-free guidance sampling](https://arxiv.org/abs/2207.12598).
161 - [`stable-diffusion-inpainting`](https://huggingface.co/sd-legacy/stable-diffusion-inpainting) Resumed from `stable-diffusion-v1-5` - then 440,000 steps of inpainting training at resolution 512x512 on “laion-aesthetics v2 5+” and 10% dropping of the text-conditioning. For inpainting, the UNet has 5 additional input channels (4 for the encoded masked-image and 1 for the mask itself) whose weights were zero-initialized after restoring the non-inpainting checkpoint. During training, we generate synthetic masks and in 25% mask everything.
162
163 - **Hardware:** 32 x 8 x A100 GPUs
164 - **Optimizer:** AdamW
165 - **Gradient Accumulations**: 2
166 - **Batch:** 32 x 8 x 2 x 4 = 2048
167 - **Learning rate:** warmup to 0.0001 for 10,000 steps and then kept constant
168
169 ## Evaluation Results
170 Evaluations with different classifier-free guidance scales (1.5, 2.0, 3.0, 4.0,
171 5.0, 6.0, 7.0, 8.0) and 50 PNDM/PLMS sampling
172 steps show the relative improvements of the checkpoints:
173
174 ![pareto](https://huggingface.co/CompVis/stable-diffusion/resolve/main/v1-1-to-v1-5.png)
175
176 Evaluated using 50 PLMS steps and 10000 random prompts from the COCO2017 validation set, evaluated at 512x512 resolution. Not optimized for FID scores.
177 ## Environmental Impact
178
179 **Stable Diffusion v1** **Estimated Emissions**
180 Based on that information, we estimate the following CO2 emissions using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700). The hardware, runtime, cloud provider, and compute region were utilized to estimate the carbon impact.
181
182 - **Hardware Type:** A100 PCIe 40GB
183 - **Hours used:** 150000
184 - **Cloud Provider:** AWS
185 - **Compute Region:** US-east
186 - **Carbon Emitted (Power consumption x Time x Carbon produced based on location of power grid):** 11250 kg CO2 eq.
187
188
189 ## Citation
190
191 ```bibtex
192 @InProceedings{Rombach_2022_CVPR,
193 author = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj\"orn},
194 title = {High-Resolution Image Synthesis With Latent Diffusion Models},
195 booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
196 month = {June},
197 year = {2022},
198 pages = {10684-10695}
199 }
200 ```
201
202 *This model card was written by: Robin Rombach and Patrick Esser and is based on the [DALL-E Mini model card](https://huggingface.co/dalle-mini/dalle-mini).*