stable-diffusion.cpp icon indicating copy to clipboard operation
stable-diffusion.cpp copied to clipboard

Diffusion model(SD,Flux,Wan,Qwen Image,Z-Image,...) inference in pure C/C++

stable-diffusion.cpp

leejet%2Fstable-diffusion.cpp | Trendshift

Diffusion model(SD,Flux,Wan,...) inference in pure C/C++

Note that this project is under active development.
API and command-line option may change frequently.

πŸ”₯Important News

  • 2025/12/01 πŸš€ stable-diffusion.cpp now supports Z-Image
    πŸ‘‰ Details: PR #1020

  • 2025/11/30 πŸš€ stable-diffusion.cpp now supports FLUX.2-dev
    πŸ‘‰ Details: PR #1016

  • 2025/10/13 πŸš€ stable-diffusion.cpp now supports Qwen-Image-Edit / Qwen-Image-Edit 2509
    πŸ‘‰ Details: PR #877

  • 2025/10/12 πŸš€ stable-diffusion.cpp now supports Qwen-Image
    πŸ‘‰ Details: PR #851

  • 2025/09/14 πŸš€ stable-diffusion.cpp now supports Wan2.1 Vace
    πŸ‘‰ Details: PR #819

  • 2025/09/06 πŸš€ stable-diffusion.cpp now supports Wan2.1 / Wan2.2
    πŸ‘‰ Details: PR #778

Features

  • Plain C/C++ implementation based on ggml, working in the same way as llama.cpp
  • Super lightweight and without external dependencies
  • Supported models
    • Image Models
      • SD1.x, SD2.x, SD-Turbo
      • SDXL, SDXL-Turbo
      • Some SD1.x and SDXL distilled models
      • SD3/SD3.5
      • FlUX.1-dev/FlUX.1-schnell
      • FLUX.2-dev
      • Chroma
      • Chroma1-Radiance
      • Qwen Image
      • Z-Image
      • Ovis-Image
    • Image Edit Models
      • FLUX.1-Kontext-dev
      • Qwen Image Edit/Qwen Image Edit 2509
    • Video Models
      • Wan2.1/Wan2.2
    • PhotoMaker support.
    • Control Net support with SD 1.5
    • LoRA support, same as stable-diffusion-webui
    • Latent Consistency Models support (LCM/LCM-LoRA)
    • Faster and memory efficient latent decoding with TAESD
    • Upscale images generated with ESRGAN
  • Supported backends
    • CPU (AVX, AVX2 and AVX512 support for x86 architectures)
    • CUDA
    • Vulkan
    • Metal
    • OpenCL
    • SYCL
  • Supported weight formats
    • Pytorch checkpoint (.ckpt or .pth)
    • Safetensors (./safetensors)
    • GGUF (.gguf)
  • Supported platforms
  • Flash Attention for memory usage optimization
  • Negative prompt
  • stable-diffusion-webui style tokenizer (not all the features, only token weighting for now)
  • VAE tiling processing for reduce memory usage
  • Sampling method
  • Cross-platform reproducibility
    • --rng cuda, default, consistent with the stable-diffusion-webui GPU RNG
    • --rng cpu, consistent with the comfyui RNG
  • Embedds generation parameters into png output as webui-compatible text string

Quick Start

Get the sd executable

  • Download pre-built binaries from the releases page
  • Or build from source by following the build guide

Download model weights

  • download weights(.ckpt or .safetensors or .gguf). For example

    • Stable Diffusion v1.5 from https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5
    curl -L -O https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors
    

Generate an image with just one command

./bin/sd-cli -m ../models/v1-5-pruned-emaonly.safetensors -p "a lovely cat"

For detailed command-line arguments, check out cli doc.

Performance

If you want to improve performance or reduce VRAM/RAM usage, please refer to performance guide.

More Guides

  • SD1.x/SD2.x/SDXL
  • SD3/SD3.5
  • FlUX.1-dev/FlUX.1-schnell
  • FLUX.2-dev
  • FLUX.1-Kontext-dev
  • Chroma
  • πŸ”₯Qwen Image
  • πŸ”₯Qwen Image Edit/Qwen Image Edit 2509
  • πŸ”₯Wan2.1/Wan2.2
  • πŸ”₯Z-Image
  • Ovis-Image
  • LoRA
  • LCM/LCM-LoRA
  • Using PhotoMaker to personalize image generation
  • Using ESRGAN to upscale results
  • Using TAESD to faster decoding
  • Docker
  • Quantization and GGUF

Bindings

These projects wrap stable-diffusion.cpp for easier use in other languages/frameworks.

UIs

These projects use stable-diffusion.cpp as a backend for their image generation.

Contributors

Thank you to all the people who have already contributed to stable-diffusion.cpp!

Contributors

Star History

Star History Chart

References