Skip to content

stable-diffusion.cpp Guide: Web UI, CLI, Z-Image on 4GB and Builds

8–12 minutes
Woman in a hijab in a sunny cafe holding a tablet with an SD.CPP card, hook AI images on 4GB VRAM

stable-diffusion.cpp (often shortened to sd.cpp) is to image generation what llama.cpp is to text models: a single C/C++ program, built on ggml, that runs diffusion models without Python, PyTorch or a pile of dependencies.

It handles Stable Diffusion 1.5 and SDXL, FLUX, Z-Image, Qwen Image, Wan and LTX video, and it now ships with its own browser-based Web UI.

It is worth a look if ComfyUI feels heavy, if you have a small or non-NVIDIA GPU, or if you want a tool you can script from a terminal. The project’s docs say Z-Image runs on GPUs with 4 GB of VRAM “or even less”.

This guide covers getting the binaries, the model folder layout, generating with the Web UI and the CLI, running Z-Image-Turbo on a small GPU, building with CUDA, Vulkan or Metal, the memory-saving flags, and the fixes for black images and Windows DLL errors. It follows the project’s README and docs as of late November 2026.

TL;DR

  • What: pure C/C++ diffusion inference for images and video, from the same ggml family as llama.cpp.
  • Get it: download a prebuilt release, or build with -DSD_CUDA=ON, -DSD_VULKAN=ON or -DSD_METAL=ON.
  • Web UI: run sd-server --model-dir ../models and open http://127.0.0.1:1234/.
  • CLI: sd-cli -m model.safetensors -p "a lovely cat".
  • Low VRAM: GGUF quants, --offload-to-cpu, --vae-tiling and flash attention.
  • Black images: add --linear-scale 0.0078125 --attn-scale 0.0078125.

Why Use stable-diffusion.cpp

  • Lightweight: one set of executables and no external dependencies. No Python environment to break after an update.
  • Runs almost anywhere: CPU (AVX, AVX2, AVX512), NVIDIA CUDA, AMD and Intel through Vulkan, Apple Metal, OpenCL for Adreno, SYCL and ROCm builds. It also runs on Android through Termux.
  • GGUF support: load quantized models in the same format you know from local LLMs, or convert your own.
  • Fast model support: the README lists day-0 support for MiniMax-H3-Image (11 Nov 2026), FLUX.3 Image Klein and MOSS-Image (16 Oct 2026) and Qwen-Image-2.1 (20 Sep 2026).
  • Built-in Web UI and API: sd-server gives you a browser interface, model management and HTTP APIs.
  • Reproducible: --rng cuda (the default) matches the stable-diffusion-webui GPU RNG, and --rng cpu matches ComfyUI’s RNG.

The project warns that it is “under active development” and that the API and command-line options can change often. Check --help after every update.

Supported Models and Backends

Type Examples supported
Classic image SD 1.x, SD 2.x, SD-Turbo, SDXL, SDXL-Turbo, SD3/SD3.5
Modern image FLUX.1, FLUX.2-dev and klein, FLUX.3 Image Klein, Z-Image, Qwen Image and 2.1, Chroma, MOSS-Image, MiniMax-H3-Image, Krea2, Ideogram4
Image editing FLUX.1-Kontext-dev, Qwen Image Edit series, LongCat Image Edit, MOSS-Image Edit
Video Wan2.1/Wan2.2, MiniMax-H3, LTX-2.3/LTX-2.5, HunyuanVideo 1.5
Video upscale RelayVSR, SeedVR2
Extras LoRA, ControlNet (SD 1.5), IP-Adapter, PhotoMaker, ADetailer, LCM, TAESD, ESRGAN upscaling

Weights can be .ckpt/.pth/.pt, .safetensors or .gguf. Each model has its own page in the project’s docs listing the exact files and component slots it needs.

Get the Binaries

You have two options:

  1. Prebuilt release (easiest). Download the archive for your OS and GPU backend from the project’s GitHub releases page and extract it. Inside you will find sd-cli and sd-server.
  2. Build from source. Clone with submodules and build with CMake. This gives you the latest fixes and the right GPU target. See the build section below.

The README’s examples run from the build folder, with models in the repository’s models/ folder one level up. On Windows the Visual Studio Release path is .\bin\Release\sd-cli.exe; with an extracted release archive, adjust the path to wherever the executables are.

Set Up the Models Folder

sd-server scans category folders, much like ComfyUI. Create this layout:

models/
  checkpoints/
  diffusion_models/
  text_encoders/
  tokenizers/
  vae/
  clip_vision/
  loras/
  recipes/

Folder names are matched case-insensitively, and the server also accepts the stable-diffusion-webui names Stable-diffusion, VAE, Lora and ControlNet. That means you can point sd.cpp at an existing A1111 or Forge models folder instead of duplicating files. Repeat --model-dir to scan several roots:

.\bin\Release\sd-server.exe --model-dir ..\models --model-dir D:\stable-diffusion-webui\models

For a first test, download Stable Diffusion 1.5 into models/checkpoints/, as the README does:

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

Generate with the Web UI

The embedded Web UI arrived in April 2026 and is now the friendliest way in.

  1. Start the server. From the repository root run start-server.bat on Windows or sh ./start-server.sh on Linux and macOS. Or run the executable directly: ./bin/sd-server --model-dir ../models. Keep the console open.
  2. Open the UI at http://127.0.0.1:1234/.
  3. Choose a model. Click Model below the prompt, pick the matching Recipe (for example SD 1.x), and leave Apply recipe defaults on.
  4. Fill the component slots. Select the diffusion model, text encoder and VAE where the recipe asks for them. Required fields have an asterisk. If a file is missing, check its folder and click Refresh files & recipes.
  5. Prompt and generate. Enter a prompt, adjust Sample & Guidance and Aspect Ratio & Resolution if needed, then click Generate. Sampling at 100% does not mean decoding has finished, so wait for the final image.

LoRAs go in models/loras/ and are applied from the LoRA panel with a strength slider. To use another port, start with --listen-port 8080. The server listens on 127.0.0.1 by default, so it is only reachable from your own PC unless you change --listen-ip.

Generate with the CLI

The CLI is ideal for scripts and batch jobs. The basic command is:

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

Useful things to know:

  • The CLI uses seed 42 by default for repeatable runs. Pass --seed -1 for a random seed.
  • Modern models load as separate parts: --diffusion-model, --vae and a text encoder such as --llm.
  • -H and -W set height and width, --steps the step count and --cfg-scale the guidance.
  • -v shows verbose logs, which is how you confirm flash attention and VRAM use.
  • Video models need --mode vid_gen, even for a single frame.
  • Run sd-cli -h for the full option list.

Images embed their generation settings as a webui-compatible text string, so you can see the prompt and seed later.

Run Z-Image-Turbo on a Small GPU

Z-Image-Turbo is the best demonstration of what sd.cpp is good at. It uses Qwen3 4B as the text encoder and the FLUX VAE, and the docs say it runs on 4 GB of VRAM or less. You need three files:

Component Where to get it Flag Folder
Z-Image-Turbo (GGUF) leejet/Z-Image-Turbo-GGUF on Hugging Face --diffusion-model diffusion_models/
FLUX VAE (ae) black-forest-labs/FLUX.1-schnell --vae vae/
Qwen3 4B (GGUF) unsloth/Qwen3-4B-Instruct-2507-GGUF --llm text_encoders/

Based on the project’s own example (with a shorter prompt), on Linux and macOS:

./bin/sd-cli \
  --diffusion-model ../models/diffusion_models/z_image_turbo-Q3_K.gguf \
  --vae ../models/vae/ae.sft \
  --llm ../models/text_encoders/Qwen3-4B-Instruct-2507-Q4_K_M.gguf \
  -p "a cosy reading nook with warm lamp light, rain on the window" \
  --cfg-scale 1.0 --steps 8 -H 1024 -W 512 \
  --offload-to-cpu -v

Turbo is distilled, so it uses CFG 1.0 and only 8 steps. On Windows replace the backslashes at line ends with backticks in PowerShell. In the Web UI, choose the Z-Image Turbo recipe and fill the diffusion_model, llm and vae slots.

With more VRAM, use a larger quant such as Q8 for better detail. Our GGUF quantization guide explains the trade-offs.

Build with CUDA, Vulkan or Metal

Clone with submodules first:

git clone --recursive https://github.com/leejet/stable-diffusion.cpp
cd stable-diffusion.cpp

If you cloned without --recursive, run git submodule update --init --recursive. Then build for your hardware:

Hardware CMake flag Needs
NVIDIA -DSD_CUDA=ON CUDA Toolkit; 4 GB+ VRAM recommended
AMD / Intel / NVIDIA (any) -DSD_VULKAN=ON Vulkan SDK
Apple Silicon -DSD_METAL=ON Xcode tools
AMD ROCm -DSD_HIPBLAS=ON ROCm / HIP
Intel oneAPI -DSD_SYCL=ON oneAPI compilers
CPU only (none) A C++ compiler
mkdir build && cd build
cmake .. -DSD_CUDA=ON
cmake --build . --config Release

To target a specific NVIDIA generation, add -DCMAKE_CUDA_ARCHITECTURES=89 for Ada, for example. CUDA builds also include sd.cpp’s SageAttention extension. The docs note that Metal still has some inefficiency with very large matrices.

On Ubuntu, the Vulkan build needs sudo apt-get install build-essential libvulkan-dev glslc spirv-headers. If you already built llama.cpp, the process will feel identical.

To update later: git pull origin master, git submodule update --init --recursive, then rebuild.

Save VRAM and Speed Things Up

Option What it does
--flash-attn on|off|auto Flash attention, auto by default. Saves roughly 600 MB on FLUX at 768×768 and about 1,400 MB on SD2.
--offload-to-cpu Keeps weights in system RAM and moves them to the GPU when needed. Lets models larger than your VRAM run.
--vae-tiling Tiles VAE encode and decode to cut peak memory. Tune with --vae-tile-size 256x256 --vae-tile-overlap 0.5.
--type q8_0 (or q5_0, q4_0) Quantizes weights on load to cut memory.
-M convert Converts a model to GGUF once, so you do not quantize on every load.

To convert ahead of time:

./bin/sd-cli -M convert -m ../models/v1-5-pruned-emaonly.safetensors -o ../models/v1-5-pruned-emaonly.q8_0.gguf -v --type q8_0

Compare --flash-attn on and off on your own GPU, because the docs say its speed effect depends on GPU, backend, driver and model.

sd.cpp vs ComfyUI

stable-diffusion.cpp ComfyUI
Install One binary download Python environment or portable build
GPU support CUDA, Vulkan, Metal, ROCm, SYCL, OpenCL, CPU Mainly CUDA, plus ROCm, MPS and others
Interface Simple Web UI, CLI, HTTP API Node graph
Custom workflows DGL scripts Huge custom node ecosystem
Best for Small GPUs, AMD/Intel via Vulkan, scripting, servers Complex pipelines and the newest community nodes

Many people use both: ComfyUI for complex workflows and sd.cpp for quick generations or a lightweight server. If you stick with ComfyUI on a small card, read our ComfyUI out of memory fixes.

Troubleshooting

Completely black or white images (NaNs)

Some backends overflow numerically on certain models. Add these to your CLI command or server startup and rerun the same seed:

--linear-scale 0.0078125 --attn-scale 0.0078125

If that does not help, try smaller values such as 0.00390625. Restart sd-server after changing startup options. --attn-scale only takes effect when flash attention is used.

“Cannot be run with generate_image()”

You loaded a video model in image mode. Add --mode vid_gen. Setting --video-frames alone does not switch modes.

Windows ROCm build exits instantly with 0xC0000135

That is STATUS_DLL_NOT_FOUND: the HIP runtime is not on PATH. Add the ROCm SDK bin folders to PATH rather than copying single DLLs, then check with .\sd-cli.exe --version.

Model missing from the Web UI dropdown

Check that the file is in the right category folder, then click Refresh files & recipes. Symlinks that point outside the model directory are rejected.

Out of memory

Use a smaller GGUF quant, add --offload-to-cpu and --vae-tiling, and lower the resolution. On Vulkan, the same advice as in our llama.cpp Vulkan guide applies: update your GPU driver first.

FAQ

Is stable-diffusion.cpp free?

Yes. It is open source on GitHub. Each model you download has its own licence.

Does it work on AMD GPUs on Windows?

Yes. The Vulkan build works on AMD, Intel and NVIDIA cards, and there are ROCm builds too.

Can it run FLUX?

Yes. FLUX.1-dev and schnell, FLUX.2-dev and klein, and FLUX.3 Image Klein are all supported. Use GGUF quants and --offload-to-cpu on smaller cards.

Can I use my ComfyUI or A1111 models?

Yes. Safetensors work directly, and the server accepts webui folder names, so you can add your existing models folder with --model-dir.

Does it support video?

Yes: Wan2.1/2.2, LTX-2.3/2.5, HunyuanVideo 1.5 and MiniMax-H3, plus RelayVSR and SeedVR2 for video upscaling.

Is there an API?

sd-server provides native and compatibility HTTP endpoints alongside the Web UI, so other apps can request images from it.

Can it run on a phone?

On Android, yes, through Termux or the Local Diffusion app listed in the README.

Sources

Free weekly email

Get new AI guides every week

One short weekly email with our newest local AI, ComfyUI and AI tool guides. No spam, no pop-ups, just the good stuff.

Free. Unsubscribe anytime in one click. We only use your email to send this newsletter. See our privacy policy.

Woman in a hijab in a sunny cafe holding a tablet with an SD.CPP card, hook AI images on 4GB VRAM