Skip to content

Commit 2ff270f

Browse files
committed
stable diffusion
1 parent f13bf9b commit 2ff270f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3640
-186
lines changed

LICENSE

+6-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,14 @@
1-
MIT License
1+
All rights reserved by the authors.
2+
You must not distribute the weights provided to you directly or indirectly without explicit consent of the authors.
3+
You must not distribute harmful, offensive, dehumanizing content or otherwise harmful representations of people or their environments, cultures, religions, etc. produced with the model weights
4+
or other generated content described in the "Misuse and Malicious Use" section in the model card.
5+
The model weights are provided for research purposes only.
26

3-
Copyright (c) 2022 Machine Vision and Learning Group, LMU Munich
4-
5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
11-
12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
147

158
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
169
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1710
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1811
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1912
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2013
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
14+
SOFTWARE.

README.md

+105-144
Large diffs are not rendered by default.

Stable_Diffusion_v1_Model_Card.md

+140
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# Stable Diffusion v1 Model Card
2+
This model card focuses on the model associated with the Stable Diffusion model, available [here](https://github.com/CompVis/stable-diffusion).
3+
4+
## Model Details
5+
- **Developed by:** Robin Rombach, Patrick Esser
6+
- **Model type:** Diffusion-based text-to-image generation model
7+
- **Language(s):** English
8+
- **License:** [Proprietary](LICENSE)
9+
- **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).
10+
- **Resources for more information:** [GitHub Repository](https://github.com/CompVis/stable-diffusion), [Paper](https://arxiv.org/abs/2112.10752).
11+
- **Cite as:**
12+
13+
@InProceedings{Rombach_2022_CVPR,
14+
author = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj\"orn},
15+
title = {High-Resolution Image Synthesis With Latent Diffusion Models},
16+
booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
17+
month = {June},
18+
year = {2022},
19+
pages = {10684-10695}
20+
}
21+
22+
# Uses
23+
24+
## Direct Use
25+
The model is intended for research purposes only. Possible research areas and
26+
tasks include
27+
28+
- Safe deployment of models which have the potential to generate harmful content.
29+
- Probing and understanding the limitations and biases of generative models.
30+
- Generation of artworks and use in design and other artistic processes.
31+
- Applications in educational or creative tools.
32+
- Research on generative models.
33+
34+
Excluded uses are described below.
35+
36+
### Misuse, Malicious Use, and Out-of-Scope Use
37+
_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_.
38+
39+
40+
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.
41+
#### Out-of-Scope Use
42+
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.
43+
#### Misuse and Malicious Use
44+
Using the model to generate content that is cruel to individuals is a misuse of this model. This includes, but is not limited to:
45+
46+
- Generating demeaning, dehumanizing, or otherwise harmful representations of people or their environments, cultures, religions, etc.
47+
- Intentionally promoting or propagating discriminatory content or harmful stereotypes.
48+
- Impersonating individuals without their consent.
49+
- Sexual content without consent of the people who might see it.
50+
- Mis- and disinformation
51+
- Representations of egregious violence and gore
52+
- Sharing of copyrighted or licensed material in violation of its terms of use.
53+
- Sharing content that is an alteration of copyrighted or licensed material in violation of its terms of use.
54+
55+
## Limitations and Bias
56+
57+
### Limitations
58+
59+
- The model does not achieve perfect photorealism
60+
- The model cannot render legible text
61+
- 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”
62+
- Faces and people in general may not be generated properly.
63+
- The model was trained mainly with English captions and will not work as well in other languages.
64+
- The autoencoding part of the model is lossy
65+
- The model was trained on a large-scale dataset
66+
[LAION-5B](https://laion.ai/blog/laion-5b/) which contains adult material
67+
and is not fit for product use without additional safety mechanisms and
68+
considerations.
69+
70+
### Bias
71+
While the capabilities of image generation models are impressive, they can also reinforce or exacerbate social biases.
72+
Stable Diffusion v1 was trained on subsets of [LAION-2B(en)](https://laion.ai/blog/laion-5b/),
73+
which consists of images that are primarily limited to English descriptions.
74+
Texts and images from communities and cultures that use other languages are likely to be insufficiently accounted for.
75+
This affects the overall output of the model, as white and western cultures are often set as the default. Further, the
76+
ability of the model to generate content with non-English prompts is significantly worse than with English-language prompts.
77+
78+
79+
## Training
80+
81+
**Training Data**
82+
The model developers used the following dataset for training the model:
83+
84+
- LAION-2B (en) and subsets thereof (see next section)
85+
86+
**Training Procedure**
87+
Stable Diffusion v1 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,
88+
89+
- 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
90+
- Text prompts are encoded through a ViT-L/14 text-encoder.
91+
- The non-pooled output of the text encoder is fed into the UNet backbone of the latent diffusion model via cross-attention.
92+
- The loss is a reconstruction objective between the noise that was added to the latent and the prediction made by the UNet.
93+
94+
We currently provide three checkpoints, `sd-v1-1.ckpt`, `sd-v1-2.ckpt` and `sd-v1-3.ckpt`,
95+
which were trained as follows,
96+
97+
- `sd-v1-1.ckpt`: 237k steps at resolution `256x256` on [laion2B-en](https://huggingface.co/datasets/laion/laion2B-en).
98+
194k steps at resolution `512x512` on [laion-high-resolution](https://huggingface.co/datasets/laion/laion-high-resolution) (170M examples from LAION-5B with resolution `>= 1024x1024`).
99+
- `sd-v1-2.ckpt`: Resumed from `sd-v1-1.ckpt`.
100+
515k steps at resolution `512x512` on "laion-improved-aesthetics" (a subset of laion2B-en,
101+
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)).
102+
- `sd-v1-3.ckpt`: Resumed from `sd-v1-2.ckpt`. 195k 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).
103+
104+
105+
- **Hardware:** 32 x 8 x A100 GPUs
106+
- **Optimizer:** AdamW
107+
- **Gradient Accumulations**: 2
108+
- **Batch:** 32 x 8 x 2 x 4 = 2048
109+
- **Learning rate:** warmup to 0.0001 for 10,000 steps and then kept constant
110+
111+
## Evaluation Results
112+
Evaluations with different classifier-free guidance scales (1.5, 2.0, 3.0, 4.0,
113+
5.0, 6.0, 7.0, 8.0) and 50 PLMS sampling
114+
steps show the relative improvements of the checkpoints:
115+
116+
![pareto](assets/v1-variants-scores.jpg)
117+
118+
Evaluated using 50 PLMS steps and 10000 random prompts from the COCO2017 validation set, evaluated at 512x512 resolution. Not optimized for FID scores.
119+
## Environmental Impact
120+
121+
**Stable Diffusion v1** **Estimated Emissions**
122+
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.
123+
124+
- **Hardware Type:** A100 PCIe 40GB
125+
- **Hours used:** 150000
126+
- **Cloud Provider:** AWS
127+
- **Compute Region:** US-east
128+
- **Carbon Emitted (Power consumption x Time x Carbon produced based on location of power grid):** 11250 kg CO2 eq.
129+
## Citation
130+
@InProceedings{Rombach_2022_CVPR,
131+
author = {Rombach, Robin and Blattmann, Andreas and Lorenz, Dominik and Esser, Patrick and Ommer, Bj\"orn},
132+
title = {High-Resolution Image Synthesis With Latent Diffusion Models},
133+
booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR)},
134+
month = {June},
135+
year = {2022},
136+
pages = {10684-10695}
137+
}
138+
139+
*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).*
140+

assets/a-painting-of-a-fire.png

651 KB
Loading

assets/a-photograph-of-a-fire.png

596 KB
Loading
609 KB
Loading
547 KB
Loading
705 KB
Loading

assets/birdhouse.png

757 KB
Loading

assets/fire.png

612 KB
Loading

assets/rdm-preview.jpg

319 KB
Loading
610 KB
Loading
643 KB
Loading
641 KB
Loading
Loading
1.11 MB
Loading
1.26 MB
Loading
945 KB
Loading
972 KB
Loading
2.46 MB
Loading
2.52 MB
Loading
2.3 MB
Loading
663 KB
Loading

assets/txt2img-convsample.png

302 KB
Loading

assets/txt2img-preview.png

2.15 MB
Loading

assets/v1-variants-scores.jpg

69.6 KB
Loading
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
model:
2+
base_learning_rate: 0.0001
3+
target: ldm.models.diffusion.ddpm.LatentDiffusion
4+
params:
5+
linear_start: 0.0015
6+
linear_end: 0.0195
7+
num_timesteps_cond: 1
8+
log_every_t: 200
9+
timesteps: 1000
10+
first_stage_key: image
11+
cond_stage_key: class_label
12+
image_size: 64
13+
channels: 3
14+
cond_stage_trainable: true
15+
conditioning_key: crossattn
16+
monitor: val/loss
17+
use_ema: False
18+
19+
unet_config:
20+
target: ldm.modules.diffusionmodules.openaimodel.UNetModel
21+
params:
22+
image_size: 64
23+
in_channels: 3
24+
out_channels: 3
25+
model_channels: 192
26+
attention_resolutions:
27+
- 8
28+
- 4
29+
- 2
30+
num_res_blocks: 2
31+
channel_mult:
32+
- 1
33+
- 2
34+
- 3
35+
- 5
36+
num_heads: 1
37+
use_spatial_transformer: true
38+
transformer_depth: 1
39+
context_dim: 512
40+
41+
first_stage_config:
42+
target: ldm.models.autoencoder.VQModelInterface
43+
params:
44+
embed_dim: 3
45+
n_embed: 8192
46+
ddconfig:
47+
double_z: false
48+
z_channels: 3
49+
resolution: 256
50+
in_channels: 3
51+
out_ch: 3
52+
ch: 128
53+
ch_mult:
54+
- 1
55+
- 2
56+
- 4
57+
num_res_blocks: 2
58+
attn_resolutions: []
59+
dropout: 0.0
60+
lossconfig:
61+
target: torch.nn.Identity
62+
63+
cond_stage_config:
64+
target: ldm.modules.encoders.modules.ClassEmbedder
65+
params:
66+
n_classes: 1001
67+
embed_dim: 512
68+
key: class_label
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
model:
2+
base_learning_rate: 5.0e-05
3+
target: ldm.models.diffusion.ddpm.LatentDiffusion
4+
params:
5+
linear_start: 0.00085
6+
linear_end: 0.012
7+
num_timesteps_cond: 1
8+
log_every_t: 200
9+
timesteps: 1000
10+
first_stage_key: image
11+
cond_stage_key: caption
12+
image_size: 32
13+
channels: 4
14+
cond_stage_trainable: true
15+
conditioning_key: crossattn
16+
monitor: val/loss_simple_ema
17+
scale_factor: 0.18215
18+
use_ema: False
19+
20+
unet_config:
21+
target: ldm.modules.diffusionmodules.openaimodel.UNetModel
22+
params:
23+
image_size: 32
24+
in_channels: 4
25+
out_channels: 4
26+
model_channels: 320
27+
attention_resolutions:
28+
- 4
29+
- 2
30+
- 1
31+
num_res_blocks: 2
32+
channel_mult:
33+
- 1
34+
- 2
35+
- 4
36+
- 4
37+
num_heads: 8
38+
use_spatial_transformer: true
39+
transformer_depth: 1
40+
context_dim: 1280
41+
use_checkpoint: true
42+
legacy: False
43+
44+
first_stage_config:
45+
target: ldm.models.autoencoder.AutoencoderKL
46+
params:
47+
embed_dim: 4
48+
monitor: val/rec_loss
49+
ddconfig:
50+
double_z: true
51+
z_channels: 4
52+
resolution: 256
53+
in_channels: 3
54+
out_ch: 3
55+
ch: 128
56+
ch_mult:
57+
- 1
58+
- 2
59+
- 4
60+
- 4
61+
num_res_blocks: 2
62+
attn_resolutions: []
63+
dropout: 0.0
64+
lossconfig:
65+
target: torch.nn.Identity
66+
67+
cond_stage_config:
68+
target: ldm.modules.encoders.modules.BERTEmbedder
69+
params:
70+
n_embed: 1280
71+
n_layer: 32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
model:
2+
base_learning_rate: 0.0001
3+
target: ldm.models.diffusion.ddpm.LatentDiffusion
4+
params:
5+
linear_start: 0.0015
6+
linear_end: 0.015
7+
num_timesteps_cond: 1
8+
log_every_t: 200
9+
timesteps: 1000
10+
first_stage_key: jpg
11+
cond_stage_key: nix
12+
image_size: 48
13+
channels: 16
14+
cond_stage_trainable: false
15+
conditioning_key: crossattn
16+
monitor: val/loss_simple_ema
17+
scale_by_std: false
18+
scale_factor: 0.22765929
19+
unet_config:
20+
target: ldm.modules.diffusionmodules.openaimodel.UNetModel
21+
params:
22+
image_size: 48
23+
in_channels: 16
24+
out_channels: 16
25+
model_channels: 448
26+
attention_resolutions:
27+
- 4
28+
- 2
29+
- 1
30+
num_res_blocks: 2
31+
channel_mult:
32+
- 1
33+
- 2
34+
- 3
35+
- 4
36+
use_scale_shift_norm: false
37+
resblock_updown: false
38+
num_head_channels: 32
39+
use_spatial_transformer: true
40+
transformer_depth: 1
41+
context_dim: 768
42+
use_checkpoint: true
43+
first_stage_config:
44+
target: ldm.models.autoencoder.AutoencoderKL
45+
params:
46+
monitor: val/rec_loss
47+
embed_dim: 16
48+
ddconfig:
49+
double_z: true
50+
z_channels: 16
51+
resolution: 256
52+
in_channels: 3
53+
out_ch: 3
54+
ch: 128
55+
ch_mult:
56+
- 1
57+
- 1
58+
- 2
59+
- 2
60+
- 4
61+
num_res_blocks: 2
62+
attn_resolutions:
63+
- 16
64+
dropout: 0.0
65+
lossconfig:
66+
target: torch.nn.Identity
67+
cond_stage_config:
68+
target: torch.nn.Identity

0 commit comments

Comments
 (0)