Yasunori Ozaki commited on
Commit
4b52363
1 Parent(s): 554444a

Replace VAE

Browse files
.gitattributes CHANGED
@@ -32,3 +32,8 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
 
 
 
 
32
  *.zip filter=lfs diff=lfs merge=lfs -text
33
  *.zst filter=lfs diff=lfs merge=lfs -text
34
  *tfevents* filter=lfs diff=lfs merge=lfs -text
35
+ text_encoder/pytorch_model.bin filter=lfs diff=lfs merge=lfs -text
36
+ unet/diffusion_pytorch_model.bin filter=lfs diff=lfs merge=lfs -text
37
+ vae/diffusion_pytorch_model.bin filter=lfs diff=lfs merge=lfs -text
38
+ astronaut_1024.png filter=lfs diff=lfs merge=lfs -text
39
+ astronaut_512.png filter=lfs diff=lfs merge=lfs -text
README.md CHANGED
@@ -1,3 +1,152 @@
1
  ---
2
  license: openrail++
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: openrail++
3
+ tags:
4
+ - stable-diffusion
5
+ - text-to-image
6
+ inference: false
7
  ---
8
+
9
+ # Stable Diffusion x2 latent upscaler model card
10
+
11
+ This model card focuses on the latent diffusion-based upscaler developed by [Katherine Crowson](https://github.com/crowsonkb/k-diffusion)
12
+ in collaboration with [Stability AI](https://stability.ai/).
13
+ This model was trained on a high-resolution subset of the LAION-2B dataset.
14
+ It is a diffusion model that operates in the same latent space as the Stable Diffusion model, which is decoded into a full-resolution image.
15
+ To use it with Stable Diffusion, You can take the generated latent from Stable Diffusion and pass it into the upscaler before decoding with your standard VAE.
16
+ Or you can take any image, encode it into the latent space, use the upscaler, and decode it.
17
+
18
+ **Note**:
19
+ This upscaling model is designed explicitely for **Stable Diffusion** as it can upscale Stable Diffusion's latent denoised image embeddings.
20
+ This allows for very fast text-to-image + upscaling pipelines as all intermeditate states can be kept on GPU. More for information, see example below.
21
+ This model works on all [Stable Diffusion checkpoints](https://huggingface.co/models?other=stable-diffusion)
22
+
23
+ | ![upscaler.jpg](https://pbs.twimg.com/media/FhK0YjAVUAUtBbx?format=jpg&name=4096x4096) |
24
+ |:--:|
25
+ Image by Tanishq Abraham from [Stability AI](https://stability.ai/) originating from [this tweet](https://twitter.com/StabilityAI/status/1590531958815064065)|
26
+
27
+ Original output image | 2x upscaled output image
28
+ :-------------------------:|:-------------------------:
29
+ ![](https://pbs.twimg.com/media/Fg8UijAaEAAqfvS?format=png&name=small) | ![](https://pbs.twimg.com/media/Fg8UjCmaMAAAUdS?format=jpg&name=medium)
30
+
31
+ - Use it with 🧨 [`diffusers`](https://huggingface.co/stabilityai/sd-x2-latent-upscaler#examples)
32
+
33
+
34
+ ## Model Details
35
+ - **Developed by:** Katherine Crowson
36
+ - **Model type:** Diffusion-based latent upscaler
37
+ - **Language(s):** English
38
+ - **License:** [CreativeML Open RAIL++-M License](https://huggingface.co/stabilityai/stable-diffusion-2/blob/main/LICENSE-MODEL)
39
+
40
+
41
+ ## Examples
42
+
43
+ Using the [🤗's Diffusers library](https://github.com/huggingface/diffusers) to run latent upscaler on top of any `StableDiffusionUpscalePipeline` checkpoint
44
+ to enhance its output image resolution by a factor of 2.
45
+
46
+ ```bash
47
+ pip install git+https://github.com/huggingface/diffusers.git
48
+ pip install transformers accelerate scipy safetensors
49
+ ```
50
+
51
+ ```python
52
+ from diffusers import StableDiffusionLatentUpscalePipeline, StableDiffusionPipeline
53
+ import torch
54
+
55
+ pipeline = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16)
56
+ pipeline.to("cuda")
57
+
58
+ upscaler = StableDiffusionLatentUpscalePipeline.from_pretrained("stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16)
59
+ upscaler.to("cuda")
60
+
61
+ prompt = "a photo of an astronaut high resolution, unreal engine, ultra realistic"
62
+ generator = torch.manual_seed(33)
63
+
64
+ # we stay in latent space! Let's make sure that Stable Diffusion returns the image
65
+ # in latent space
66
+ low_res_latents = pipeline(prompt, generator=generator, output_type="latent").images
67
+
68
+ upscaled_image = upscaler(
69
+ prompt=prompt,
70
+ image=low_res_latents,
71
+ num_inference_steps=20,
72
+ guidance_scale=0,
73
+ generator=generator,
74
+ ).images[0]
75
+
76
+ # Let's save the upscaled image under "upscaled_astronaut.png"
77
+ upscaled_image.save("astronaut_1024.png")
78
+
79
+ # as a comparison: Let's also save the low-res image
80
+ with torch.no_grad():
81
+ image = pipeline.decode_latents(low_res_latents)
82
+ image = pipeline.numpy_to_pil(image)[0]
83
+
84
+ image.save("astronaut_512.png")
85
+ ```
86
+
87
+ **Result**:
88
+
89
+ *512-res Astronaut*
90
+ ![ow_res](./astronaut_512.png)
91
+
92
+ *1024-res Astronaut*
93
+ ![upscaled](./astronaut_1024.png)
94
+
95
+ **Notes**:
96
+ - Despite not being a dependency, we highly recommend you to install [xformers](https://github.com/facebookresearch/xformers) for memory efficient attention (better performance)
97
+ - If you have low GPU RAM available, make sure to add a `pipe.enable_attention_slicing()` after sending it to `cuda` for less VRAM usage (to the cost of speed)
98
+
99
+ # Uses
100
+
101
+ ## Direct Use
102
+ The model is intended for research purposes only. Possible research areas and tasks include
103
+
104
+ - Safe deployment of models which have the potential to generate harmful content.
105
+ - Probing and understanding the limitations and biases of generative models.
106
+ - Generation of artworks and use in design and other artistic processes.
107
+ - Applications in educational or creative tools.
108
+ - Research on generative models.
109
+
110
+ Excluded uses are described below.
111
+
112
+ ### Misuse, Malicious Use, and Out-of-Scope Use
113
+ _Note: This section is originally taken from the [DALLE-MINI model card](https://huggingface.co/dalle-mini/dalle-mini), was used for Stable Diffusion v1, but applies in the same way to Stable Diffusion v2_.
114
+
115
+ 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.
116
+
117
+ #### Out-of-Scope Use
118
+ 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.
119
+
120
+ #### Misuse and Malicious Use
121
+ Using the model to generate content that is cruel to individuals is a misuse of this model. This includes, but is not limited to:
122
+
123
+ - Generating demeaning, dehumanizing, or otherwise harmful representations of people or their environments, cultures, religions, etc.
124
+ - Intentionally promoting or propagating discriminatory content or harmful stereotypes.
125
+ - Impersonating individuals without their consent.
126
+ - Sexual content without consent of the people who might see it.
127
+ - Mis- and disinformation
128
+ - Representations of egregious violence and gore
129
+ - Sharing of copyrighted or licensed material in violation of its terms of use.
130
+ - Sharing content that is an alteration of copyrighted or licensed material in violation of its terms of use.
131
+
132
+ ## Limitations and Bias
133
+
134
+ ### Limitations
135
+
136
+ - The model does not achieve perfect photorealism
137
+ - The model cannot render legible text
138
+ - 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”
139
+ - Faces and people in general may not be generated properly.
140
+ - The model was trained mainly with English captions and will not work as well in other languages.
141
+ - The autoencoding part of the model is lossy
142
+ - The model was trained on a subset of the large-scale dataset
143
+ [LAION-5B](https://laion.ai/blog/laion-5b/), which contains adult, violent and sexual content. To partially mitigate this, we have filtered the dataset using LAION's NFSW detector (see Training section).
144
+
145
+ ### Bias
146
+ While the capabilities of image generation models are impressive, they can also reinforce or exacerbate social biases.
147
+ Stable Diffusion vw was primarily trained on subsets of [LAION-2B(en)](https://laion.ai/blog/laion-5b/),
148
+ which consists of images that are limited to English descriptions.
149
+ Texts and images from communities and cultures that use other languages are likely to be insufficiently accounted for.
150
+ This affects the overall output of the model, as white and western cultures are often set as the default. Further, the
151
+ ability of the model to generate content with non-English prompts is significantly worse than with English-language prompts.
152
+ Stable Diffusion v2 mirrors and exacerbates biases to such a degree that viewer discretion must be advised irrespective of the input or its intent.
astronaut_1024.png ADDED

Git LFS Details

  • SHA256: 13eed83062bceaf88c8bde6988b0359104ebfc326350c7b67a97176ff20f59a6
  • Pointer size: 132 Bytes
  • Size of remote file: 1.58 MB
astronaut_512.png ADDED

Git LFS Details

  • SHA256: 6cfa17d6f29705958de7ab67b39673f03abd68c97de1064ed076b8752375a18c
  • Pointer size: 131 Bytes
  • Size of remote file: 429 kB
model_index.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "StableDiffusionLatentUpscalePipeline",
3
+ "_diffusers_version": "0.13.0.dev0",
4
+ "scheduler": [
5
+ "diffusers",
6
+ "EulerDiscreteScheduler"
7
+ ],
8
+ "text_encoder": [
9
+ "transformers",
10
+ "CLIPTextModel"
11
+ ],
12
+ "tokenizer": [
13
+ "transformers",
14
+ "CLIPTokenizer"
15
+ ],
16
+ "unet": [
17
+ "diffusers",
18
+ "UNet2DConditionModel"
19
+ ],
20
+ "vae": [
21
+ "diffusers",
22
+ "AutoencoderKL"
23
+ ]
24
+ }
scheduler/scheduler_config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "EulerDiscreteScheduler",
3
+ "_diffusers_version": "0.13.0.dev0",
4
+ "beta_end": 0.012,
5
+ "beta_schedule": "scaled_linear",
6
+ "beta_start": 0.00085,
7
+ "num_train_timesteps": 1000,
8
+ "interpolation_type": "log_linear",
9
+ "prediction_type": "original_sample",
10
+ "trained_betas": null
11
+ }
text_encoder/config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/home/patrick_huggingface_co/latent-upscaler/text_encoder",
3
+ "architectures": [
4
+ "CLIPTextModel"
5
+ ],
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": 0,
8
+ "dropout": 0.0,
9
+ "eos_token_id": 2,
10
+ "hidden_act": "quick_gelu",
11
+ "hidden_size": 768,
12
+ "initializer_factor": 1.0,
13
+ "initializer_range": 0.02,
14
+ "intermediate_size": 3072,
15
+ "layer_norm_eps": 1e-05,
16
+ "max_position_embeddings": 77,
17
+ "model_type": "clip_text_model",
18
+ "num_attention_heads": 12,
19
+ "num_hidden_layers": 12,
20
+ "pad_token_id": 1,
21
+ "projection_dim": 768,
22
+ "torch_dtype": "float32",
23
+ "transformers_version": "4.27.0.dev0",
24
+ "vocab_size": 49408
25
+ }
text_encoder/pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:98124f3d5663b2f14ff08d4c29db93800622b4fcfa3d952bb6f9112f5d6dadd7
3
+ size 492307041
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,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "<|startoftext|>",
4
+ "lstrip": false,
5
+ "normalized": true,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "eos_token": {
10
+ "content": "<|endoftext|>",
11
+ "lstrip": false,
12
+ "normalized": true,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "pad_token": "<|endoftext|>",
17
+ "unk_token": {
18
+ "content": "<|endoftext|>",
19
+ "lstrip": false,
20
+ "normalized": true,
21
+ "rstrip": false,
22
+ "single_word": false
23
+ }
24
+ }
tokenizer/tokenizer_config.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "bos_token": {
4
+ "__type": "AddedToken",
5
+ "content": "<|startoftext|>",
6
+ "lstrip": false,
7
+ "normalized": true,
8
+ "rstrip": false,
9
+ "single_word": false
10
+ },
11
+ "do_lower_case": true,
12
+ "eos_token": {
13
+ "__type": "AddedToken",
14
+ "content": "<|endoftext|>",
15
+ "lstrip": false,
16
+ "normalized": true,
17
+ "rstrip": false,
18
+ "single_word": false
19
+ },
20
+ "errors": "replace",
21
+ "model_max_length": 77,
22
+ "name_or_path": "/home/patrick_huggingface_co/latent-upscaler/tokenizer",
23
+ "pad_token": "<|endoftext|>",
24
+ "special_tokens_map_file": "./special_tokens_map.json",
25
+ "tokenizer_class": "CLIPTokenizer",
26
+ "unk_token": {
27
+ "__type": "AddedToken",
28
+ "content": "<|endoftext|>",
29
+ "lstrip": false,
30
+ "normalized": true,
31
+ "rstrip": false,
32
+ "single_word": false
33
+ }
34
+ }
tokenizer/vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
unet/config.json ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "UNet2DConditionModel",
3
+ "_diffusers_version": "0.13.0.dev0",
4
+ "_name_or_path": "/home/patrick_huggingface_co/latent-upscaler/unet",
5
+ "act_fn": "gelu",
6
+ "attention_head_dim": 64,
7
+ "block_out_channels": [
8
+ 384,
9
+ 384,
10
+ 768,
11
+ 768
12
+ ],
13
+ "center_input_sample": false,
14
+ "class_embed_type": null,
15
+ "conv_in_kernel": 1,
16
+ "conv_out_kernel": 1,
17
+ "cross_attention_dim": 768,
18
+ "down_block_types": [
19
+ "KDownBlock2D",
20
+ "KCrossAttnDownBlock2D",
21
+ "KCrossAttnDownBlock2D",
22
+ "KCrossAttnDownBlock2D"
23
+ ],
24
+ "downsample_padding": 1,
25
+ "dual_cross_attention": false,
26
+ "flip_sin_to_cos": true,
27
+ "freq_shift": 0,
28
+ "in_channels": 8,
29
+ "layers_per_block": 4,
30
+ "mid_block_scale_factor": 1,
31
+ "mid_block_type": null,
32
+ "norm_eps": 1e-05,
33
+ "norm_num_groups": null,
34
+ "num_class_embeds": null,
35
+ "only_cross_attention": false,
36
+ "out_channels": 5,
37
+ "resnet_time_scale_shift": "scale_shift",
38
+ "sample_size": null,
39
+ "time_cond_proj_dim": 896,
40
+ "time_embedding_type": "fourier",
41
+ "timestep_post_act": "gelu",
42
+ "up_block_types": [
43
+ "KCrossAttnUpBlock2D",
44
+ "KCrossAttnUpBlock2D",
45
+ "KCrossAttnUpBlock2D",
46
+ "KUpBlock2D"
47
+ ],
48
+ "upcast_attention": false,
49
+ "use_linear_projection": false
50
+ }
unet/diffusion_pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3b3cb6a12cfb382e72401ffd26a4a4acc700d1b41bea038509b5eb9e6fbfae7d
3
+ size 1490494675
vae/config.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "AutoencoderKL",
3
+ "_diffusers_version": "0.13.0.dev0",
4
+ "_name_or_path": "/home/patrick_huggingface_co/latent-upscaler/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
+ "norm_num_groups": 32,
22
+ "out_channels": 3,
23
+ "sample_size": 256,
24
+ "scaling_factor": 0.18215,
25
+ "up_block_types": [
26
+ "UpDecoderBlock2D",
27
+ "UpDecoderBlock2D",
28
+ "UpDecoderBlock2D",
29
+ "UpDecoderBlock2D"
30
+ ]
31
+ }
vae/diffusion_pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:26a1bc4df64d4da1dae6081472367df75f88624602f966c8493cdb673bfed921
3
+ size 334707217