Find your next open-source project

Search by name, purpose, or keyword — or paste a GitHub repository URL

leejet/stable-diffusion.cpp

Machine Learning

Run Stable Diffusion, FLUX, Wan and other diffusion image/video models locally in pure C/C++ across CPU and GPU backends.

7,881
924
C++
MIT
3 years old

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

  1. Get the sd-cli executable: download a pre-built binary from the releases page, or build from source using the build guide README lines 136–140.
  2. Download model weights into a local models directory. 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/
  1. 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 cuda follows stable-diffusion-webui GPU RNG, and --rng cpu follows 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.

Hacker News

Stable Diffusion in C/C++
▲ 303 · 115 comments · August 19, 2023
Stable Diffusion in pure C/C++
▲ 3 · 0 comments · August 16, 2023
Stable-Diffusion.cpp
▲ 2 · 1 comment · August 16, 2023