Diffusers — Universal Video & Image Generation Hub
Hugging Face's diffusion model library. Run CogVideoX, AnimateDiff, Stable Video Diffusion, and 50+ video/image models with a unified API. 33,200+ stars.
What it is
Diffusers is Hugging Face's Python library for running diffusion models. It provides a unified API for over 50 models including Stable Diffusion, SDXL, CogVideoX, AnimateDiff, and Stable Video Diffusion. You can generate images, edit images, create videos, and run inpainting through the same pipeline interface.
Diffusers targets AI researchers, creative developers, and product teams building generative media features who need a consistent API across rapidly evolving model architectures.
How it saves time or tokens
Diffusers abstracts away the differences between model architectures behind a consistent pipeline API. Switching from Stable Diffusion to SDXL or from image to video generation requires changing a model name, not rewriting your inference code. Pre-built pipelines handle tokenization, scheduling, VAE encoding, and output formatting. The library integrates directly with Hugging Face Hub for one-line model downloads.
How to use
- Install Diffusers:
pip install diffusers torch
- Generate an image with Stable Diffusion:
import torch
from diffusers import StableDiffusionPipeline
pipe = StableDiffusionPipeline.from_pretrained(
'stabilityai/stable-diffusion-2-1',
torch_dtype=torch.float16
).to('cuda')
image = pipe('A serene mountain lake at sunset').images[0]
image.save('output.png')
- Generate video with CogVideoX:
from diffusers import CogVideoXPipeline
from diffusers.utils import export_to_video
pipe = CogVideoXPipeline.from_pretrained(
'THUDM/CogVideoX-2b',
torch_dtype=torch.float16
).to('cuda')
video = pipe('A cat playing with a ball of yarn').frames[0]
export_to_video(video, 'output.mp4')
Example
Image-to-image transformation:
from diffusers import StableDiffusionImg2ImgPipeline
from PIL import Image
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
'stabilityai/stable-diffusion-2-1',
torch_dtype=torch.float16
).to('cuda')
init_image = Image.open('sketch.png').resize((768, 768))
result = pipe(
prompt='A detailed oil painting',
image=init_image,
strength=0.75
).images[0]
result.save('painting.png')
Related on TokRepo
- Video tools — AI video generation and editing resources
- Design tools — AI-powered visual design and image generation
Common pitfalls
- Most diffusion models require a GPU with at least 8GB VRAM. Use torch.float16 and enable attention slicing for lower memory usage.
- Model downloads from Hugging Face Hub can be several GB. Cache models locally to avoid repeated downloads in CI/CD or serverless environments.
- Video generation models are significantly slower than image models. A single CogVideoX generation can take minutes on consumer GPUs.
Frequently Asked Questions
Yes, but slowly. Image generation on CPU takes minutes instead of seconds. Video generation on CPU is impractical. Use a GPU for any interactive or production workload.
Diffusers supports Stable Diffusion 1.5/2.1/XL, DALL-E-compatible models, Kandinsky, PixArt, CogVideoX, AnimateDiff, Stable Video Diffusion, ControlNet, and more. New models are added regularly.
Yes. Diffusers includes training scripts for LoRA, DreamBooth, and textual inversion fine-tuning. The diffusers training examples cover most common fine-tuning workflows.
Enable attention slicing with pipe.enable_attention_slicing(), use float16 precision, and enable model CPU offloading with pipe.enable_model_cpu_offload(). These techniques can reduce VRAM usage by 50% or more.
Diffusers library is Apache 2.0 licensed. Individual model weights have their own licenses. Stable Diffusion uses an open license; other models may have restrictions. Check each model's license card on Hugging Face Hub.
Citations (3)
- Diffusers GitHub— Diffusers provides a unified API for 50+ diffusion models
- Diffusers Documentation— Supports image and video generation with consistent pipeline interface
- Diffusers Training— Training scripts for LoRA, DreamBooth, and textual inversion
Related on TokRepo
Source & Thanks
Created by Hugging Face. Licensed under Apache 2.0. diffusers — ⭐ 33,200+ Docs: huggingface.co/docs/diffusers
Discussion
Related Assets
Moodle — Open-Source Learning Management System
The most widely used open-source learning platform, providing course management, assessments, and collaboration tools for educators and organizations worldwide.
Sylius — Headless E-Commerce Framework on Symfony
An open-source headless e-commerce platform built on Symfony and API Platform, designed for developers who need a customizable and API-first commerce solution.
Akaunting — Free Self-Hosted Accounting Software
A free, open-source online accounting application built on Laravel for small businesses and freelancers to manage invoices, expenses, and financial reports.