sd-cli
TLDR
Generate an image from a text prompt
SYNOPSIS
sd-cli -m model -p prompt [options] -o output
DESCRIPTION
sd-cli is the command-line interface for stable-diffusion.cpp, a lightweight C/C++ implementation of Stable Diffusion using the ggml tensor library. It runs image generation models on CPU and GPU without requiring Python or heavy ML frameworks.
The tool supports Stable Diffusion 1.x, 2.x, SDXL, and Flux model architectures. Models in safetensors or gguf (quantized) format can be loaded directly. Quantized models significantly reduce memory usage while maintaining reasonable quality.
Text-to-image generates from a prompt. Image-to-image transforms an existing image guided by a prompt. The strength parameter controls how much the original image is altered.
Build from source using CMake. GPU acceleration is available through CUDA, Metal, and Vulkan backends.
PARAMETERS
-m, --model FILE
Path to model weights (.safetensors or .gguf).-p, --prompt TEXT
Text prompt for image generation.-n, --negative-prompt TEXT
Negative prompt to guide away from.-o, --output FILE
Output image path.--steps N
Number of sampling steps (default: 20).--cfg-scale FLOAT
Classifier-free guidance scale (default: 7.0).--seed INT
RNG seed (-1 for random).--width PX
Image width in pixels.--height PX
Image height in pixels.--sampling-method METHOD
Sampling method: euler, eulera, heun, dpm2, dpm++2sa, dpm++2m, dpm++2mv2, lcm.--img2img FILE
Input image for image-to-image generation.--strength FLOAT
Denoising strength for img2img (0.0-1.0).--threads N
Number of CPU threads.--rng TYPE
RNG type: std_default, cuda.
CAVEATS
Must be built from source. Large model files required (several GB). Quality depends on model choice and parameters. GPU acceleration requires backend-specific build flags. SDXL and Flux models need more memory than SD 1.x.
HISTORY
stable-diffusion.cpp was created by leejet in 2023, inspired by llama.cpp's approach of bringing ML models to C/C++ with minimal dependencies. It brought Stable Diffusion inference to resource-constrained environments and platforms without Python support.


