leejet/stable-diffusion.cpp
Machine LearningRun Stable Diffusion, FLUX, Wan and other diffusion image/video models locally in pure C/C++ across CPU and GPU backends.
What it does
stable-diffusion.cpp is a lightweight C/C++ inference engine for diffusion models, built on ggml in the spirit of llama.cpp. It runs text-to-image, image-to-image, image editing, and video generation models without a Python stack. Supported families include SD1.x/2.x/XL/3.x, FLUX.1/2/3, Qwen Image and Image Edit, Z-Image, Wan2.1/2.2, LTX-2, HunyuanVideo, plus ControlNet, IP-Adapter, LoRA, PhotoMaker, ESRGAN upscaling, and TAESD decoding README lines 37–133.
It targets users who want local, dependency-light generation on Linux, macOS, Windows, or Android via Termux. Backends include CPU (AVX/AVX2/AVX512), CUDA, Vulkan, Metal, OpenCL, and SYCL, and weights can be loaded from .ckpt, .safetensors, or .gguf. A convert mode can rewrite weights to .gguf or .safetensors. An embedded web UI has been available since 2026-04-11 README lines 16–36.
The project is under active development and its API and command-line options may change frequently README lines 5–15.
Quick start
- Get the
sd-cliexecutable: download a pre-built binary from the releases page, or build from source using the build guide README lines 136–140. - Download model weights into a local
modelsdirectory. The README example fetches SD v1.5:
curl -L -O https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors
mv v1-5-pruned-emaonly.safetensors ../models/
- Generate an image from the repository build directory:
./bin/sd-cli -m ../models/v1-5-pruned-emaonly.safetensors -p "a lovely cat"
The output image is written to disk by the CLI. For the full argument list, see the CLI documentation README lines 150–157. Model-specific setup notes live in per-model docs such as SD, FLUX.1, Qwen Image, and Wan.
Constraints
- Generation speed and memory use depend heavily on the selected backend and model size. The performance guide and backend selection guide cover threading, VRAM/RAM reduction, Flash Attention, VAE tiling, and sampling options.
- Only a subset of stable-diffusion-webui tokenizer behavior is implemented, currently token weighting README lines 37–133.
- Cross-platform reproducibility requires matching the RNG flag:
--rng cudafollows stable-diffusion-webui GPU RNG, and--rng cpufollows ComfyUI RNG. - The project does not ship model weights; users must obtain them separately and comply with each model's license.
- The code is MIT licensed.
HotRepo's take
HN discussion at launch focused on whether a C/C++ port makes sense for diffusion, where compute and memory profiles differ from LLM inference comment by brucethemoose2. Practical replies pushed back: users ran it on an old laptop without a discrete GPU, and one noted the binary replaced gigabytes of Python dependencies comment by badsectoracula. Those trade-offs still define the project: it is a fit for constrained hardware and minimal setups, not necessarily for the fastest possible throughput. In HotRepo's records, the repository sat at 7,881 stars on 2026-11-03, ranked 10th on the C++ daily list that day with 16 stars gained, and the original 2023 HN thread drew 303 points and 115 comments.
Written by AI from the project's README, updated . The project's own docs are the source of truth.