开源项目 GitHub Trending 2026-09-24T12:01 正文 ok 346 words

🔥 leejet/stable-diffusion.cpp:纯 C/C++ 扩散模型推理引擎

英文标题:🔥 leejet/stable-diffusion.cpp

stable-diffusion.cpp 是一个基于 ggml 的纯 C/C++ 扩散模型推理项目,设计思路与 llama.cpp 类似,主打轻量、无外部依赖和跨平台部署。项目支持 Stable Diffusion、Flux、Wan、Qwen Image、Z-Image 等模型,并覆盖 CPU、CUDA、Vulkan、Metal、OpenCL 和 SYCL 后端,以及 PyTorch、Safetensors、GGUF 等权重格式。更新记录显示,该项目持续快速跟进新模型,包括 Qwen-Image-2.1、LTX-2.5、MiniMax-H3、Krea2、Ideogram4 和 FLUX.2 等。对开发者而言,它提供命令行图像生成、权重转换、显存优化、可复现随机数及 WebUI 兼容参数写入等能力,适合构建本地或嵌入式图像生成应用。
打开原文相关 2 · 机会 2
media1.0 MB media5.1 KB media419.6 KB

中文

使用纯 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 的原生 C/C++ 实现,工作方式与 llama.cpp 相同

  • 极为轻量,且没有外部依赖

  • 支持的模型

  • 支持的后端

    • CPU(x86 架构支持 AVX、AVX2 和 AVX512)
    • CUDA
    • Vulkan
    • Metal
    • OpenCL
    • SYCL
  • 支持的权重格式

    • Pytorch checkpoint(.ckpt、.pth 或 .pt)
    • Safetensors(.safetensors)
    • GGUF(.gguf)
  • 转换模式支持将模型权重转换为 .gguf 或 .safetensors

  • 支持的平台

  • Flash Attention,用于优化内存使用

  • 负向提示词

  • stable-diffusion-webui 风格的分词器(并非支持全部功能,目前仅支持 token 权重)

  • VAE 分块处理,以降低内存使用量

  • 采样方法

  • 跨平台可复现性

    • --rng cuda:默认选项,与 stable-diffusion-webui GPU RNG 保持一致
    • --rng cpu:与 comfyui RNG 保持一致
  • 将生成参数以与 WebUI 兼容的文本字符串形式嵌入 PNG 输出文件

只需一条命令即可生成图像

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

如需查看详细的命令行参数,请参阅 cli 文档。

如果希望提升性能或降低 VRAM/RAM 使用量,请参阅性能指南。有关运行时与参数的后端分配,请参阅后端选择指南。

这些项目封装了 stable-diffusion.cpp,以便在其他语言或框架中更方便地使用。

这些项目将 stable-diffusion.cpp 作为图像生成后端。

感谢所有已经为 stable-diffusion.cpp 作出贡献的人!

贡献者

English / 原文

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.

  • 2026/09/20 🚀 stable-diffusion.cpp adds Day-0 support for Qwen-Image-2.1

  • 2026/08/20 🚀 stable-diffusion.cpp now supports LTX-2.5

  • 2026/08/04 🚀 stable-diffusion.cpp adds Day-1 support for MiniMax-H3

  • 2026/06/25 🚀 stable-diffusion.cpp now supports Krea2

  • 2026/06/04 🚀 stable-diffusion.cpp now supports Ideogram4

  • 2026/05/31 🚀 stable-diffusion.cpp now supports PiD

  • 2026/05/27 🚀 stable-diffusion.cpp now supports Lens

  • 2026/05/17 🚀 stable-diffusion.cpp now supports LTX-2.3

  • 2026/04/11 🚀 stable-diffusion.cpp now uses a brand-new embedded web UI.

  • 2026/01/18 🚀 stable-diffusion.cpp now supports FLUX.2-klein

  • 2025/12/01 🚀 stable-diffusion.cpp now supports Z-Image

  • 2025/11/30 🚀 stable-diffusion.cpp now supports FLUX.2-dev

  • 2025/10/13 🚀 stable-diffusion.cpp now supports Qwen-Image-Edit / Qwen-Image-Edit 2509

  • 2025/10/12 🚀 stable-diffusion.cpp now supports Qwen-Image

  • 2025/09/14 🚀 stable-diffusion.cpp now supports Wan2.1 Vace

  • 2025/09/06 🚀 stable-diffusion.cpp now supports Wan2.1 / Wan2.2

  • Plain C/C++ implementation based on ggml, working in the same way as llama.cpp

  • Super lightweight and without external dependencies

  • Supported models

  • Supported backends

    • CPU (AVX, AVX2 and AVX512 support for x86 architectures)
    • CUDA
    • Vulkan
    • Metal
    • OpenCL
    • SYCL
  • Supported weight formats

    • Pytorch checkpoint (.ckpt or .pth or .pt)
    • Safetensors (.safetensors)
    • GGUF (.gguf)
  • Convert mode supports converting model weights to .gguf or .safetensors

  • Supported platforms

  • 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

  • Cross-platform reproducibility

    • --rng cuda, default, consistent with the stable-diffusion-webui GPU RNG
    • --rng cpu, consistent with the comfyui RNG
  • Embedds generation parameters into png output as webui-compatible text string

Generate an image with just one command

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

For detailed command-line arguments, check outcli doc.

If you want to improve performance or reduce VRAM/RAM usage, please refer to performance guide. For runtime and parameter backend placement, see the backend selection guide.

These projects wrap stable-diffusion.cpp for easier use in other languages/frameworks.

These projects use stable-diffusion.cpp as a backend for their image generation.

Thank you to all the people who have already contributed to stable-diffusion.cpp!

Contributors