patrickvonplaten commited on
Commit
c3795c9
0 Parent(s):

Duplicate from openai/consistency-model-pipelines

Browse files
.gitattributes ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tflite filter=lfs diff=lfs merge=lfs -text
29
+ *.tgz filter=lfs diff=lfs merge=lfs -text
30
+ *.wasm filter=lfs diff=lfs merge=lfs -text
31
+ *.xz 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
README.md ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - generative model
5
+ - unconditional image generation
6
+ - consistency-model
7
+ duplicated_from: openai/consistency-model-pipelines
8
+ ---
9
+
10
+ **Disclaimer**: This model was added by the amazing community contributor [dg845](https://huggingface.co/dg845) ❤️
11
+
12
+ Consistency models are a new class of generative models introduced in ["Consistency Models"](https://arxiv.org/abs/2303.01469) ([paper](https://arxiv.org/pdf/2303.01469.pdf), [code](https://github.com/openai/consistency_models)) by Yang Song, Prafulla Dhariwal, Mark Chen, and Ilya Sutskever.
13
+ From the paper abstract:
14
+
15
+ > Diffusion models have significantly advanced the fields of image, audio, and video generation, but
16
+ they depend on an iterative sampling process that causes slow generation. To overcome this limitation,
17
+ we propose consistency models, a new family of models that generate high quality samples by directly
18
+ mapping noise to data. They support fast one-step generation by design, while still allowing multistep
19
+ sampling to trade compute for sample quality. They also support zero-shot data editing, such as image
20
+ inpainting, colorization, and super-resolution, without requiring explicit training on these tasks.
21
+ Consistency models can be trained either by distilling pre-trained diffusion models, or as standalone
22
+ generative models altogether. Through extensive experiments, we demonstrate that they outperform
23
+ existing distillation techniques for diffusion models in one- and few-step sampling, achieving the new
24
+ state-of-the-art FID of 3.55 on CIFAR-10 and 6.20 on ImageNet 64 x 64 for one-step generation. When
25
+ trained in isolation, consistency models become a new family of generative models that can outperform
26
+ existing one-step, non-adversarial generative models on standard benchmarks such as CIFAR-10, ImageNet
27
+ 64 x 64 and LSUN 256 x 256.
28
+
29
+ Intuitively, a consistency model can be thought of as a model which, when evaluated on a noisy image and timestep, returns an output image sample similar to that which would be returned by running a sampling algorithm on a diffusion model.
30
+ Consistency models can be parameterized by any neural network whose input has the same dimensionality as its output, such as a U-Net.
31
+
32
+ More precisely, given a teacher diffusion model and fixed sampler, we can train ("distill") a consistency model such that when it is given a noisy image and its corresponding timestep, the output sample of the consistency model will be close to the output that would result by using the sampler on the diffusion model to produce a sample, starting at the same noisy image and timestep.
33
+ The authors call this procedure "consistency distillation (CD)".
34
+ Consistency models can also be trained from scratch to generate clean images from a noisy image and timestep, which the authors call "consistency training (CT)".
35
+
36
+ This model is a `diffusers`-compatible version of the [cd_imagenet64_l2.pt](https://github.com/openai/consistency_models#pre-trained-models) checkpont from the [original code and model release](https://github.com/openai/consistency_models).
37
+ This model was distilled (via consistency distillation (CD)) from an [EDM model](https://arxiv.org/pdf/2206.00364.pdf) trained on the ImageNet 64x64 dataset, using the [L2 distance](https://en.wikipedia.org/wiki/Norm_(mathematics)#Euclidean_norm) as the measure of closeness.
38
+ See the [original model card](https://github.com/openai/consistency_models/blob/main/model-card.md) for more information.
39
+
40
+ ## Download
41
+
42
+ The original PyTorch model checkpoint can be downloaded from the [original code and model release](https://github.com/openai/consistency_models#pre-trained-models).
43
+
44
+ The `diffusers` pipeline for the `cd-imagenet64-l2` model can be downloaded as follows:
45
+
46
+ ```python
47
+ from diffusers import ConsistencyModelPipeline
48
+
49
+ pipe = ConsistencyModelPipeline.from_pretrained("openai/consistency-model-pipelines")
50
+ ```
51
+
52
+ ## Usage
53
+
54
+ The original model checkpoint can be used with the [original consistency models codebase](https://github.com/openai/consistency_models).
55
+
56
+ Here is an example of using the `cd-imagenet64-l2` checkpoint with `diffusers`:
57
+
58
+ ```python
59
+ import torch
60
+
61
+ from diffusers import ConsistencyModelPipeline
62
+
63
+ device = "cuda"
64
+ # Load the cd_imagenet64_l2 checkpoint.
65
+ model_id_or_path = "openai/consistency-model-pipelines"
66
+ pipe = ConsistencyModelPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
67
+ pipe.to(device)
68
+
69
+ # Onestep Sampling
70
+ image = pipe(num_inference_steps=1).images[0]
71
+ image.save("cd_imagenet64_l2_onestep_sample.png")
72
+
73
+ # Onestep sampling, class-conditional image generation
74
+ # ImageNet-64 class label 145 corresponds to king penguins
75
+ image = pipe(num_inference_steps=1, class_labels=145).images[0]
76
+ image.save("cd_imagenet64_l2_onestep_sample_penguin.png")
77
+
78
+ # Multistep sampling, class-conditional image generation
79
+ # Timesteps can be explicitly specified; the particular timesteps below are from the original Github repo:
80
+ # https://github.com/openai/consistency_models/blob/main/scripts/launch.sh#L77
81
+ image = pipe(num_inference_steps=None, timesteps=[22, 0], class_labels=145).images[0]
82
+ image.save("cd_imagenet64_l2_multistep_sample_penguin.png")
83
+ ```
84
+
85
+ ## Model Details
86
+ - **Model type:** Consistency model unconditional image generation model, distilled from a diffusion model
87
+ - **Dataset:** ImageNet 64x64
88
+ - **License:** MIT
89
+ - **Model Description:** This model performs unconditional image generation. Its main component is a U-Net, which parameterizes the consistency model. This model was distilled by the Consistency Model authors from an EDM diffusion model, also originally trained by the authors.
90
+ - **Resources for more information:**: [Paper](https://arxiv.org/abs/2303.01469), [GitHub Repository](https://github.com/openai/consistency_models), [Original Model Card](/openai/consistency_models/blob/main/model-card.md)
91
+
92
+ ## Datasets
93
+
94
+ _Note: This section is taken from the ["Datasets" section of the original model card](https://github.com/openai/consistency_models/blob/main/model-card.md#datasets)_.
95
+
96
+ The models that we are making available have been trained on the [ILSVRC 2012 subset of ImageNet](http://www.image-net.org/challenges/LSVRC/2012/) or on individual categories from [LSUN](https://arxiv.org/abs/1506.03365). Here we outline the characteristics of these datasets that influence the behavior of the models:
97
+
98
+ **ILSVRC 2012 subset of ImageNet**: This dataset was curated in 2012 and has around a million pictures, each of which belongs to one of 1,000 categories. A significant number of the categories in this dataset are animals, plants, and other naturally occurring objects. Although many photographs include humans, these humans are typically not represented by the class label (for example, the category "Tench, tinca tinca" includes many photographs of individuals holding fish).
99
+
100
+ **LSUN**: This dataset was collected in 2015 by a combination of human labeling via Amazon Mechanical Turk and automated data labeling. Both classes that we consider have more than a million images. The dataset creators discovered that when assessed by trained experts, the label accuracy was approximately 90% throughout the entire LSUN dataset. The pictures are gathered from the internet, and those in the cat class often follow a "meme" format. Occasionally, people, including faces, appear in these photographs.
101
+
102
+ ## Performance
103
+
104
+ _Note: This section is taken from the ["Performance" section of the original model card](https://github.com/openai/consistency_models/blob/main/model-card.md#performance)_.
105
+
106
+ These models are intended to generate samples consistent with their training distributions.
107
+ This has been measured in terms of FID, Inception Score, Precision, and Recall.
108
+ These metrics all rely on the representations of a [pre-trained Inception-V3 model](https://arxiv.org/abs/1512.00567),
109
+ which was trained on ImageNet, and so is likely to focus more on the ImageNet classes (such as animals) than on other visual features (such as human faces).
110
+
111
+ ## Intended Use
112
+
113
+ _Note: This section is taken from the ["Intended Use" section of the original model card](https://github.com/openai/consistency_models/blob/main/model-card.md#intended-use)_.
114
+
115
+ These models are intended to be used for research purposes only. In particular, they can be used as a baseline for generative modeling research, or as a starting point for advancing such research. These models are not intended to be commercially deployed. Additionally, they are not intended to be used to create propaganda or offensive imagery.
116
+
117
+ ## Limitations
118
+
119
+ _Note: This section is taken from the ["Limitations" section of the original model card](https://github.com/openai/consistency_models/blob/main/model-card.md#limitations)_.
120
+
121
+ These models sometimes produce highly unrealistic outputs, particularly when generating images containing human faces.
122
+ This may stem from ImageNet's emphasis on non-human objects.
123
+
124
+ In consistency distillation and training, minimizing LPIPS results in better sample quality, as evidenced by improved FID and Inception scores. However, it also carries the risk of overestimating model performance, because LPIPS uses a VGG network pre-trained on ImageNet, while FID and Inception scores also rely on convolutional neural networks (the Inception network in particular) pre-trained on the same ImageNet dataset. Although these two convolutional neural networks do not share the same architecture and we extract latents from them in substantially different ways, knowledge leakage is still plausible which can undermine the fidelity of FID and Inception scores.
125
+
126
+ Because ImageNet and LSUN contain images from the internet, they include photos of real people, and the model may have memorized some of the information contained in these photos. However, these images are already publicly available, and existing generative models trained on ImageNet have not demonstrated significant leakage of this information.
127
+
model_index.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "ConsistencyModelPipeline",
3
+ "_diffusers_version": "0.17.0.dev0",
4
+ "scheduler": [
5
+ "diffusers",
6
+ "CMStochasticIterativeScheduler"
7
+ ],
8
+ "unet": [
9
+ "diffusers",
10
+ "UNet2DModel"
11
+ ]
12
+ }
scheduler/scheduler_config.json ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "CMStochasticIterativeScheduler",
3
+ "_diffusers_version": "0.17.0.dev0",
4
+ "clip_denoised": true,
5
+ "num_train_timesteps": 40,
6
+ "rho": 7.0,
7
+ "s_noise": 1.0,
8
+ "sigma_data": 0.5,
9
+ "sigma_max": 80.0,
10
+ "sigma_min": 0.002
11
+ }
unet/config.json ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "UNet2DModel",
3
+ "_diffusers_version": "0.17.0.dev0",
4
+ "_name_or_path": "ayushtues/consistency_models",
5
+ "act_fn": "silu",
6
+ "add_attention": true,
7
+ "attention_head_dim": 64,
8
+ "block_out_channels": [
9
+ 192,
10
+ 384,
11
+ 576,
12
+ 768
13
+ ],
14
+ "center_input_sample": false,
15
+ "class_embed_type": null,
16
+ "down_block_types": [
17
+ "ResnetDownsampleBlock2D",
18
+ "AttnDownsampleBlock2D",
19
+ "AttnDownsampleBlock2D",
20
+ "AttnDownsampleBlock2D"
21
+ ],
22
+ "downsample_padding": 1,
23
+ "flip_sin_to_cos": true,
24
+ "freq_shift": 0,
25
+ "in_channels": 3,
26
+ "layers_per_block": 3,
27
+ "mid_block_scale_factor": 1,
28
+ "norm_eps": 1e-05,
29
+ "norm_num_groups": 32,
30
+ "num_class_embeds": 1000,
31
+ "out_channels": 3,
32
+ "resnet_time_scale_shift": "scale_shift",
33
+ "sample_size": 64,
34
+ "time_embedding_type": "positional",
35
+ "up_block_types": [
36
+ "AttnUpsampleBlock2D",
37
+ "AttnUpsampleBlock2D",
38
+ "AttnUpsampleBlock2D",
39
+ "ResnetUpsampleBlock2D"
40
+ ]
41
+ }
unet/diffusion_pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:26810cf35758bdb4be69af55547a43ba0eff229a08b5d8addb80390b7736fd58
3
+ size 1183833415