leejet/stable-diffusion.cpp

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

What it is

stable‑diffusion.cpp is a pure C/C++ implementation of diffusion‑model inference (Stable Diffusion, FLUX, Qwen‑Image, etc.) built on top of the ggml tensor library, much like the popular llama.cpp project for LLMs. It lets you run image‑generation models locally on a wide range of hardware – from CPUs to GPUs (CUDA, Vulkan, Metal, OpenCL, SYCL) and even Android devices – without needing heavyweight Python stacks.

Why it matters

  • Lightweight & portable – a single binary with no external runtime dependencies, making it easy to ship on low‑resource machines.
  • Broad model support – dozens of image‑generation, image‑editing, and video diffusion models are listed, including the newest releases (e.g., Qwen‑Image‑2.1, FLUX‑2‑klein, MiniMax‑H3). This keeps the tool relevant as the field evolves.
  • Cross‑platform reproducibility – deterministic RNG options match those of popular web‑UIs, and generation parameters are embedded in the output PNGs for easy round‑tripping.
  • Performance knobs – supports CPU SIMD (AVX/AVX2/AVX512), GPU back‑ends, Flash Attention, TAESD decoding, and quantised weight formats (GGUF, safetensors, INT8) to squeeze speed and memory usage.

Core features (from the README)

  • Implementation: Pure C/C++ using ggml; no Python or other heavy dependencies.
  • Supported model families:
    • Image generation: SD‑1.x/2.x, SDXL, SD‑Turbo, SD‑distilled, SD3/3.5, FLUX‑1/2, Lens, Qwen‑Image, PiD, etc.
    • Image editing: FLUX‑1‑Kontext, Qwen‑Image‑Edit series, LongCat Edit, etc.
    • Video: Wan2.1/2.2, MiniMax‑H3, LTX‑2.3/2.5, HunyuanVideo, LingBot‑Video.
  • Additional capabilities: LoRA, IP‑Adapter, ControlNet, ADetailer, Latent Consistency Models (LCM), ESRGAN upscaling, negative prompts, VAE tiling, multiple samplers (Euler, DPM++, LCM, etc.).
  • Back‑ends: CPU (AVX/AVX2/AVX512), CUDA, Vulkan, Metal, OpenCL, SYCL.
  • Weight formats: .ckpt/.pth/.pt (PyTorch), .safetensors, .gguf.
  • Conversion: Can convert weights to GGUF or safetensors.
  • Platforms: Linux, macOS, Windows, Android (via Termux/Local Diffusion).
  • CLI: Simple command‑line tool (sd-cli) that takes a model file and a prompt.
  • Web UI: Embedded web UI added in April 2026.
  • Bindings & UIs: Community wrappers for Go, C#, Python, Rust, Dart/Flutter, plus GUIs for GIMP, Jellybox, wxWidgets, etc.

How to get started (quick‑start summary)

  1. Obtain the binary – download a pre‑built release or compile from source following the docs/build.md guide.
  2. Download model weights – e.g., curl -L -O https://huggingface.co/.../v1-5-pruned-emaonly.safetensors.
  3. Run a generation:
    ./bin/sd-cli -m ../models/v1-5-pruned-emaonly.safetensors -p "a lovely cat"
    
    The CLI supports many flags for sampler choice, LoRA, IP‑Adapter, etc.; see examples/cli/README.md.
  4. Tune performance – consult docs/performance.md and docs/backend.md for VRAM/RAM optimisations and backend selection.

Who might use it

  • Developers who want to embed diffusion inference in native applications or games without pulling in Python.
  • Researchers experimenting with new diffusion models on modest hardware.
  • Enthusiasts looking for a fast, offline image generator that runs on laptops, desktops, or even phones.
  • Tool builders creating GUIs, plugins, or server‑side services (many community projects already do this).

All information above is taken directly from the repository’s README; no external assumptions have been added.

Related

  • Project
  • Project
  • Project
  • Project
  • Project