junnyu commited on
Commit
150a167
1 Parent(s): c9f5bcc

My first signed commit

Browse files
.gitattributes CHANGED
@@ -30,3 +30,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
30
  *.zip filter=lfs diff=lfs merge=lfs -text
31
  *.zst filter=lfs diff=lfs merge=lfs -text
32
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
30
  *.zip filter=lfs diff=lfs merge=lfs -text
31
  *.zst filter=lfs diff=lfs merge=lfs -text
32
  *tfevents* filter=lfs diff=lfs merge=lfs -text
33
+ *.pdparams filter=lfs diff=lfs merge=lfs -text
.ipynb_checkpoints/README-checkpoint.md ADDED
@@ -0,0 +1,251 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: creativeml-openrail-m
3
+ tags:
4
+ - stable-diffusion
5
+ - stable-diffusion-diffusers
6
+ - text-to-image
7
+ inference: false
8
+ extra_gated_prompt: |-
9
+ One more step before getting this model.
10
+ This model is open access and available to all, with a CreativeML OpenRAIL-M license further specifying rights and usage.
11
+ The CreativeML OpenRAIL License specifies:
12
+
13
+ 1. You can't use the model to deliberately produce nor share illegal or harmful outputs or content
14
+ 2. CompVis claims no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in the license
15
+ 3. You may re-distribute the weights and use the model commercially and/or as a service. If you do, please be aware you have to include the same use restrictions as the ones in the license and share a copy of the CreativeML OpenRAIL-M to all your users (please read the license entirely and carefully)
16
+ Please read the full license here: https://huggingface.co/spaces/CompVis/stable-diffusion-license
17
+
18
+ By clicking on "Access repository" below, you accept that your *contact information* (email address and username) can be shared with the model authors as well.
19
+
20
+ extra_gated_fields:
21
+ I have read the License and agree with its terms: checkbox
22
+ ---
23
+
24
+ # Stable Diffusion v1-4 Model Card
25
+
26
+ Stable Diffusion is a latent text-to-image diffusion model capable of generating photo-realistic images given any text input.
27
+ For more information about how Stable Diffusion functions, please have a look at [🤗's Stable Diffusion with 🧨Diffusers blog](https://huggingface.co/blog/stable_diffusion).
28
+
29
+ The **Stable-Diffusion-v1-4** checkpoint was initialized with the weights of the [Stable-Diffusion-v1-2](https:/steps/huggingface.co/CompVis/stable-diffusion-v1-2)
30
+ checkpoint and subsequently fine-tuned on 225k 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).
31
+
32
+ This weights here are intended to be used with the 🧨 Diffusers library. If you are looking for the weights to be loaded into the CompVis Stable Diffusion codebase, [come here](https://huggingface.co/CompVis/stable-diffusion-v-1-4-original)
33
+
34
+ ## Model Details
35
+ - **Developed by:** Robin Rombach, Patrick Esser
36
+ - **Model type:** Diffusion-based text-to-image generation model
37
+ - **Language(s):** English
38
+ - **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.
39
+ - **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).
40
+ - **Resources for more information:** [GitHub Repository](https://github.com/CompVis/stable-diffusion), [Paper](https://arxiv.org/abs/2112.10752).
41
+ - **Cite as:**
42
+
43
+ @InProceedings{Rombach_2022_CVPR,
44
+ author = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj\"orn},
45
+ title = {High-Resolution Image Synthesis With Latent Diffusion Models},
46
+ booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
47
+ month = {June},
48
+ year = {2022},
49
+ pages = {10684-10695}
50
+ }
51
+
52
+ ## Examples
53
+
54
+ We recommend using [🤗's Diffusers library](https://github.com/huggingface/diffusers) to run Stable Diffusion.
55
+ We convert this library to paddle version.
56
+
57
+ ```bash
58
+ pip install --upgrade diffusers_paddle paddlenlp scipy
59
+ ```
60
+
61
+ Run this command to log in with your HF Hub token if you haven't before:
62
+
63
+ ```bash
64
+ huggingface-cli login
65
+ ```
66
+
67
+ Running the pipeline with the default PNDM scheduler:
68
+
69
+ ```python
70
+ import paddle
71
+ from paddle.amp import auto_cast as autocast
72
+ from diffusers_paddle import StableDiffusionPipeline
73
+
74
+ model_id = "CompVis/stable-diffusion-v1-4"
75
+
76
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True)
77
+
78
+ prompt = "a photo of an astronaut riding a horse on mars"
79
+ with autocast(True):
80
+ image = pipe(prompt, guidance_scale=7.5).images[0]
81
+
82
+ image.save("astronaut_rides_horse.png")
83
+ ```
84
+
85
+ **Note**:
86
+ If you are limited by GPU memory and have less than 10GB of GPU RAM available, please make sure to load the StableDiffusionPipeline in float16 precision instead of the default float32 precision as done above. You can do so by telling diffusers to expect the weights to be in float16 precision:
87
+
88
+
89
+ ```py
90
+ import paddle
91
+
92
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, paddle_dtype=paddle.float16, use_auth_token=True)
93
+
94
+ prompt = "a photo of an astronaut riding a horse on mars"
95
+ with autocast(True):
96
+ image = pipe(prompt, guidance_scale=7.5).images[0]
97
+
98
+ image.save("astronaut_rides_horse.png")
99
+ ```
100
+
101
+ To swap out the noise scheduler, pass it to `from_pretrained`:
102
+
103
+ ```python
104
+ from diffusers_paddle import StableDiffusionPipeline, LMSDiscreteScheduler
105
+ from paddle.amp import auto_cast as autocast
106
+ model_id = "junnyu/stable-diffusion-v1-4-paddle"
107
+ # Use the K-LMS scheduler here instead
108
+ scheduler = LMSDiscreteScheduler(beta_start=0.00085, beta_end=0.012, beta_schedule="scaled_linear", num_train_timesteps=1000)
109
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, use_auth_token=True)
110
+
111
+ prompt = "a photo of an astronaut riding a horse on mars"
112
+ with autocast(True):
113
+ image = pipe(prompt, guidance_scale=7.5).images[0]
114
+
115
+ image.save("astronaut_rides_horse.png")
116
+ ```
117
+
118
+ # Uses
119
+
120
+ ## Direct Use
121
+ The model is intended for research purposes only. Possible research areas and
122
+ tasks include
123
+
124
+ - Safe deployment of models which have the potential to generate harmful content.
125
+ - Probing and understanding the limitations and biases of generative models.
126
+ - Generation of artworks and use in design and other artistic processes.
127
+ - Applications in educational or creative tools.
128
+ - Research on generative models.
129
+
130
+ Excluded uses are described below.
131
+
132
+ ### Misuse, Malicious Use, and Out-of-Scope Use
133
+ _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_.
134
+
135
+
136
+ 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.
137
+
138
+ #### Out-of-Scope Use
139
+ 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.
140
+
141
+ #### Misuse and Malicious Use
142
+ Using the model to generate content that is cruel to individuals is a misuse of this model. This includes, but is not limited to:
143
+
144
+ - Generating demeaning, dehumanizing, or otherwise harmful representations of people or their environments, cultures, religions, etc.
145
+ - Intentionally promoting or propagating discriminatory content or harmful stereotypes.
146
+ - Impersonating individuals without their consent.
147
+ - Sexual content without consent of the people who might see it.
148
+ - Mis- and disinformation
149
+ - Representations of egregious violence and gore
150
+ - Sharing of copyrighted or licensed material in violation of its terms of use.
151
+ - Sharing content that is an alteration of copyrighted or licensed material in violation of its terms of use.
152
+
153
+ ## Limitations and Bias
154
+
155
+ ### Limitations
156
+
157
+ - The model does not achieve perfect photorealism
158
+ - The model cannot render legible text
159
+ - 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”
160
+ - Faces and people in general may not be generated properly.
161
+ - The model was trained mainly with English captions and will not work as well in other languages.
162
+ - The autoencoding part of the model is lossy
163
+ - The model was trained on a large-scale dataset
164
+ [LAION-5B](https://laion.ai/blog/laion-5b/) which contains adult material
165
+ and is not fit for product use without additional safety mechanisms and
166
+ considerations.
167
+ - 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.
168
+ 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.
169
+
170
+ ### Bias
171
+
172
+ While the capabilities of image generation models are impressive, they can also reinforce or exacerbate social biases.
173
+ Stable Diffusion v1 was trained on subsets of [LAION-2B(en)](https://laion.ai/blog/laion-5b/),
174
+ which consists of images that are primarily limited to English descriptions.
175
+ Texts and images from communities and cultures that use other languages are likely to be insufficiently accounted for.
176
+ This affects the overall output of the model, as white and western cultures are often set as the default. Further, the
177
+ ability of the model to generate content with non-English prompts is significantly worse than with English-language prompts.
178
+
179
+ ### Safety Module
180
+
181
+ 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.
182
+ This checker works by checking model outputs against known hard-coded NSFW concepts.
183
+ The concepts are intentionally hidden to reduce the likelihood of reverse-engineering this filter.
184
+ Specifically, the checker compares the class probability of harmful concepts in the embedding space of the `CLIPTextModel` *after generation* of the images.
185
+ The concepts are passed into the model with the generated image and compared to a hand-engineered weight for each NSFW concept.
186
+
187
+
188
+ ## Training
189
+
190
+ **Training Data**
191
+ The model developers used the following dataset for training the model:
192
+
193
+ - LAION-2B (en) and subsets thereof (see next section)
194
+
195
+ **Training Procedure**
196
+ Stable Diffusion v1-4 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,
197
+
198
+ - 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
199
+ - Text prompts are encoded through a ViT-L/14 text-encoder.
200
+ - The non-pooled output of the text encoder is fed into the UNet backbone of the latent diffusion model via cross-attention.
201
+ - The loss is a reconstruction objective between the noise that was added to the latent and the prediction made by the UNet.
202
+
203
+ We currently provide four checkpoints, which were trained as follows.
204
+ - [`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).
205
+ 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`).
206
+ - [`stable-diffusion-v1-2`](https://huggingface.co/CompVis/stable-diffusion-v1-2): Resumed from `stable-diffusion-v1-1`.
207
+ 515,000 steps at resolution `512x512` on "laion-improved-aesthetics" (a subset of laion2B-en,
208
+ 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)).
209
+ - [`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).
210
+ - [`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).
211
+
212
+ - **Hardware:** 32 x 8 x A100 GPUs
213
+ - **Optimizer:** AdamW
214
+ - **Gradient Accumulations**: 2
215
+ - **Batch:** 32 x 8 x 2 x 4 = 2048
216
+ - **Learning rate:** warmup to 0.0001 for 10,000 steps and then kept constant
217
+
218
+ ## Evaluation Results
219
+ Evaluations with different classifier-free guidance scales (1.5, 2.0, 3.0, 4.0,
220
+ 5.0, 6.0, 7.0, 8.0) and 50 PLMS sampling
221
+ steps show the relative improvements of the checkpoints:
222
+
223
+ ![pareto](https://huggingface.co/CompVis/stable-diffusion/resolve/main/v1-variants-scores.jpg)
224
+
225
+ Evaluated using 50 PLMS steps and 10000 random prompts from the COCO2017 validation set, evaluated at 512x512 resolution. Not optimized for FID scores.
226
+ ## Environmental Impact
227
+
228
+ **Stable Diffusion v1** **Estimated Emissions**
229
+ 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.
230
+
231
+ - **Hardware Type:** A100 PCIe 40GB
232
+ - **Hours used:** 150000
233
+ - **Cloud Provider:** AWS
234
+ - **Compute Region:** US-east
235
+ - **Carbon Emitted (Power consumption x Time x Carbon produced based on location of power grid):** 11250 kg CO2 eq.
236
+
237
+
238
+ ## Citation
239
+
240
+ ```bibtex
241
+ @InProceedings{Rombach_2022_CVPR,
242
+ author = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj\"orn},
243
+ title = {High-Resolution Image Synthesis With Latent Diffusion Models},
244
+ booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
245
+ month = {June},
246
+ year = {2022},
247
+ pages = {10684-10695}
248
+ }
249
+ ```
250
+
251
+ *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).*
.ipynb_checkpoints/model_index-checkpoint.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "StableDiffusionPipeline",
3
+ "_diffusers_paddle_version": "0.3.0",
4
+ "feature_extractor": [
5
+ "paddlenlp.transformers",
6
+ "CLIPFeatureExtractor"
7
+ ],
8
+ "safety_checker": [
9
+ "stable_diffusion",
10
+ "StableDiffusionSafetyChecker"
11
+ ],
12
+ "scheduler": [
13
+ "diffusers_paddle",
14
+ "PNDMScheduler"
15
+ ],
16
+ "text_encoder": [
17
+ "paddlenlp.transformers",
18
+ "CLIPTextModel"
19
+ ],
20
+ "tokenizer": [
21
+ "paddlenlp.transformers",
22
+ "CLIPTokenizer"
23
+ ],
24
+ "unet": [
25
+ "diffusers_paddle",
26
+ "UNet2DConditionModel"
27
+ ],
28
+ "vae": [
29
+ "diffusers_paddle",
30
+ "AutoencoderKL"
31
+ ]
32
+ }
README.md CHANGED
@@ -1,3 +1,251 @@
1
  ---
2
  license: creativeml-openrail-m
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: creativeml-openrail-m
3
+ tags:
4
+ - stable-diffusion
5
+ - stable-diffusion-diffusers
6
+ - text-to-image
7
+ inference: false
8
+ extra_gated_prompt: |-
9
+ One more step before getting this model.
10
+ This model is open access and available to all, with a CreativeML OpenRAIL-M license further specifying rights and usage.
11
+ The CreativeML OpenRAIL License specifies:
12
+
13
+ 1. You can't use the model to deliberately produce nor share illegal or harmful outputs or content
14
+ 2. CompVis claims no rights on the outputs you generate, you are free to use them and are accountable for their use which must not go against the provisions set in the license
15
+ 3. You may re-distribute the weights and use the model commercially and/or as a service. If you do, please be aware you have to include the same use restrictions as the ones in the license and share a copy of the CreativeML OpenRAIL-M to all your users (please read the license entirely and carefully)
16
+ Please read the full license here: https://huggingface.co/spaces/CompVis/stable-diffusion-license
17
+
18
+ By clicking on "Access repository" below, you accept that your *contact information* (email address and username) can be shared with the model authors as well.
19
+
20
+ extra_gated_fields:
21
+ I have read the License and agree with its terms: checkbox
22
  ---
23
+
24
+ # Stable Diffusion v1-4 Model Card
25
+
26
+ Stable Diffusion is a latent text-to-image diffusion model capable of generating photo-realistic images given any text input.
27
+ For more information about how Stable Diffusion functions, please have a look at [🤗's Stable Diffusion with 🧨Diffusers blog](https://huggingface.co/blog/stable_diffusion).
28
+
29
+ The **Stable-Diffusion-v1-4** checkpoint was initialized with the weights of the [Stable-Diffusion-v1-2](https:/steps/huggingface.co/CompVis/stable-diffusion-v1-2)
30
+ checkpoint and subsequently fine-tuned on 225k 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).
31
+
32
+ This weights here are intended to be used with the 🧨 Diffusers library. If you are looking for the weights to be loaded into the CompVis Stable Diffusion codebase, [come here](https://huggingface.co/CompVis/stable-diffusion-v-1-4-original)
33
+
34
+ ## Model Details
35
+ - **Developed by:** Robin Rombach, Patrick Esser
36
+ - **Model type:** Diffusion-based text-to-image generation model
37
+ - **Language(s):** English
38
+ - **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.
39
+ - **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).
40
+ - **Resources for more information:** [GitHub Repository](https://github.com/CompVis/stable-diffusion), [Paper](https://arxiv.org/abs/2112.10752).
41
+ - **Cite as:**
42
+
43
+ @InProceedings{Rombach_2022_CVPR,
44
+ author = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj\"orn},
45
+ title = {High-Resolution Image Synthesis With Latent Diffusion Models},
46
+ booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
47
+ month = {June},
48
+ year = {2022},
49
+ pages = {10684-10695}
50
+ }
51
+
52
+ ## Examples
53
+
54
+ We recommend using [🤗's Diffusers library](https://github.com/huggingface/diffusers) to run Stable Diffusion.
55
+ We convert this library to paddle version.
56
+
57
+ ```bash
58
+ pip install --upgrade diffusers_paddle paddlenlp scipy
59
+ ```
60
+
61
+ Run this command to log in with your HF Hub token if you haven't before:
62
+
63
+ ```bash
64
+ huggingface-cli login
65
+ ```
66
+
67
+ Running the pipeline with the default PNDM scheduler:
68
+
69
+ ```python
70
+ import paddle
71
+ from paddle.amp import auto_cast as autocast
72
+ from diffusers_paddle import StableDiffusionPipeline
73
+
74
+ model_id = "CompVis/stable-diffusion-v1-4"
75
+
76
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, use_auth_token=True)
77
+
78
+ prompt = "a photo of an astronaut riding a horse on mars"
79
+ with autocast(True):
80
+ image = pipe(prompt, guidance_scale=7.5).images[0]
81
+
82
+ image.save("astronaut_rides_horse.png")
83
+ ```
84
+
85
+ **Note**:
86
+ If you are limited by GPU memory and have less than 10GB of GPU RAM available, please make sure to load the StableDiffusionPipeline in float16 precision instead of the default float32 precision as done above. You can do so by telling diffusers to expect the weights to be in float16 precision:
87
+
88
+
89
+ ```py
90
+ import paddle
91
+
92
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, paddle_dtype=paddle.float16, use_auth_token=True)
93
+
94
+ prompt = "a photo of an astronaut riding a horse on mars"
95
+ with autocast(True):
96
+ image = pipe(prompt, guidance_scale=7.5).images[0]
97
+
98
+ image.save("astronaut_rides_horse.png")
99
+ ```
100
+
101
+ To swap out the noise scheduler, pass it to `from_pretrained`:
102
+
103
+ ```python
104
+ from diffusers_paddle import StableDiffusionPipeline, LMSDiscreteScheduler
105
+ from paddle.amp import auto_cast as autocast
106
+ model_id = "junnyu/stable-diffusion-v1-4-paddle"
107
+ # Use the K-LMS scheduler here instead
108
+ scheduler = LMSDiscreteScheduler(beta_start=0.00085, beta_end=0.012, beta_schedule="scaled_linear", num_train_timesteps=1000)
109
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, scheduler=scheduler, use_auth_token=True)
110
+
111
+ prompt = "a photo of an astronaut riding a horse on mars"
112
+ with autocast(True):
113
+ image = pipe(prompt, guidance_scale=7.5).images[0]
114
+
115
+ image.save("astronaut_rides_horse.png")
116
+ ```
117
+
118
+ # Uses
119
+
120
+ ## Direct Use
121
+ The model is intended for research purposes only. Possible research areas and
122
+ tasks include
123
+
124
+ - Safe deployment of models which have the potential to generate harmful content.
125
+ - Probing and understanding the limitations and biases of generative models.
126
+ - Generation of artworks and use in design and other artistic processes.
127
+ - Applications in educational or creative tools.
128
+ - Research on generative models.
129
+
130
+ Excluded uses are described below.
131
+
132
+ ### Misuse, Malicious Use, and Out-of-Scope Use
133
+ _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_.
134
+
135
+
136
+ 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.
137
+
138
+ #### Out-of-Scope Use
139
+ 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.
140
+
141
+ #### Misuse and Malicious Use
142
+ Using the model to generate content that is cruel to individuals is a misuse of this model. This includes, but is not limited to:
143
+
144
+ - Generating demeaning, dehumanizing, or otherwise harmful representations of people or their environments, cultures, religions, etc.
145
+ - Intentionally promoting or propagating discriminatory content or harmful stereotypes.
146
+ - Impersonating individuals without their consent.
147
+ - Sexual content without consent of the people who might see it.
148
+ - Mis- and disinformation
149
+ - Representations of egregious violence and gore
150
+ - Sharing of copyrighted or licensed material in violation of its terms of use.
151
+ - Sharing content that is an alteration of copyrighted or licensed material in violation of its terms of use.
152
+
153
+ ## Limitations and Bias
154
+
155
+ ### Limitations
156
+
157
+ - The model does not achieve perfect photorealism
158
+ - The model cannot render legible text
159
+ - 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”
160
+ - Faces and people in general may not be generated properly.
161
+ - The model was trained mainly with English captions and will not work as well in other languages.
162
+ - The autoencoding part of the model is lossy
163
+ - The model was trained on a large-scale dataset
164
+ [LAION-5B](https://laion.ai/blog/laion-5b/) which contains adult material
165
+ and is not fit for product use without additional safety mechanisms and
166
+ considerations.
167
+ - 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.
168
+ 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.
169
+
170
+ ### Bias
171
+
172
+ While the capabilities of image generation models are impressive, they can also reinforce or exacerbate social biases.
173
+ Stable Diffusion v1 was trained on subsets of [LAION-2B(en)](https://laion.ai/blog/laion-5b/),
174
+ which consists of images that are primarily limited to English descriptions.
175
+ Texts and images from communities and cultures that use other languages are likely to be insufficiently accounted for.
176
+ This affects the overall output of the model, as white and western cultures are often set as the default. Further, the
177
+ ability of the model to generate content with non-English prompts is significantly worse than with English-language prompts.
178
+
179
+ ### Safety Module
180
+
181
+ 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.
182
+ This checker works by checking model outputs against known hard-coded NSFW concepts.
183
+ The concepts are intentionally hidden to reduce the likelihood of reverse-engineering this filter.
184
+ Specifically, the checker compares the class probability of harmful concepts in the embedding space of the `CLIPTextModel` *after generation* of the images.
185
+ The concepts are passed into the model with the generated image and compared to a hand-engineered weight for each NSFW concept.
186
+
187
+
188
+ ## Training
189
+
190
+ **Training Data**
191
+ The model developers used the following dataset for training the model:
192
+
193
+ - LAION-2B (en) and subsets thereof (see next section)
194
+
195
+ **Training Procedure**
196
+ Stable Diffusion v1-4 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,
197
+
198
+ - 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
199
+ - Text prompts are encoded through a ViT-L/14 text-encoder.
200
+ - The non-pooled output of the text encoder is fed into the UNet backbone of the latent diffusion model via cross-attention.
201
+ - The loss is a reconstruction objective between the noise that was added to the latent and the prediction made by the UNet.
202
+
203
+ We currently provide four checkpoints, which were trained as follows.
204
+ - [`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).
205
+ 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`).
206
+ - [`stable-diffusion-v1-2`](https://huggingface.co/CompVis/stable-diffusion-v1-2): Resumed from `stable-diffusion-v1-1`.
207
+ 515,000 steps at resolution `512x512` on "laion-improved-aesthetics" (a subset of laion2B-en,
208
+ 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)).
209
+ - [`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).
210
+ - [`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).
211
+
212
+ - **Hardware:** 32 x 8 x A100 GPUs
213
+ - **Optimizer:** AdamW
214
+ - **Gradient Accumulations**: 2
215
+ - **Batch:** 32 x 8 x 2 x 4 = 2048
216
+ - **Learning rate:** warmup to 0.0001 for 10,000 steps and then kept constant
217
+
218
+ ## Evaluation Results
219
+ Evaluations with different classifier-free guidance scales (1.5, 2.0, 3.0, 4.0,
220
+ 5.0, 6.0, 7.0, 8.0) and 50 PLMS sampling
221
+ steps show the relative improvements of the checkpoints:
222
+
223
+ ![pareto](https://huggingface.co/CompVis/stable-diffusion/resolve/main/v1-variants-scores.jpg)
224
+
225
+ Evaluated using 50 PLMS steps and 10000 random prompts from the COCO2017 validation set, evaluated at 512x512 resolution. Not optimized for FID scores.
226
+ ## Environmental Impact
227
+
228
+ **Stable Diffusion v1** **Estimated Emissions**
229
+ 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.
230
+
231
+ - **Hardware Type:** A100 PCIe 40GB
232
+ - **Hours used:** 150000
233
+ - **Cloud Provider:** AWS
234
+ - **Compute Region:** US-east
235
+ - **Carbon Emitted (Power consumption x Time x Carbon produced based on location of power grid):** 11250 kg CO2 eq.
236
+
237
+
238
+ ## Citation
239
+
240
+ ```bibtex
241
+ @InProceedings{Rombach_2022_CVPR,
242
+ author = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj\"orn},
243
+ title = {High-Resolution Image Synthesis With Latent Diffusion Models},
244
+ booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
245
+ month = {June},
246
+ year = {2022},
247
+ pages = {10684-10695}
248
+ }
249
+ ```
250
+
251
+ *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).*
feature_extractor/preprocessor_config.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "crop_size": 224,
3
+ "do_center_crop": true,
4
+ "do_convert_rgb": true,
5
+ "do_normalize": true,
6
+ "do_resize": true,
7
+ "feature_extractor_type": "CLIPFeatureExtractor",
8
+ "image_mean": [
9
+ 0.48145466,
10
+ 0.4578275,
11
+ 0.40821073
12
+ ],
13
+ "image_std": [
14
+ 0.26862954,
15
+ 0.26130258,
16
+ 0.27577711
17
+ ],
18
+ "resample": 3,
19
+ "size": 224
20
+ }
model_index.json ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "StableDiffusionPipeline",
3
+ "_diffusers_paddle_version": "0.3.0",
4
+ "feature_extractor": [
5
+ "paddlenlp.transformers",
6
+ "CLIPFeatureExtractor"
7
+ ],
8
+ "safety_checker": [
9
+ "stable_diffusion",
10
+ "StableDiffusionSafetyChecker"
11
+ ],
12
+ "scheduler": [
13
+ "diffusers_paddle",
14
+ "PNDMScheduler"
15
+ ],
16
+ "text_encoder": [
17
+ "paddlenlp.transformers",
18
+ "CLIPTextModel"
19
+ ],
20
+ "tokenizer": [
21
+ "paddlenlp.transformers",
22
+ "CLIPTokenizer"
23
+ ],
24
+ "unet": [
25
+ "diffusers_paddle",
26
+ "UNet2DConditionModel"
27
+ ],
28
+ "vae": [
29
+ "diffusers_paddle",
30
+ "AutoencoderKL"
31
+ ]
32
+ }
safety_checker/model_config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "init_args": [
3
+ {
4
+ "image_resolution": 224,
5
+ "vision_layers": 24,
6
+ "vision_heads": 16,
7
+ "vision_mlp_ratio": 4,
8
+ "vision_embed_dim": 1024,
9
+ "vision_patch_size": 14,
10
+ "vision_hidden_act": "quick_gelu",
11
+ "max_text_length": 77,
12
+ "vocab_size": 49408,
13
+ "text_embed_dim": 768,
14
+ "text_heads": 12,
15
+ "text_layers": 12,
16
+ "text_hidden_act": "quick_gelu",
17
+ "projection_dim": 768,
18
+ "initializer_range": 0.02,
19
+ "logit_scale_init_value": 2.6592,
20
+ "init_class": "CLIPVisionModel"
21
+ }
22
+ ],
23
+ "init_class": "StableDiffusionSafetyChecker"
24
+ }
safety_checker/model_state.pdparams ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b7d4f5da35bb269634421f7c20e98dce98864408282e51c7239e8e98a44256c1
3
+ size 1215973996
scheduler/.ipynb_checkpoints/scheduler_config-checkpoint.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "PNDMScheduler",
3
+ "_diffusers_paddle_version": "0.3.0",
4
+ "beta_end": 0.012,
5
+ "beta_schedule": "scaled_linear",
6
+ "beta_start": 0.00085,
7
+ "num_train_timesteps": 1000,
8
+ "skip_prk_steps": true,
9
+ "trained_betas": null
10
+ }
scheduler/scheduler_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "PNDMScheduler",
3
+ "_diffusers_paddle_version": "0.3.0",
4
+ "beta_end": 0.012,
5
+ "beta_schedule": "scaled_linear",
6
+ "beta_start": 0.00085,
7
+ "num_train_timesteps": 1000,
8
+ "skip_prk_steps": true,
9
+ "trained_betas": null
10
+ }
text_encoder/model_config.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "image_resolution": 224,
3
+ "vision_layers": 24,
4
+ "vision_heads": 16,
5
+ "vision_mlp_ratio": 4,
6
+ "vision_embed_dim": 1024,
7
+ "vision_patch_size": 14,
8
+ "vision_hidden_act": "quick_gelu",
9
+ "max_text_length": 77,
10
+ "vocab_size": 49408,
11
+ "text_embed_dim": 768,
12
+ "text_heads": 12,
13
+ "text_layers": 12,
14
+ "text_hidden_act": "quick_gelu",
15
+ "projection_dim": 768,
16
+ "initializer_range": 0.02,
17
+ "logit_scale_init_value": 2.6592,
18
+ "paddle_dtype": null,
19
+ "init_class": "CLIPTextModel"
20
+ }
text_encoder/model_state.pdparams ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:adf181e10a2bff61056a5343f9f96efed2a159c80aea429536af2531ceb23666
3
+ size 492264228
tokenizer/merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer/special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"bos_token": {"content": "<|startoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "eos_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "unk_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}, "pad_token": {"content": "<|endoftext|>", "single_word": false, "lstrip": false, "rstrip": false, "normalized": true}}
tokenizer/tokenizer_config.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"errors": "replace", "max_len": 77, "bos_token": "<|startoftext|>", "eos_token": "<|endoftext|>", "unk_token": "<|endoftext|>", "pad_token": "<|endoftext|>", "tokenizer_class": "CLIPTokenizer", "special_tokens_map_file": "./CompVis-stable-diffusion-v1-4-v1/tokenizer/special_tokens_map.json"}
tokenizer/vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
unet/.ipynb_checkpoints/config-checkpoint.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "UNet2DConditionModel",
3
+ "_diffusers_paddle_version": "0.3.0",
4
+ "_name_or_path": "./CompVis-stable-diffusion-v1-4-v1/unet",
5
+ "act_fn": "silu",
6
+ "attention_head_dim": 8,
7
+ "block_out_channels": [
8
+ 320,
9
+ 640,
10
+ 1280,
11
+ 1280
12
+ ],
13
+ "center_input_sample": false,
14
+ "cross_attention_dim": 768,
15
+ "down_block_types": [
16
+ "CrossAttnDownBlock2D",
17
+ "CrossAttnDownBlock2D",
18
+ "CrossAttnDownBlock2D",
19
+ "DownBlock2D"
20
+ ],
21
+ "downsample_padding": 1,
22
+ "flip_sin_to_cos": true,
23
+ "freq_shift": 0,
24
+ "in_channels": 4,
25
+ "layers_per_block": 2,
26
+ "mid_block_scale_factor": 1,
27
+ "norm_eps": 1e-05,
28
+ "norm_num_groups": 32,
29
+ "out_channels": 4,
30
+ "sample_size": 64,
31
+ "up_block_types": [
32
+ "UpBlock2D",
33
+ "CrossAttnUpBlock2D",
34
+ "CrossAttnUpBlock2D",
35
+ "CrossAttnUpBlock2D"
36
+ ]
37
+ }
unet/config.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "UNet2DConditionModel",
3
+ "_diffusers_paddle_version": "0.3.0",
4
+ "_name_or_path": "./CompVis-stable-diffusion-v1-4-v1/unet",
5
+ "act_fn": "silu",
6
+ "attention_head_dim": 8,
7
+ "block_out_channels": [
8
+ 320,
9
+ 640,
10
+ 1280,
11
+ 1280
12
+ ],
13
+ "center_input_sample": false,
14
+ "cross_attention_dim": 768,
15
+ "down_block_types": [
16
+ "CrossAttnDownBlock2D",
17
+ "CrossAttnDownBlock2D",
18
+ "CrossAttnDownBlock2D",
19
+ "DownBlock2D"
20
+ ],
21
+ "downsample_padding": 1,
22
+ "flip_sin_to_cos": true,
23
+ "freq_shift": 0,
24
+ "in_channels": 4,
25
+ "layers_per_block": 2,
26
+ "mid_block_scale_factor": 1,
27
+ "norm_eps": 1e-05,
28
+ "norm_num_groups": 32,
29
+ "out_channels": 4,
30
+ "sample_size": 64,
31
+ "up_block_types": [
32
+ "UpBlock2D",
33
+ "CrossAttnUpBlock2D",
34
+ "CrossAttnUpBlock2D",
35
+ "CrossAttnUpBlock2D"
36
+ ]
37
+ }
unet/model_state.pdparams ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f118e102131c24a5669d80ec059439d4044eb188c43acc658af302959c4caadd
3
+ size 3438161600
vae/config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "AutoencoderKL",
3
+ "_diffusers_paddle_version": "0.3.0",
4
+ "_name_or_path": "./CompVis-stable-diffusion-v1-4-v1/vae",
5
+ "act_fn": "silu",
6
+ "block_out_channels": [
7
+ 128,
8
+ 256,
9
+ 512,
10
+ 512
11
+ ],
12
+ "down_block_types": [
13
+ "DownEncoderBlock2D",
14
+ "DownEncoderBlock2D",
15
+ "DownEncoderBlock2D",
16
+ "DownEncoderBlock2D"
17
+ ],
18
+ "in_channels": 3,
19
+ "latent_channels": 4,
20
+ "layers_per_block": 2,
21
+ "out_channels": 3,
22
+ "sample_size": 512,
23
+ "up_block_types": [
24
+ "UpDecoderBlock2D",
25
+ "UpDecoderBlock2D",
26
+ "UpDecoderBlock2D",
27
+ "UpDecoderBlock2D"
28
+ ]
29
+ }
vae/model_state.pdparams ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:05e7872019afea4d24622b2d626fa4eb4bd23b2c652da1cd1510e1eda9aad71b
3
+ size 334641628