leejet/stable-diffusion.cpp
摘要
一个用于扩散模型的轻量级 C/C++ 推理引擎,支持广泛的图像和视频生成模型,并积极开发,对新发布提供日零支持。
查看缓存全文
缓存时间: 2026/09/24 15:10
leejet/stable-diffusion.cpp
来源:https://github.com/leejet/stable-diffusion.cpp
stable-diffusion.cpp
纯 C/C++ 实现的扩散模型(SD, Flux, Wan 等)推理。 注意:此项目正在积极开发中。API 和命令行选项可能频繁变更。
🔥重要新闻
- 2026/09/20 🚀 stable-diffusion.cpp 新增 对 Qwen-Image-2.1 的 Day-0 支持
- 2026/08/20 🚀 stable-diffusion.cpp 现已支持 LTX-2.5
- 2026/08/04 🚀 stable-diffusion.cpp 新增 对 MiniMax-H3 的 Day-1 支持
- 2026/06/25 🚀 stable-diffusion.cpp 现已支持 Krea2
- 2026/06/04 🚀 stable-diffusion.cpp 现已支持 Ideogram4
- 2026/05/31 🚀 stable-diffusion.cpp 现已支持 PiD
- 2026/05/27 🚀 stable-diffusion.cpp 现已支持 Lens
- 2026/05/17 🚀 stable-diffusion.cpp 现已支持 LTX-2.3
- 2026/04/11 🚀 stable-diffusion.cpp 现已使用全新的内置 Web UI。
- 2026/01/18 🚀 stable-diffusion.cpp 现已支持 FLUX.2-klein
- 2025/12/01 🚀 stable-diffusion.cpp 现已支持 Z-Image
- 2025/11/30 🚀 stable-diffusion.cpp 现已支持 FLUX.2-dev
- 2025/10/13 🚀 stable-diffusion.cpp 现已支持 Qwen-Image-Edit / Qwen-Image-Edit 2509
- 2025/10/12 🚀 stable-diffusion.cpp 现已支持 Qwen-Image
- 2025/09/14 🚀 stable-diffusion.cpp 现已支持 Wan2.1 Vace
- 2025/09/06 🚀 stable-diffusion.cpp 现已支持 Wan2.1 / Wan2.2
功能特性
- 基于 ggml (https://github.com/ggml-org/ggml) 的纯 C/C++ 实现,工作方式与 llama.cpp (https://github.com/ggml-org/llama.cpp) 相同
- 极致轻量,无外部依赖
- 支持的模型
- 图像模型
- SD1.x, SD2.x, SD-Turbo
- SDXL, SDXL-Turbo
- 部分 SD1.x 和 SDXL 蒸馏模型
- SD3/SD3.5
- FLUX.1-dev/FLUX.1-schnell
- FLUX.2-dev/FLUX.2-klein
- Lens
- Chroma
- Chroma1-Radiance
- Qwen Image
- Qwen Image 2.1
- PiD
- LongCat Image
- Z-Image
- MiniT2I
- SenseNova U1.5
- Ovis-Image
- Anima
- ERNIE-Image
- Boogu Image
- Krea2
- Mage-Flow
- SeFi-Image
- HiDream-O1-Image
- Ideogram4
- LLaDA-Image
- 图像编辑模型
- 视频模型
- 图像模型
- IP-Adapter 支持(SD 1.5 和 SDXL,包括 Plus)
- SD 1.5 的 Control Net 支持
- ADetailer
- LoRA 支持,与 stable-diffusion-webui (https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Features#lora) 相同
- 潜在一致性模型支持(LCM/LCM-LoRA)
- 使用 TAESD 实现更快、内存效率更高的潜在解码
- 使用 ESRGAN 放大生成的图像
- 支持的后端
- CPU(支持 x86 架构的 AVX、AVX2 和 AVX512)
- CUDA
- Vulkan
- Metal
- OpenCL
- SYCL
- 支持的权重格式
- Pytorch checkpoint(
.ckpt或.pth或.pt) - Safetensors(
.safetensors) - GGUF(
.gguf)
- Pytorch checkpoint(
- 转换模式支持将模型权重转换为
.gguf或.safetensors - 支持的平台
- Linux
- Mac OS
- Windows
- Android(通过 Termux, Local Diffusion (https://github.com/rmatif/Local-Diffusion))
- Flash Attention 用于内存使用优化
- 负面提示词
- stable-diffusion-webui (https://github.com/AUTOMATIC1111/stable-diffusion-webui) 风格的分词器(目前仅支持部分功能,如 token 权重)
- VAE 平铺处理以减少内存使用
- 采样方法
Euler AEulerHeunDPM2DPM++ 2MDPM++ 2M v2(https://github.com/AUTOMATIC1111/stable-diffusion-webui/discussions/8457)DPM++ 2S aER-SDELCM(https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/13952)
- 跨平台可复现性
--rng cuda,默认,与stable-diffusion-webui GPU RNG一致--rng cpu,与comfyui RNG一致
- 将生成参数嵌入 PNG 输出为兼容 webui 的文本字符串
快速开始
获取 sd 可执行文件
- 从 releases 页面 (https://github.com/leejet/stable-diffusion.cpp/releases) 下载预编译二进制文件
- 或者按照 构建指南 从源代码构建
下载模型权重
- 下载权重(
.ckpt或.safetensors或.gguf)。例如- Stable Diffusion v1.5 来自 https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5
curl -L -O https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors
一条命令生成图像
./bin/sd-cli -m ../models/v1-5-pruned-emaonly.safetensors -p "a lovely cat"
有关详细的命令行参数,请查看 cli 文档。
性能
如果您想提升性能或降低 VRAM/RAM 使用量,请参考 性能指南。关于运行时和参数后端放置,请参阅 后端选择指南。
更多指南
绑定
这些项目封装了 stable-diffusion.cpp,以便在其他语言/框架中更轻松地使用。
- Golang (非 cgo): seasonjs/stable-diffusion (https://github.com/seasonjs/stable-diffusion)
- Golang (cgo): Binozo/GoStableDiffusion (https://github.com/Binozo/GoStableDiffusion)
- Golang (非 cgo): l8bloom/gosd (https://github.com/l8bloom/gosd)
- C#: DarthAffe/StableDiffusion.NET (https://github.com/DarthAffe/StableDiffusion.NET)
- Python: william-murray1204/stable-diffusion-cpp-python (https://github.com/william-murray1204/stable-diffusion-cpp-python)
- Rust: newfla/diffusion-rs (https://github.com/newfla/diffusion-rs)
- Flutter/Dart: rmatif/Local-Diffusion (https://github.com/rmatif/Local-Diffusion)
用户界面
这些项目使用 stable-diffusion.cpp 作为其图像生成的后端。
- GIMP 插件 (https://github.com/themanyone/gimp-plugins)
- Jellybox (https://jellybox.com)
- Stable Diffusion GUI (https://github.com/fszontagh/sd.cpp.gui.wx)
- Stable Diffusion CLI-GUI (https://github.com/piallai/stable-diffusion.cpp)
- Local Diffusion (https://github.com/rmatif/Local-Diffusion)
- sd.cpp-webui (https://github.com/daniandtheweb/sd.cpp-webui)
- LocalAI (https://github.com/mudler/LocalAI)
- Neural-Pixel (https://github.com/Luiz-Alcantara/Neural-Pixel)
- KoboldCpp (https://github.com/LostRuins/koboldcpp)
贡献者
感谢所有已为 stable-diffusion.cpp 做出贡献的人! 贡献者列表 (https://github.com/leejet/stable-diffusion.cpp/graphs/contributors)
相似文章
AUTOMATIC1111/stable-diffusion-webui
该开源项目为 Stable Diffusion 提供了一个功能丰富的 Web 界面,使用户能够借助各种 AI 模型和扩展轻松生成、编辑和放大图像。项目基于 Gradio 构建,支持 txt2img、img2img、inpainting 以及众多由社区驱动的本地 AI 图像生成工具。
将 Nunchaku 4-bit 扩散推理引入 Diffusers
Nunchaku 是一款基于 SVDQuant 的 4-bit 扩散推理引擎,现已原生集成到 Hugging Face Diffusers 中,通过简单的 from_pretrained() 调用即可快速、节省内存地加载量化扩散模型。
线性约束下的条件扩散:Langevin 混合与信息论保证
本文分析了预训练扩散模型在线性逆问题上的零样本条件采样,提供了信息论保证并提出了一种投影 Langevin 初始化方法。
DiffusionGemma
Google 发布了 DiffusionGemma,这是一个采用 Apache 2 许可证的开源权重文本生成模型(总参数量 26B,活跃参数量 4B),通过 NVIDIA 的 NIM 云 API 展示了极高的推理速度。
来自NVIDIA的Nemotron-Labs-Diffusion
NVIDIA发布了Nemotron-Labs-Diffusion模型系列(3B至14B),该系列同时支持AR解码和扩散解码,并采用新颖的自推测机制,在多种硬件平台上相比标准AR和Eagle3方法实现了显著加速(最高达4倍)。