{"id":13442214,"url":"https://github.com/openai/consistency_models","last_synced_at":"2025-05-14T10:06:21.561Z","repository":{"id":152622474,"uuid":"606926030","full_name":"openai/consistency_models","owner":"openai","description":"Official repo for consistency models.","archived":false,"fork":false,"pushed_at":"2024-03-22T06:56:31.000Z","size":59,"stargazers_count":6312,"open_issues_count":52,"forks_count":426,"subscribers_count":58,"default_branch":"main","last_synced_at":"2025-04-11T04:11:36.589Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-26T23:57:45.000Z","updated_at":"2025-04-09T11:08:54.000Z","dependencies_parsed_at":"2024-01-13T19:22:00.795Z","dependency_job_id":"43f91119-952d-480b-9086-a7e3ba440e4b","html_url":"https://github.com/openai/consistency_models","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openai%2Fconsistency_models","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openai%2Fconsistency_models/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openai%2Fconsistency_models/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openai%2Fconsistency_models/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openai","download_url":"https://codeload.github.com/openai/consistency_models/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254119472,"owners_count":22017951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T03:01:43.040Z","updated_at":"2025-05-14T10:06:21.516Z","avatar_url":"https://github.com/openai.png","language":"Python","funding_links":[],"categories":["Python","其他_机器视觉","Repos","Accelerate","Generative Models — Diffusion \u0026 Flow"],"sub_categories":["网络服务_其他"],"readme":"# Consistency Models\n\nThis repository contains the codebase for [Consistency Models](https://arxiv.org/abs/2303.01469), implemented using PyTorch for conducting large-scale experiments on ImageNet-64, LSUN Bedroom-256, and LSUN Cat-256. We have based our repository on [openai/guided-diffusion](https://github.com/openai/guided-diffusion), which was initially released under the MIT license. Our modifications have enabled support for consistency distillation, consistency training, as well as several sampling and editing algorithms discussed in the paper.\n\nThe repository for CIFAR-10 experiments is in JAX and can be found at [openai/consistency_models_cifar10](https://github.com/openai/consistency_models_cifar10).\n\n# Pre-trained models\n\nWe have released checkpoints for the main models in the paper. Before using these models, please review the corresponding [model card](model-card.md) to understand the intended use and limitations of these models.\n\nHere are the download links for each model checkpoint:\n\n * EDM on ImageNet-64: [edm_imagenet64_ema.pt](https://openaipublic.blob.core.windows.net/consistency/edm_imagenet64_ema.pt)\n * CD on ImageNet-64 with l2 metric: [cd_imagenet64_l2.pt](https://openaipublic.blob.core.windows.net/consistency/cd_imagenet64_l2.pt)\n * CD on ImageNet-64 with LPIPS metric: [cd_imagenet64_lpips.pt](https://openaipublic.blob.core.windows.net/consistency/cd_imagenet64_lpips.pt)\n * CT on ImageNet-64: [ct_imagenet64.pt](https://openaipublic.blob.core.windows.net/consistency/ct_imagenet64.pt)\n * EDM on LSUN Bedroom-256: [edm_bedroom256_ema.pt](https://openaipublic.blob.core.windows.net/consistency/edm_bedroom256_ema.pt)\n * CD on LSUN Bedroom-256 with l2 metric: [cd_bedroom256_l2.pt](https://openaipublic.blob.core.windows.net/consistency/cd_bedroom256_l2.pt)\n * CD on LSUN Bedroom-256 with LPIPS metric: [cd_bedroom256_lpips.pt](https://openaipublic.blob.core.windows.net/consistency/cd_bedroom256_lpips.pt)\n * CT on LSUN Bedroom-256: [ct_bedroom256.pt](https://openaipublic.blob.core.windows.net/consistency/ct_bedroom256.pt)\n * EDM on LSUN Cat-256: [edm_cat256_ema.pt](https://openaipublic.blob.core.windows.net/consistency/edm_cat256_ema.pt)\n * CD on LSUN Cat-256 with l2 metric: [cd_cat256_l2.pt](https://openaipublic.blob.core.windows.net/consistency/cd_cat256_l2.pt)\n * CD on LSUN Cat-256 with LPIPS metric: [cd_cat256_lpips.pt](https://openaipublic.blob.core.windows.net/consistency/cd_cat256_lpips.pt)\n * CT on LSUN Cat-256: [ct_cat256.pt](https://openaipublic.blob.core.windows.net/consistency/ct_cat256.pt)\n\n# Dependencies\n\nTo install all packages in this codebase along with their dependencies, run\n```sh\npip install -e .\n```\n\nTo install with Docker, run the following commands:\n```sh\ncd docker \u0026\u0026 make build \u0026\u0026 make run\n```\n\n# Model training and sampling\n\nWe provide examples of EDM training, consistency distillation, consistency training, single-step generation, and multistep generation in [scripts/launch.sh](scripts/launch.sh).\n\n# Evaluations\n\nTo compare different generative models, we use FID, Precision, Recall, and Inception Score. These metrics can all be calculated using batches of samples stored in `.npz` (numpy) files. One can evaluate samples with [cm/evaluations/evaluator.py](evaluations/evaluator.py) in the same way as described in [openai/guided-diffusion](https://github.com/openai/guided-diffusion), with reference dataset batches provided therein.\n\n## Use in 🧨 diffusers\n\nConsistency models are supported in [🧨 diffusers](https://github.com/huggingface/diffusers) via the [`ConsistencyModelPipeline` class](https://huggingface.co/docs/diffusers/main/en/api/pipelines/consistency_models). Below we provide an example:\n\n```python\nimport torch\n\nfrom diffusers import ConsistencyModelPipeline\n\ndevice = \"cuda\"\n# Load the cd_imagenet64_l2 checkpoint.\nmodel_id_or_path = \"openai/diffusers-cd_imagenet64_l2\"\npipe = ConsistencyModelPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)\npipe.to(device)\n\n# Onestep Sampling\nimage = pipe(num_inference_steps=1).images[0]\nimage.save(\"consistency_model_onestep_sample.png\")\n\n# Onestep sampling, class-conditional image generation\n# ImageNet-64 class label 145 corresponds to king penguins\n\nclass_id = 145\nclass_id = torch.tensor(class_id, dtype=torch.long)\n\nimage = pipe(num_inference_steps=1, class_labels=class_id).images[0]\nimage.save(\"consistency_model_onestep_sample_penguin.png\")\n\n# Multistep sampling, class-conditional image generation\n# Timesteps can be explicitly specified; the particular timesteps below are from the original Github repo.\n# https://github.com/openai/consistency_models/blob/main/scripts/launch.sh#L77\nimage = pipe(timesteps=[22, 0], class_labels=class_id).images[0]\nimage.save(\"consistency_model_multistep_sample_penguin.png\")\n```\nYou can further speed up the inference process by using `torch.compile()` on `pipe.unet` (only supported from PyTorch 2.0). For more details, please check out the [official documentation](https://huggingface.co/docs/diffusers/main/en/api/pipelines/consistency_models). This support was contributed to 🧨 diffusers by [dg845](https://github.com/dg845) and [ayushtues](https://github.com/ayushtues).\n\n# Citation\n\nIf you find this method and/or code useful, please consider citing\n\n```bibtex\n@article{song2023consistency,\n  title={Consistency Models},\n  author={Song, Yang and Dhariwal, Prafulla and Chen, Mark and Sutskever, Ilya},\n  journal={arXiv preprint arXiv:2303.01469},\n  year={2023},\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenai%2Fconsistency_models","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenai%2Fconsistency_models","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenai%2Fconsistency_models/lists"}