Diffusion model(SD,Flux,Wan,...) inference in pure C/C++
Note that this project is under active development.
API and command-line option may change frequently.
Before you install this project please make sure that you have the rocm installed. If not then please install it and check weather your gpu is supported or not. Run this command to check the rocm support information:
rocminfoIf supported then you will be able to see it's gfx code something like gfx1100 (For RX 7900 Series), This will vary depending on the GPU Model.
If the rocm is supported then you can proceed to install ninja build system.
If everything is all right then you can proceed to run these commands:
git clone https://github.com/BillyOutlast/rocm-stable-diffusion.cpp.git
cd rocm-stable-diffusion.cpp
# Create build directory
mkdir build && cd build
# Adding ggml
git submodule update --init --recursive
# Configure CMake for ROCm (HIPBLAS)
cmake .. \
-G Ninja \
-DCMAKE_C_COMPILER=clang \
-DCMAKE_CXX_COMPILER=clang++ \
-DSD_HIPBLAS=ON \
-DCMAKE_BUILD_TYPE=Release \
-DAMDGPU_TARGETS=gfx1100
# Build
ninja
# Move the binary and clean the project
mv bin ../../
cd ../../
rm -rf rocm-stable-diffusion.cppAfter wards you will have the bin/sd binary file.
You can use that binary according to the documentation.
- Plain C/C++ implementation based on ggml, working in the same way as llama.cpp
- Super lightweight and without external dependencies
- Supported models
- Image Models
- Image Edit Models
- Video Models
- PhotoMaker support.
- Control Net support with SD 1.5
- LoRA support, same as stable-diffusion-webui
- Latent Consistency Models support (LCM/LCM-LoRA)
- Faster and memory efficient latent decoding with TAESD
- Upscale images generated with ESRGAN
- Supported backends
- CPU (AVX, AVX2 and AVX512 support for x86 architectures)
- CUDA
- Vulkan
- Metal
- OpenCL
- SYCL
- Supported weight formats
- Pytorch checkpoint (
.ckptor.pth) - Safetensors (
./safetensors) - GGUF (
.gguf)
- Pytorch checkpoint (
- Supported platforms
- Linux
- Mac OS
- Windows
- Android (via Termux, Local Diffusion)
- Flash Attention for memory usage optimization
- Negative prompt
- stable-diffusion-webui style tokenizer (not all the features, only token weighting for now)
- VAE tiling processing for reduce memory usage
- Sampling method
Euler AEulerHeunDPM2DPM++ 2MDPM++ 2M v2DPM++ 2S aLCM
- Cross-platform reproducibility
--rng cuda, default, consistent with thestable-diffusion-webui GPU RNG--rng cpu, consistent with thecomfyui RNG
- Embedds generation parameters into png output as webui-compatible text string
- Download pre-built binaries from the releases page
- Or build from source by following the build guide
-
download weights(.ckpt or .safetensors or .gguf). For example
- Stable Diffusion v1.5 from https://huggingface.co/runwayml/stable-diffusion-v1-5
curl -L -O https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors
./bin/sd -m ../models/v1-5-pruned-emaonly.safetensors -p "a lovely cat"For detailed command-line arguments, check out cli doc.
If you want to improve performance or reduce VRAM/RAM usage, please refer to performance guide.
- SD1.x/SD2.x/SDXL
- SD3/SD3.5
- Flux-dev/Flux-schnell
- FLUX.1-Kontext-dev
- Chroma
- 🔥Qwen Image
- 🔥Qwen Image Edit/Qwen Image Edit 2509
- 🔥Wan2.1/Wan2.2
- LoRA
- LCM/LCM-LoRA
- Using PhotoMaker to personalize image generation
- Using ESRGAN to upscale results
- Using TAESD to faster decoding
- Docker
- Quantization and GGUF
These projects wrap stable-diffusion.cpp for easier use in other languages/frameworks.
- Golang (non-cgo): seasonjs/stable-diffusion
- Golang (cgo): Binozo/GoStableDiffusion
- C#: DarthAffe/StableDiffusion.NET
- Python: william-murray1204/stable-diffusion-cpp-python
- Rust: newfla/diffusion-rs
- Flutter/Dart: rmatif/Local-Diffusion
These projects use stable-diffusion.cpp as a backend for their image generation.
- Jellybox
- Stable Diffusion GUI
- Stable Diffusion CLI-GUI
- Local Diffusion
- sd.cpp-webui
- LocalAI
- Neural-Pixel
- KoboldCpp
Thank you to all the people who have already contributed to stable-diffusion.cpp!
