cq commited on
Commit
797cc55
1 Parent(s): 2ffd613

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +158 -0
README.md CHANGED
@@ -1,3 +1,161 @@
1
  ---
 
 
 
 
2
  license: openrail
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ thumbnail: >-
3
+ https://huggingface.co/OFA-Sys/small-stable-diffusion-v0/resolve/main/sample_images_compressed.jpg
4
+ datasets:
5
+ - ChristophSchuhmann/improved_aesthetics_6plus
6
  license: openrail
7
+ tags:
8
+ - stable-diffusion
9
+ - stable-diffusion-diffusers
10
+ - text-to-image
11
+ language:
12
+ - en
13
+ pipeline_tag: text-to-image
14
  ---
15
+
16
+ # Small Stable Diffusion Model Card
17
+
18
+ Similar image generation quality, but nearly 1/2 smaller!
19
+ Here are some samples:
20
+ ![Samples](https://huggingface.co/OFA-Sys/small-stable-diffusion-v0/resolve/main/sample_images_compressed.jpg)
21
+
22
+
23
+ ## Example
24
+
25
+ *Use `Diffusers` >=0.8.0, do not support lower versions.*
26
+
27
+ ```python
28
+ import torch
29
+ from diffusers import StableDiffusionPipeline
30
+
31
+
32
+ model_id = "OFA-Sys/small-stable-diffusion-v0/"
33
+ pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
34
+ pipe = pipe.to("cuda")
35
+
36
+ prompt = "a apple, 4k"
37
+ image = pipe(prompt).images[0]
38
+
39
+ image.save("apple.png")
40
+ ```
41
+
42
+ # Training
43
+
44
+ ### Initialization
45
+
46
+ This model is initialized from stable-diffusion v1-4. As the model structure is not the same as stable-diffusion and the number of parameters is smaller, the parameters of stable diffusion could not be utilized directly. Therefore, small stable diffusion set `layers_per_block=1` and select the first layer of each block in original stable diffusion to initilize the small model.
47
+
48
+ ### Training Procedure
49
+
50
+ After the initialization, the model have been trained for 1100k steps in 8xA100 GPUS. The training progress consists of three stages. The first stage is a simple pre-training precedure. In the last two stages, the original stable diffusion was utilized to distill knowledge to small model as a teacher model. In all stages, only the parameters in unet were trained and other parameters were frozen.
51
+
52
+
53
+ - **Hardware:** 8 x A100-80GB GPUs
54
+ - **Optimizer:** AdamW
55
+
56
+ - **Stage 1** - Pretrain the unet part of model.
57
+ - **Steps**: 500,000
58
+ - **Batch:** batch size=8, GPUs=8, Gradient Accumulations=2. Total batch size=128
59
+ - **Learning rate:** warmup to 1e-5 for 10,000 steps and then kept constant
60
+ - **Stage 2** - Distill the model using stable-diffusion v1-4 as the teacher. Besides the ground truth, the training in this stage uses the soft-label (`pred_noise`) generated by teacher model as well.
61
+ - **Steps**: 400,000
62
+ - **Batch:** batch size=8, GPUs=8, Gradient Accumulations=2. Total batch size=128
63
+ - **Learning rate:** warmup to 1e-5 for 5,000 steps and then kept constant
64
+ - **Soft label weight:** 0.5
65
+ - **Hard label weight:** 0.5
66
+ - **Stage 3** - Distill the model using stable-diffusion v1-5 as the teacher. Use several techniques in `Knowledge Distillation of Transformer-based Language Models Revisited`, including similarity-based layer match apart from soft label.
67
+ - **Steps**: 200,000
68
+ - **Batch:** batch size=8, GPUs=8, Gradient Accumulations=2. Total batch size=128
69
+ - **Learning rate:** warmup to 1e-5 for 5,000 steps and then kept constant
70
+ - **Softlabel weight:** 0.5
71
+ - **Hard label weight:** 0.5
72
+
73
+ ### Training Data
74
+ The model developers used the following dataset for training the model:
75
+ 1. [LAION-2B en aesthetic](https://huggingface.co/datasets/laion/laion2B-en-aesthetic)
76
+ 2. [LAION-Art](https://huggingface.co/datasets/laion/laion-art)
77
+ 3. [LAION-HD](https://huggingface.co/datasets/laion/laion-high-resolution)
78
+
79
+ ### Citation
80
+
81
+ ```bibtex
82
+ @article{Lu2022KnowledgeDO,
83
+ title={Knowledge Distillation of Transformer-based Language Models Revisited},
84
+ author={Chengqiang Lu and Jianwei Zhang and Yunfei Chu and Zhengyu Chen and Jingren Zhou and Fei Wu and Haiqing Chen and Hongxia Yang},
85
+ journal={ArXiv},
86
+ year={2022},
87
+ volume={abs/2206.14366}
88
+ }
89
+ ```
90
+
91
+ # Uses
92
+ _The following section is adapted from the [Stable Diffusion model card](https://huggingface.co/CompVis/stable-diffusion-v1-4)_
93
+
94
+ ## Direct Use
95
+ The model is intended for research purposes only. Possible research areas and
96
+ tasks include
97
+
98
+ - Safe deployment of models which have the potential to generate harmful content.
99
+ - Probing and understanding the limitations and biases of generative models.
100
+ - Generation of artworks and use in design and other artistic processes.
101
+ - Applications in educational or creative tools.
102
+ - Research on generative models.
103
+
104
+ Excluded uses are described below.
105
+
106
+ ### Misuse, Malicious Use, and Out-of-Scope Use
107
+
108
+ 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.
109
+
110
+ #### Out-of-Scope Use
111
+ 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.
112
+
113
+ #### Misuse and Malicious Use
114
+ Using the model to generate content that is cruel to individuals is a misuse of this model. This includes, but is not limited to:
115
+
116
+ - Generating demeaning, dehumanizing, or otherwise harmful representations of people or their environments, cultures, religions, etc.
117
+ - Intentionally promoting or propagating discriminatory content or harmful stereotypes.
118
+ - Impersonating individuals without their consent.
119
+ - Sexual content without consent of the people who might see it.
120
+ - Mis- and disinformation
121
+ - Representations of egregious violence and gore
122
+ - Sharing of copyrighted or licensed material in violation of its terms of use.
123
+ - Sharing content that is an alteration of copyrighted or licensed material in violation of its terms of use.
124
+
125
+ ## Limitations and Bias
126
+
127
+ ### Limitations
128
+
129
+ - The model does not achieve perfect photorealism
130
+ - The model cannot render legible text
131
+ - 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”
132
+ - Faces and people in general may not be generated properly.
133
+ - The model was trained mainly with English captions and will not work as well in other languages.
134
+ - The autoencoding part of the model is lossy
135
+ - The model was trained on a large-scale dataset
136
+ [LAION-5B](https://laion.ai/blog/laion-5b/) which contains adult material
137
+ and is not fit for product use without additional safety mechanisms and
138
+ considerations.
139
+ - 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.
140
+ 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.
141
+
142
+ ### Bias
143
+
144
+ While the capabilities of image generation models are impressive, they can also reinforce or exacerbate social biases.
145
+ Stable Diffusion v1 was trained on subsets of [LAION-2B(en)](https://laion.ai/blog/laion-5b/),
146
+ which consists of images that are primarily limited to English descriptions.
147
+ Texts and images from communities and cultures that use other languages are likely to be insufficiently accounted for.
148
+ This affects the overall output of the model, as white and western cultures are often set as the default. Further, the
149
+ ability of the model to generate content with non-English prompts is significantly worse than with English-language prompts.
150
+
151
+ ### Safety Module
152
+
153
+ 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.
154
+ This checker works by checking model outputs against known hard-coded NSFW concepts.
155
+ The concepts are intentionally hidden to reduce the likelihood of reverse-engineering this filter.
156
+ Specifically, the checker compares the class probability of harmful concepts in the embedding space of the `CLIPModel` *after generation* of the images.
157
+ The concepts are passed into the model with the generated image and compared to a hand-engineered weight for each NSFW concept.
158
+
159
+
160
+
161
+ *This model card was written by: Justin Pinkney and is based on the [Stable Diffusion model card](https://huggingface.co/CompVis/stable-diffusion-v1-4).*