stable-diffusion.cpp README

The project's README from github.com/leejet/stable-diffusion.cpp. As one markdown file: README.md.

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

Features

Quick Start

Get the executables

The executable examples below run from the build directory (cd build from the repository root). Windows examples use the Visual Studio Release path; adjust the executable path for other build configurations or extracted archives. Model files stay under the repository's models/ directory.

Download model weights

Choose a model from the model guides and download its weights and required components. For a simple example, save Stable Diffusion 1.5 under models/checkpoints/:

Windows (PowerShell)

New-Item -ItemType Directory -Force ..\models\checkpoints | Out-Null
curl.exe -L -o ..\models\checkpoints\v1-5-pruned-emaonly.safetensors https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors

Linux/macOS

mkdir -p ../models/checkpoints
curl -L -o ../models/checkpoints/v1-5-pruned-emaonly.safetensors https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors

Option 1: Web UI

Start the server:

Windows (PowerShell)

.\bin\Release\sd-server.exe --model-dir ..\models

Linux/macOS

./bin/sd-server --model-dir ../models

Open http://127.0.0.1:1234/, choose SD 1.x in Recipe, select the checkpoint, and click Load models. Enter a prompt and click Generate. See the Web UI guide for the full workflow.

Option 2: CLI

Generate an image with one command:

Windows (PowerShell)

.\bin\Release\sd-cli.exe -m ..\models\checkpoints\v1-5-pruned-emaonly.safetensors -p "a lovely cat"

Linux/macOS

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

Run .\bin\Release\sd-cli.exe --help on Windows or ./bin/sd-cli --help on Linux/macOS for all command-line options. See the CLI guide for additional usage notes.

Performance

If you want to improve performance or reduce VRAM/RAM usage, please refer to performance guide. For runtime and parameter backend placement, see the backend selection guide.

Documentation

Browse the documentation index or jump to a topic:

Contributors

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

Contributors

stable-diffusion.cpp (leejet/stable-diffusion.cpp)

metal
Searching Database…

What is this?A pure C/C++ inference engine for diffusion models like Stable Diffusion, Flux, Wan, Qwen Image, and Z-Image, built the same way as llama.cpp so you can generate images and videos without heavy Python dependencies.
Is this a library or a ready-to-use app?It is primarily a command-line tool and library (same philosophy as llama.cpp), but it also ships a brand-new embedded web UI and has third-party GUIs and language bindings (Go, Python, Rust, C#, Dart) built on top of it.
How do I get it running?Download a pre-built 'sd' executable from the releases page (or build from source via the build guide), download model weights (.ckpt/.safetensors/.gguf), then run the generate command with your prompt.
Do I need Python or any ML framework to use it?No, it's a plain C/C++ implementation based on ggml with no external dependencies — you just need model weight files in checkpoint, safetensors, or GGUF format.
Does it support GPU acceleration, or is it CPU-only?Both: it runs on CPU (with AVX/AVX2/AVX512 on x86) and also supports CUDA, Vulkan, Metal, OpenCL, and SYCL backends, so performance varies a lot depending on which backend you pick.
Which platforms and model types are supported?It runs on Linux, macOS, Windows, and Android (via Termux/Local Diffusion), and supports a huge range of image and video models including SD1.x/SDXL/SD3.5, Flux, Qwen Image, Wan, LTX video, and more.
What extra features does it support beyond plain text-to-image?It supports LoRA, ControlNet, IP-Adapter, PhotoMaker, LCM/LCM-LoRA, VAE tiling for lower memory use, ESRGAN upscaling, ADetailer, and embeds generation parameters into PNG output compatible with webui.
What weight formats can I load?It can load PyTorch checkpoints (.ckpt/.pth/.pt), Safetensors, and GGUF files, and the convert mode can turn weights into .gguf or .safetensors.
Can I get reproducible results across different machines?Yes, it offers cross-platform reproducibility with --rng cuda (matching stable-diffusion-webui's GPU RNG) or --rng cpu (matching ComfyUI's RNG).
Are there bindings for other languages?Yes — community bindings exist for Go, C#, Python, Rust, and Flutter/Dart, letting you use stable-diffusion.cpp as a backend from other ecosystems.
Creator
leejet
Size
169.4 MB
Stars
8.1K
Age
3y
Commits · 90 Days