gitmyhub

stable-diffusion.cpp

C++ ★ 6.4k updated 28m ago

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

A dependency-free C++ tool for generating images from text prompts on your own hardware, supporting Nvidia, Apple Silicon, AMD, and CPU, no cloud API key needed.

C++CCUDAMetalVulkanOpenCLsetup: moderatecomplexity 4/5

stable-diffusion.cpp is a tool for running AI image-generation models on your own computer, written in C and C++. The name follows the pattern of llama.cpp, a widely known project that brought large language models to personal hardware. This project does the same thing but for diffusion models: the kind of AI systems that turn a text prompt into an image (or, for some models, a short video clip).

The main draw is that it runs with no external software dependencies and works on a wide range of hardware. You can run it on a regular CPU or take advantage of a graphics card via CUDA (for Nvidia), Metal (for Apple Silicon), Vulkan, or OpenCL. The project supports many popular model families: Stable Diffusion 1.x, 2.x, XL, the FLUX series, Wan video models, Qwen Image, Z-Image, and others. Models can be loaded in several file formats including .safetensors and the compressed .gguf format, which can reduce memory usage.

Using it is straightforward once you have the binary and a model file. You run a command-line tool, point it at your model, pass a text prompt, and it writes an image to disk. The project also ships an embedded web interface for those who prefer a browser-based view over the command line.

Beyond basic text-to-image, the project supports ControlNet (which lets you guide composition using a reference image), LoRA fine-tuned models (small extra weights that adjust a model's style or subject), and image upscaling via ESRGAN. There are also several sampling methods available, which affect the quality and speed trade-off during generation.

Third-party wrappers exist for Go, Python, Rust, C#, and Flutter, so developers who want to build applications on top of stable-diffusion.cpp can work in their preferred language rather than calling C code directly.

Where it fits