Home

Awesome

<p align="center"> <br> <img src="./docs/source/en/imgs/diffusers_library.jpg" width="400"/> <br> <p> <p align="center"> <a href="https://github.com/huggingface/diffusers/blob/main/LICENSE"> <img alt="GitHub" src="https://img.shields.io/github/license/huggingface/datasets.svg?color=blue"> </a> <a href="https://github.com/huggingface/diffusers/releases"> <img alt="GitHub release" src="https://img.shields.io/github/release/huggingface/diffusers.svg"> </a> <a href="CODE_OF_CONDUCT.md"> <img alt="Contributor Covenant" src="https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg"> </a> </p>

🤗 Diffusers is the go-to library for state-of-the-art pretrained diffusion models for generating images, audio, and even 3D structures of molecules. Whether you're looking for a simple inference solution or training your own diffusion models, 🤗 Diffusers is a modular toolbox that supports both. Our library is designed with a focus on usability over performance, simple over easy, and customizability over abstractions.

🤗 Diffusers offers three core components:

Installation

We recommend installing 🤗 Diffusers in a virtual environment from PyPi or Conda. For more details about installing PyTorch and Flax, please refer to their official documentation.

PyTorch

With pip (official package):

pip install --upgrade diffusers[torch]

With conda (maintained by the community):

conda install -c conda-forge diffusers

Flax

With pip (official package):

pip install --upgrade diffusers[flax]

Apple Silicon (M1/M2) support

Please refer to the How to use Stable Diffusion in Apple Silicon guide.

Quickstart

Generating outputs is super easy with 🤗 Diffusers. To generate an image from text, use the from_pretrained method to load any pretrained diffusion model (browse the Hub for 4000+ checkpoints):

from diffusers import DiffusionPipeline

pipeline = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5")
pipeline.to("cuda")
pipeline("An image of a squirrel in Picasso style").images[0]

You can also dig into the models and schedulers toolbox to build your own diffusion system:

from diffusers import DDPMScheduler, UNet2DModel
from PIL import Image
import torch
import numpy as np

scheduler = DDPMScheduler.from_pretrained("google/ddpm-cat-256")
model = UNet2DModel.from_pretrained("google/ddpm-cat-256").to("cuda")
scheduler.set_timesteps(50)

sample_size = model.config.sample_size
noise = torch.randn((1, 3, sample_size, sample_size)).to("cuda")
input = noise

for t in scheduler.timesteps:
    with torch.no_grad():
        noisy_residual = model(input, t).sample
        prev_noisy_sample = scheduler.step(noisy_residual, t, input).prev_sample
        input = prev_noisy_sample

image = (input / 2 + 0.5).clamp(0, 1)
image = image.cpu().permute(0, 2, 3, 1).numpy()[0]
image = Image.fromarray((image * 255).round().astype("uint8"))
image

Check out the Quickstart to launch your diffusion journey today!

How to navigate the documentation

DocumentationWhat can I learn?
TutorialA basic crash course for learning how to use the library's most important features like using models and schedulers to build your own diffusion system, and training your own diffusion model.
LoadingGuides for how to load and configure all the components (pipelines, models, and schedulers) of the library, as well as how to use different schedulers.
Pipelines for inferenceGuides for how to use pipelines for different inference tasks, batched generation, controlling generated outputs and randomness, and how to contribute a pipeline to the library.
OptimizationGuides for how to optimize your diffusion model to run faster and consume less memory.
TrainingGuides for how to train a diffusion model for different tasks with different training techniques.

Supported pipelines

PipelinePaperTasks
alt_diffusionAltDiffusionImage-to-Image Text-Guided Generation
audio_diffusionAudio DiffusionUnconditional Audio Generation
controlnetControlNet with Stable DiffusionImage-to-Image Text-Guided Generation
cycle_diffusionCycle DiffusionImage-to-Image Text-Guided Generation
dance_diffusionDance DiffusionUnconditional Audio Generation
ddpmDenoising Diffusion Probabilistic ModelsUnconditional Image Generation
ddimDenoising Diffusion Implicit ModelsUnconditional Image Generation
latent_diffusionHigh-Resolution Image Synthesis with Latent Diffusion ModelsText-to-Image Generation
latent_diffusionHigh-Resolution Image Synthesis with Latent Diffusion ModelsSuper Resolution Image-to-Image
latent_diffusion_uncondHigh-Resolution Image Synthesis with Latent Diffusion ModelsUnconditional Image Generation
paint_by_examplePaint by Example: Exemplar-based Image Editing with Diffusion ModelsImage-Guided Image Inpainting
pndmPseudo Numerical Methods for Diffusion Models on ManifoldsUnconditional Image Generation
score_sde_veScore-Based Generative Modeling through Stochastic Differential EquationsUnconditional Image Generation
score_sde_vpScore-Based Generative Modeling through Stochastic Differential EquationsUnconditional Image Generation
semantic_stable_diffusionSemantic GuidanceText-Guided Generation
stable_diffusion_text2imgStable DiffusionText-to-Image Generation
stable_diffusion_img2imgStable DiffusionImage-to-Image Text-Guided Generation
stable_diffusion_inpaintStable DiffusionText-Guided Image Inpainting
stable_diffusion_panoramaMultiDiffusionText-to-Panorama Generation
stable_diffusion_pix2pixInstructPix2PixText-Guided Image Editing
stable_diffusion_pix2pix_zeroZero-shot Image-to-Image TranslationText-Guided Image Editing
stable_diffusion_attend_and_exciteAttend and Excite for Stable DiffusionText-to-Image Generation
stable_diffusion_self_attention_guidanceSelf-Attention GuidanceText-to-Image Generation
stable_diffusion_image_variationStable Diffusion Image VariationsImage-to-Image Generation
stable_diffusion_latent_upscaleStable Diffusion Latent UpscalerText-Guided Super Resolution Image-to-Image
stable_diffusion_2Stable Diffusion 2Text-to-Image Generation
stable_diffusion_2Stable Diffusion 2Text-Guided Image Inpainting
stable_diffusion_2Depth-Conditional Stable DiffusionDepth-to-Image Generation
stable_diffusion_2Stable Diffusion 2Text-Guided Super Resolution Image-to-Image
stable_diffusion_safeSafe Stable DiffusionText-Guided Generation
stable_unclipStable unCLIPText-to-Image Generation
stable_unclipStable unCLIPImage-to-Image Text-Guided Generation
stochastic_karras_veElucidating the Design Space of Diffusion-Based Generative ModelsUnconditional Image Generation
unclipHierarchical Text-Conditional Image Generation with CLIP LatentsText-to-Image Generation
versatile_diffusionVersatile Diffusion: Text, Images and Variations All in One Diffusion ModelText-to-Image Generation
versatile_diffusionVersatile Diffusion: Text, Images and Variations All in One Diffusion ModelImage Variations Generation
versatile_diffusionVersatile Diffusion: Text, Images and Variations All in One Diffusion ModelDual Image and Text Guided Generation
vq_diffusionVector Quantized Diffusion Model for Text-to-Image SynthesisText-to-Image Generation

Contribution

We ❤️ contributions from the open-source community! If you want to contribute to this library, please check out our Contribution guide. You can look out for issues you'd like to tackle to contribute to the library.

Also, say 👋 in our public Discord channel <a href="https://discord.gg/G7tWnz98XR"><img alt="Join us on Discord" src="https://img.shields.io/discord/823813159592001537?color=5865F2&logo=discord&logoColor=white"></a>. We discuss the hottest trends about diffusion models, help each other with contributions, personal projects or just hang out ☕.

Credits

This library concretizes previous work by many different authors and would not have been possible without their great research and implementations. We'd like to thank, in particular, the following implementations which have helped us in our development and without which the API could not have been as polished today:

We also want to thank @heejkoo for the very helpful overview of papers, code and resources on diffusion models, available here as well as @crowsonkb and @rromb for useful discussions and insights.

Citation

@misc{von-platen-etal-2022-diffusers,
  author = {Patrick von Platen and Suraj Patil and Anton Lozhkov and Pedro Cuenca and Nathan Lambert and Kashif Rasul and Mishig Davaadorj and Thomas Wolf},
  title = {Diffusers: State-of-the-art diffusion models},
  year = {2022},
  publisher = {GitHub},
  journal = {GitHub repository},
  howpublished = {\url{https://github.com/huggingface/diffusers}}
}