stable-diffusion.cpp is a pure C/C++ implementation of Stable Diffusion model inference, built on ggml – the same way llama.cpp runs LLMs. No Python, no PyTorch, no heavy dependencies: just a single executable that runs on your CPU or GPU. In this post we’ll show you how to install it and generate your first image with a single command.
What it supports
The project keeps up with model releases and supports a wide range of image and video models:
- Image – SD 1.x/2.x, SDXL, SD3/3.5, FLUX.1-dev/schnell, FLUX.2-dev/klein, Qwen Image, Z-Image, Ideogram4, Krea2, SenseNova U1.5 and more
- Video – Wan2.1/2.2, HunyuanVideo 1.5, LTX-2.3/2.5
- Extras – LoRA, ControlNet, IP-Adapter, ADetailer, LCM and ESRGAN upscaling, plus an embedded web UI
Supported backends include CPU (AVX/AVX2/AVX512), NVIDIA CUDA, AMD ROCm, Intel SYCL, Vulkan, Apple Metal and OpenCL, on Linux, macOS, Windows and even Android (via Termux). Model weights can be loaded in .safetensors, .gguf or PyTorch (.ckpt/.pth/.pt) formats.
Step 1: Get the sd executable
Option A: Pre-built binaries (easiest)
Download a pre-built binary for your platform from the releases page, extract the archive and you’re ready to go. Binaries are available for Linux (x86_64), macOS (Apple Silicon) and Windows (x64), in CPU, CUDA, ROCm and Vulkan variants.
Option B: Build from source
Clone the repository – the --recursive flag fetches the required submodules:
git clone --recursive https://github.com/leejet/stable-diffusion.cpp
cd stable-diffusion.cpp
Then build the CPU-only version:
mkdir build && cd build
cmake ..
cmake --build . --config Release
Build for your GPU
For an NVIDIA GPU, install the CUDA toolkit (at least 4 GB of VRAM recommended) and add the -DSD_CUDA=ON flag:
mkdir build && cd build
cmake .. -DSD_CUDA=ON
cmake --build . --config Release
AMD GPUs use ROCm/HipBLAS, Intel GPUs use SYCL, and Apple silicon can use Metal (-DSD_METAL=ON). For CPU builds, you can also enable OpenBLAS for better performance:
cmake .. -DGGML_OPENBLAS=ON
cmake --build . --config Release
Full instructions for every backend: build guide.
Step 2: Download the model weights
The executable does not bundle any model. Download the weights for the model you want to use – for example Stable Diffusion 1.5:
curl -L -O https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors
Any of the supported weight formats work: .safetensors, .gguf or PyTorch checkpoints (.ckpt/.pth/.pt). The project also includes a convert mode to turn weights into .gguf quantized models, which are smaller and use less memory – see the quantization guide.
Some models – Qwen Image, FLUX.2, Z-Image and similar – are released as separate files: a diffusion model, a VAE and a text encoder. You download all of them and point the server at each one, as shown in the next step.
Step 3: Run it in server mode
For regular use, run sd-server, which starts the embedded web UI – and a REST API – in your browser. Here is a real example with Qwen Image on Windows, with flash attention, a LoRA folder, and an RPC server for extra GPU compute:
C:\stable-diffusion.cpp\build\bin\Release\sd-server.exe --diffusion-model "D:\llamacpp\models\qwen-image-2512\qwen-image-2512-Q4_K_M.gguf" --vae "D:\llamacpp\models\qwen-image-2512\qwen_image_vae.safetensors" --cfg-scale 2.5 --diffusion-fa --llm "D:\llamacpp\models\qwen-image-2512\Qwen2.5-VL-7B-Instruct-UD-Q4_K_XL.gguf" --listen-ip 0.0.0.0 --lora-model-dir "D:\llamacpp\models\qwen-image-2512\loras" --rpc-servers 192.168.1.9:50052
--diffusion-model,--vaeand--llm– the diffusion model, VAE decoder and text encoder--cfg-scale 2.5– default CFG scale for generations--diffusion-fa– flash attention, to reduce VRAM usage--listen-ip 0.0.0.0– make the UI reachable from your network--lora-model-dir– LoRAs in this folder show up in the web UI--rpc-servers– offload computation to another GPU running an RPC server
The Qwen-Image-2512 diffusion model, VAE and text encoder used in this example – and how to download them – are covered in the Qwen-Image-2512 tutorial.
Once it starts, open http://127.0.0.1:1234 (or the machine’s IP when using --listen-ip) and generate images from the browser. A native API is available under /sdcpp/v1, plus Stable Diffusion WebUI-compatible endpoints under /sdapi/v1. And if you just want one-shot generation from the terminal, sd-cli -m <model> -p "a lovely cat" still works.
Go further
- All CLI options – negative prompts, sampling methods (Euler A, DPM++ 2M, LCM and more), steps, CFG scale: cli docs
- Performance and VRAM – make generation faster and reduce memory usage: performance guide
- Choosing a backend – which backend to use on your hardware: backend guide
Full documentation and source code: github.com/leejet/stable-diffusion.cpp
