Initial release
@@ -0,0 +1,12 @@
|
|||||||
|
BasedOnStyle: Chromium
|
||||||
|
UseTab: Never
|
||||||
|
IndentWidth: 4
|
||||||
|
TabWidth: 4
|
||||||
|
AllowShortIfStatementsOnASingleLine: false
|
||||||
|
ColumnLimit: 0
|
||||||
|
AccessModifierOffset: -4
|
||||||
|
NamespaceIndentation: All
|
||||||
|
FixNamespaceComments: false
|
||||||
|
AlignAfterOpenBracket: true
|
||||||
|
AlignConsecutiveAssignments: true
|
||||||
|
IndentCaseLabels: true
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
Checks: >
|
||||||
|
modernize-make-shared,
|
||||||
|
modernize-use-nullptr,
|
||||||
|
modernize-use-override,
|
||||||
|
modernize-pass-by-value,
|
||||||
|
modernize-return-braced-init-list,
|
||||||
|
modernize-deprecated-headers,
|
||||||
|
HeaderFilterRegex: '^$'
|
||||||
|
WarningsAsErrors: ''
|
||||||
|
FormatStyle: none
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
build*/
|
||||||
|
docs/
|
||||||
|
test/
|
||||||
|
|
||||||
|
.cache/
|
||||||
|
*.swp
|
||||||
|
models/
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
build*/
|
||||||
|
cmake-build-*/
|
||||||
|
test/
|
||||||
|
.vscode/
|
||||||
|
.idea/
|
||||||
|
.cache/
|
||||||
|
*.swp
|
||||||
|
*.bat
|
||||||
|
*.bin
|
||||||
|
*.exe
|
||||||
|
*.gguf
|
||||||
|
output*.png
|
||||||
|
models*
|
||||||
|
*.log
|
||||||
|
preview.png
|
||||||
|
.claude/
|
||||||
|
CLAUDE.local.md
|
||||||
|
.agents/
|
||||||
|
.codex/
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
[submodule "ggml"]
|
||||||
|
path = ggml
|
||||||
|
url = https://github.com/leejet/ggml.git
|
||||||
|
[submodule "examples/server/frontend"]
|
||||||
|
path = examples/server/frontend
|
||||||
|
url = https://github.com/leejet/sdcpp-webui.git
|
||||||
|
[submodule "thirdparty/libwebp"]
|
||||||
|
path = thirdparty/libwebp
|
||||||
|
url = https://github.com/webmproject/libwebp.git
|
||||||
|
[submodule "thirdparty/libwebm"]
|
||||||
|
path = thirdparty/libwebm
|
||||||
|
url = https://github.com/webmproject/libwebm.git
|
||||||
@@ -0,0 +1,183 @@
|
|||||||
|
# Instructions for stable-diffusion.cpp
|
||||||
|
|
||||||
|
This document is for AI coding agents working in this repository. It should
|
||||||
|
describe agent-specific workflow, repository routing, editing boundaries, and
|
||||||
|
project-specific pitfalls.
|
||||||
|
|
||||||
|
For general contribution rules, including PR scope, commit conventions, code
|
||||||
|
style, dependency updates, security hygiene, and AI-assisted contribution policy,
|
||||||
|
see `CONTRIBUTING.md`.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Agent Operating Rules
|
||||||
|
|
||||||
|
Before analyzing or modifying the repository:
|
||||||
|
|
||||||
|
1. Read this file.
|
||||||
|
2. Use `rg` / `rg --files` or directory listing commands to confirm the current
|
||||||
|
tree before relying on a path.
|
||||||
|
3. Start from `src/` and relevant `docs/` for runtime behavior.
|
||||||
|
4. Read the relevant code before editing.
|
||||||
|
5. Prefer the smallest change that fits the existing architecture.
|
||||||
|
6. Report focused verification and mention any tests not run.
|
||||||
|
|
||||||
|
Agents must not:
|
||||||
|
|
||||||
|
* Run `git push`, create PRs, or submit issue/PR comments on the user's behalf.
|
||||||
|
* Create commits unless the user explicitly requests that specific commit.
|
||||||
|
* Modify `ggml/`, `thirdparty/`, or `examples/server/frontend/` unless
|
||||||
|
explicitly requested and necessary.
|
||||||
|
* Read large local model files or tokenizer vocabulary files.
|
||||||
|
* Rewrite unrelated code for style-only reasons.
|
||||||
|
* Add secrets, model weights, generated binaries, local absolute paths, or
|
||||||
|
machine-specific output.
|
||||||
|
|
||||||
|
When a change is large, architectural, or likely to affect public behavior,
|
||||||
|
pause and present a short plan before editing.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Repository Map and Editing Boundaries
|
||||||
|
|
||||||
|
This is a routing map for agents, not a full architecture document. The layout
|
||||||
|
can change, so verify paths before using them. Do not inspect excluded
|
||||||
|
large-data directories while checking the tree.
|
||||||
|
|
||||||
|
### Primary Project Code
|
||||||
|
|
||||||
|
Core implementation lives under `src/`.
|
||||||
|
|
||||||
|
Current source layout includes:
|
||||||
|
|
||||||
|
* `src/core/` - shared tensor, ggml integration, backend, graph, RNG, and utility
|
||||||
|
code.
|
||||||
|
* `src/model/` - model families and model components.
|
||||||
|
* `src/model_io/` - model file loading, GGUF, safetensors, pickle, and related
|
||||||
|
serialization helpers.
|
||||||
|
* `src/runtime/` - sampling, denoising, guidance, caching, preprocessing, and
|
||||||
|
runtime execution helpers.
|
||||||
|
* `src/tokenizers/` - tokenizer implementations.
|
||||||
|
* `src/conditioning/` - conditioning and prompt-related implementation.
|
||||||
|
* `src/extensions/` - optional feature extensions.
|
||||||
|
* top-level `src/*.cpp` and `src/*.h` files - public implementation entry
|
||||||
|
points, model loading, conversion, versioning, and shared managers.
|
||||||
|
|
||||||
|
`src/tokenizers/vocab/` contains large tokenizer vocabulary data. Do not read or
|
||||||
|
parse files in this directory; reference the path only when necessary.
|
||||||
|
|
||||||
|
### Public API
|
||||||
|
|
||||||
|
`include/` contains the C API exposed by the project. Currently the primary
|
||||||
|
public header is `include/stable-diffusion.h`.
|
||||||
|
|
||||||
|
Treat public headers as stable API. Avoid breaking compatibility unless the user
|
||||||
|
explicitly requests it. If public behavior changes, update relevant examples or
|
||||||
|
documentation.
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
`examples/` contains programs demonstrating library usage.
|
||||||
|
|
||||||
|
* `examples/cli/` - command line program for running models, testing features,
|
||||||
|
and debugging.
|
||||||
|
* `examples/common/` - shared example support code.
|
||||||
|
* `examples/server/` - server application built on top of the library.
|
||||||
|
* `examples/server/frontend/` - git submodule containing independent frontend
|
||||||
|
code. Avoid modifying it unless explicitly requested.
|
||||||
|
|
||||||
|
### Documentation and Tooling
|
||||||
|
|
||||||
|
* `docs/` - documentation for supported models, build options, behavior, and
|
||||||
|
workflows.
|
||||||
|
* `scripts/` - development, model processing, build automation, formatting, and
|
||||||
|
tooling scripts.
|
||||||
|
* `cmake/` - CMake support modules.
|
||||||
|
* `docker/` - Docker-related project files.
|
||||||
|
* `assets/` - documentation assets; not runtime code.
|
||||||
|
|
||||||
|
### External, Local, and Generated State
|
||||||
|
|
||||||
|
* `ggml/` - git submodule for the ggml dependency.
|
||||||
|
* `thirdparty/` - vendored third-party dependencies.
|
||||||
|
* `models/` - local model storage. Ignore this directory and do not read model
|
||||||
|
files.
|
||||||
|
* `test/` - local testing scripts. Use only when relevant to the task.
|
||||||
|
* `build/`, `build_*`, and similar directories - generated build outputs.
|
||||||
|
Inspect them only when debugging a build result.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Agent Workflow for Code Changes
|
||||||
|
|
||||||
|
1. Identify the relevant modules under `src/`.
|
||||||
|
2. Check whether the change touches the public API in `include/`.
|
||||||
|
3. Consult relevant `docs/` and examples before changing user-facing behavior.
|
||||||
|
4. Follow existing local patterns before adding new abstractions.
|
||||||
|
5. Keep edits scoped to the requested behavior.
|
||||||
|
6. Run the narrowest useful build, test, or inspection command available.
|
||||||
|
|
||||||
|
Follow `CONTRIBUTING.md` for formatting, naming, PR expectations, dependency
|
||||||
|
update policy, and security rules.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Code Comments
|
||||||
|
|
||||||
|
Keep comments rare and useful.
|
||||||
|
|
||||||
|
Do not add comments that only describe what the code does. Add comments only
|
||||||
|
when the code cannot fully express the logic, the logic is unusually complex, or
|
||||||
|
there are historical reasons, invariants, constraints, compatibility concerns,
|
||||||
|
or known pitfalls that future maintainers need to understand.
|
||||||
|
|
||||||
|
Do not add task-specific comments that will be meaningless after review.
|
||||||
|
|
||||||
|
Examples from the current codebase:
|
||||||
|
|
||||||
|
```cpp
|
||||||
|
// GOOD: explains a safety constraint that is not obvious from the assignment.
|
||||||
|
// From src/model_io/pickle_io.cpp.
|
||||||
|
// Non-tensor checkpoint metadata can use REDUCE for arbitrary
|
||||||
|
// Python objects. Do not execute it; keep stack shape only.
|
||||||
|
stack.push_back(make_none_value());
|
||||||
|
|
||||||
|
// BAD: describes only what the next line does.
|
||||||
|
// Set the token count to zero.
|
||||||
|
token_count = 0;
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Text File Encoding
|
||||||
|
|
||||||
|
When reading or editing repository text files:
|
||||||
|
|
||||||
|
* Prefer UTF-8 with LF for Markdown, frontend source, JSON, and other text-first
|
||||||
|
project files unless the file already clearly uses a different encoding.
|
||||||
|
* Do not assume terminal output encoding matches file encoding on Windows.
|
||||||
|
* A file that looks garbled in PowerShell output may still be valid UTF-8.
|
||||||
|
* When inspecting UTF-8 files in PowerShell, prefer explicit UTF-8 reads such as:
|
||||||
|
* `[Console]::OutputEncoding = [System.Text.Encoding]::UTF8`
|
||||||
|
* `Get-Content -Encoding utf8 <path>`
|
||||||
|
* Avoid rewriting a file purely because console output looked garbled; verify
|
||||||
|
the actual file encoding first.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Tensor and Layout Notes
|
||||||
|
|
||||||
|
Additional tensor/layout rules for this codebase:
|
||||||
|
|
||||||
|
* `sd::Tensor` shape order is not PyTorch/NumPy-style. `shape()[0]` is the
|
||||||
|
lowest and most contiguous dimension, and higher indices are higher
|
||||||
|
dimensions.
|
||||||
|
* Broadcasting for `sd::Tensor` must align dimensions from low to high dimension
|
||||||
|
indices. If one tensor has fewer dimensions, append implicit `1`s at the
|
||||||
|
higher-dimension end.
|
||||||
|
* `ggml_n_dims` / `ggml_n_dims(tensor)` can drop trailing singleton high
|
||||||
|
dimensions. Do not assume a logical trailing dimension of `1` will still be
|
||||||
|
counted in ggml metadata.
|
||||||
|
* Internal tensor-returning interfaces use an empty `sd::Tensor` to represent
|
||||||
|
null, absent, or failure states. Do not add `std::optional<sd::Tensor<...>>`
|
||||||
|
for internal APIs unless a distinct semantic state is truly required.
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
@AGENTS.md
|
||||||
|
|
||||||
|
## Claude Code
|
||||||
|
|
||||||
|
Follow `AGENTS.md` as the shared repository instructions.
|
||||||
|
|
||||||
|
Do not duplicate contribution, style, PR, dependency, or security policy here;
|
||||||
|
use `CONTRIBUTING.md` as the canonical source for those rules.
|
||||||
|
|
||||||
|
Keep Claude-specific project notes in this file only when they do not apply to
|
||||||
|
other coding agents.
|
||||||
@@ -0,0 +1,401 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.12)
|
||||||
|
project("stable-diffusion")
|
||||||
|
|
||||||
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
|
|
||||||
|
if (NOT XCODE AND NOT MSVC AND NOT CMAKE_BUILD_TYPE)
|
||||||
|
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
|
||||||
|
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (MSVC)
|
||||||
|
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
||||||
|
add_compile_definitions(_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
|
||||||
|
# /MP is MSVC-only: icx rejects it outright once offloading is enabled.
|
||||||
|
add_compile_options(
|
||||||
|
$<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:MSVC>>:/MP>
|
||||||
|
$<$<COMPILE_LANGUAGE:C>:/utf-8>
|
||||||
|
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/MP>
|
||||||
|
$<$<COMPILE_LANGUAGE:CXX>:/utf-8>
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||||
|
|
||||||
|
if(APPLE)
|
||||||
|
function(sd_set_macos_rpaths target)
|
||||||
|
get_target_property(target_type ${target} TYPE)
|
||||||
|
if(target_type STREQUAL "EXECUTABLE")
|
||||||
|
set(runtime_paths "@executable_path" "@executable_path/../lib")
|
||||||
|
elseif(target_type STREQUAL "SHARED_LIBRARY" OR target_type STREQUAL "MODULE_LIBRARY")
|
||||||
|
set(runtime_paths "@loader_path" "@loader_path/../lib")
|
||||||
|
set_target_properties(${target} PROPERTIES
|
||||||
|
MACOSX_RPATH ON
|
||||||
|
INSTALL_NAME_DIR "@rpath"
|
||||||
|
BUILD_WITH_INSTALL_NAME_DIR ON
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Release artifacts zip the build output directly, so keep macOS rpaths relocatable.
|
||||||
|
set_target_properties(${target} PROPERTIES
|
||||||
|
BUILD_RPATH "${runtime_paths}"
|
||||||
|
INSTALL_RPATH "${runtime_paths}"
|
||||||
|
BUILD_WITH_INSTALL_RPATH ON
|
||||||
|
)
|
||||||
|
endfunction()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
|
||||||
|
set(SD_STANDALONE ON)
|
||||||
|
else()
|
||||||
|
set(SD_STANDALONE OFF)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(SD_SUBMODULE_WEBP FALSE)
|
||||||
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libwebp/CMakeLists.txt")
|
||||||
|
set(SD_SUBMODULE_WEBP TRUE)
|
||||||
|
endif()
|
||||||
|
if(SD_SUBMODULE_WEBP)
|
||||||
|
set(SD_WEBP_DEFAULT ON)
|
||||||
|
else()
|
||||||
|
set(SD_WEBP_DEFAULT ${SD_USE_SYSTEM_WEBP})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(SD_SUBMODULE_WEBM FALSE)
|
||||||
|
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/libwebm/CMakeLists.txt")
|
||||||
|
set(SD_SUBMODULE_WEBM TRUE)
|
||||||
|
endif()
|
||||||
|
if(SD_SUBMODULE_WEBM)
|
||||||
|
set(SD_WEBM_DEFAULT ON)
|
||||||
|
else()
|
||||||
|
set(SD_WEBM_DEFAULT ${SD_USE_SYSTEM_WEBM})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
#
|
||||||
|
# Option list
|
||||||
|
#
|
||||||
|
|
||||||
|
# general
|
||||||
|
#option(SD_BUILD_TESTS "sd: build tests" ${SD_STANDALONE})
|
||||||
|
option(SD_BUILD_EXAMPLES "sd: build examples" ${SD_STANDALONE})
|
||||||
|
option(SD_WEBP "sd: enable WebP image I/O support" ${SD_WEBP_DEFAULT})
|
||||||
|
option(SD_USE_SYSTEM_WEBP "sd: link against system libwebp" OFF)
|
||||||
|
option(SD_WEBM "sd: enable WebM video output support" ${SD_WEBM_DEFAULT})
|
||||||
|
option(SD_USE_SYSTEM_WEBM "sd: link against system libwebm" OFF)
|
||||||
|
option(SD_CUDA "sd: cuda backend" OFF)
|
||||||
|
option(SD_HIPBLAS "sd: rocm backend" OFF)
|
||||||
|
option(SD_METAL "sd: metal backend" OFF)
|
||||||
|
option(SD_VULKAN "sd: vulkan backend" OFF)
|
||||||
|
option(SD_OPENCL "sd: opencl backend" OFF)
|
||||||
|
option(SD_SYCL "sd: sycl backend" OFF)
|
||||||
|
option(SD_MUSA "sd: musa backend" OFF)
|
||||||
|
option(SD_BUILD_SHARED_LIBS "sd: build shared libs" OFF)
|
||||||
|
option(SD_BUILD_SHARED_GGML_LIB "sd: build ggml as a separate shared lib" OFF)
|
||||||
|
option(SD_USE_SYSTEM_GGML "sd: use system-installed GGML library" OFF)
|
||||||
|
#option(SD_BUILD_SERVER "sd: build server example" ON)
|
||||||
|
|
||||||
|
set(CMAKE_C_STANDARD 11)
|
||||||
|
set(CMAKE_C_STANDARD_REQUIRED true)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED true)
|
||||||
|
|
||||||
|
if(SD_CUDA)
|
||||||
|
message("-- Use CUDA as backend stable-diffusion")
|
||||||
|
set(GGML_CUDA ON)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(SD_METAL)
|
||||||
|
message("-- Use Metal as backend stable-diffusion")
|
||||||
|
set(GGML_METAL ON)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (SD_VULKAN)
|
||||||
|
message("-- Use Vulkan as backend stable-diffusion")
|
||||||
|
set(GGML_VULKAN ON)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (SD_OPENCL)
|
||||||
|
message("-- Use OpenCL as backend stable-diffusion")
|
||||||
|
set(GGML_OPENCL ON)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if (SD_HIPBLAS)
|
||||||
|
message("-- Use HIPBLAS as backend stable-diffusion")
|
||||||
|
set(GGML_HIP ON)
|
||||||
|
# ggml-hip's device-stub objects must be position-independent, or the
|
||||||
|
# default-PIE sd-cli link fails with `relocation R_X86_64_32 ... cannot be
|
||||||
|
# used when making a PIE object` on distros that default to PIE
|
||||||
|
# (Ubuntu 24.04, Fedora 40+, Debian 12+). The shared-library branch below
|
||||||
|
# already sets this; the static build (the HIP default) did not.
|
||||||
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
if(SD_MUSA)
|
||||||
|
message("-- Use MUSA as backend stable-diffusion")
|
||||||
|
set(GGML_MUSA ON)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(SD_WEBP)
|
||||||
|
if(NOT SD_SUBMODULE_WEBP AND NOT SD_USE_SYSTEM_WEBP)
|
||||||
|
message(FATAL_ERROR "WebP support enabled but no source found.
|
||||||
|
Either initialize the submodule:\n git submodule update --init thirdparty/libwebp\n\n"
|
||||||
|
"Or link against system library:\n cmake (...) -DSD_USE_SYSTEM_WEBP=ON")
|
||||||
|
endif()
|
||||||
|
if(SD_USE_SYSTEM_WEBP)
|
||||||
|
find_package(WebP)
|
||||||
|
if(WebP_FOUND)
|
||||||
|
add_library(webp ALIAS WebP::webp)
|
||||||
|
# libwebp CMake target naming is not consistent across versions/distros.
|
||||||
|
# Some export WebP::libwebpmux, others export WebP::webpmux.
|
||||||
|
if(TARGET WebP::libwebpmux)
|
||||||
|
add_library(libwebpmux ALIAS WebP::libwebpmux)
|
||||||
|
elseif(TARGET WebP::webpmux)
|
||||||
|
add_library(libwebpmux ALIAS WebP::webpmux)
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"Could not find a compatible webpmux target in system WebP package. "
|
||||||
|
"Expected WebP::libwebpmux or WebP::webpmux."
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules(WebP REQUIRED IMPORTED_TARGET GLOBAL libwebp)
|
||||||
|
pkg_check_modules(WebPMux REQUIRED IMPORTED_TARGET GLOBAL libwebpmux)
|
||||||
|
link_libraries(PkgConfig::WebP)
|
||||||
|
link_libraries(PkgConfig::WebPMux)
|
||||||
|
add_library(libwebpmux ALIAS PkgConfig::WebPMux)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(SD_WEBM)
|
||||||
|
if(NOT SD_WEBP)
|
||||||
|
message(FATAL_ERROR "SD_WEBM requires SD_WEBP because WebM output reuses libwebp VP8 encoding.")
|
||||||
|
endif()
|
||||||
|
if(NOT SD_SUBMODULE_WEBM AND NOT SD_USE_SYSTEM_WEBM)
|
||||||
|
message(FATAL_ERROR "WebM support enabled but no source found.
|
||||||
|
Either initialize the submodule:\n git submodule update --init thirdparty/libwebm\n\n"
|
||||||
|
"Or link against system library:\n cmake (...) -DSD_USE_SYSTEM_WEBM=ON")
|
||||||
|
endif()
|
||||||
|
if(SD_USE_SYSTEM_WEBM)
|
||||||
|
find_package(PkgConfig)
|
||||||
|
if(PkgConfig_FOUND)
|
||||||
|
pkg_check_modules(WebM REQUIRED IMPORTED_TARGET GLOBAL libwebm)
|
||||||
|
endif()
|
||||||
|
if(PkgConfig_FOUND AND WebM_FOUND)
|
||||||
|
link_libraries(PkgConfig::WebM)
|
||||||
|
else()
|
||||||
|
find_path(WEBM_INCLUDE_DIR
|
||||||
|
NAMES mkvmuxer/mkvmuxer.h mkvparser/mkvparser.h common/webmids.h
|
||||||
|
PATH_SUFFIXES webm
|
||||||
|
REQUIRED)
|
||||||
|
find_library(WEBM_LIBRARY
|
||||||
|
NAMES webm libwebm
|
||||||
|
REQUIRED)
|
||||||
|
|
||||||
|
add_library(webm UNKNOWN IMPORTED)
|
||||||
|
set_target_properties(webm PROPERTIES
|
||||||
|
IMPORTED_LOCATION "${WEBM_LIBRARY}"
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${WEBM_INCLUDE_DIR}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if (SD_RPC)
|
||||||
|
message("-- Use RPC as backend stable-diffusion")
|
||||||
|
set(GGML_RPC ON)
|
||||||
|
add_definitions(-DSD_USE_RPC)
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
set(SD_LIB stable-diffusion)
|
||||||
|
|
||||||
|
file(GLOB SD_LIB_SOURCES CONFIGURE_DEPENDS
|
||||||
|
"src/*.h"
|
||||||
|
"src/*.cpp"
|
||||||
|
"src/*.hpp"
|
||||||
|
"src/conditioning/*.h"
|
||||||
|
"src/conditioning/*.cpp"
|
||||||
|
"src/conditioning/*.hpp"
|
||||||
|
"src/core/*.h"
|
||||||
|
"src/core/*.cpp"
|
||||||
|
"src/core/*.hpp"
|
||||||
|
"src/extensions/*.h"
|
||||||
|
"src/extensions/*.cpp"
|
||||||
|
"src/extensions/*.hpp"
|
||||||
|
"src/model/*/*.h"
|
||||||
|
"src/model/*/*.cpp"
|
||||||
|
"src/model/*/*.hpp"
|
||||||
|
"src/runtime/*.h"
|
||||||
|
"src/runtime/*.cpp"
|
||||||
|
"src/runtime/*.hpp"
|
||||||
|
"src/model_io/*.h"
|
||||||
|
"src/model_io/*.cpp"
|
||||||
|
"src/tokenizers/*.h"
|
||||||
|
"src/tokenizers/*.cpp"
|
||||||
|
"src/tokenizers/vocab/*.h"
|
||||||
|
"src/tokenizers/vocab/*.cpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
find_program(GIT_EXE NAMES git git.exe NO_CMAKE_FIND_ROOT_PATH)
|
||||||
|
if(GIT_EXE)
|
||||||
|
execute_process(COMMAND ${GIT_EXE} describe --tags --abbrev=7 --dirty=+
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
OUTPUT_VARIABLE SDCPP_BUILD_VERSION
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
ERROR_QUIET
|
||||||
|
)
|
||||||
|
execute_process(COMMAND ${GIT_EXE} rev-parse --short HEAD
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||||
|
OUTPUT_VARIABLE SDCPP_BUILD_COMMIT
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
ERROR_QUIET
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT SDCPP_BUILD_VERSION)
|
||||||
|
set(SDCPP_BUILD_VERSION unknown)
|
||||||
|
endif()
|
||||||
|
message(STATUS "stable-diffusion.cpp version ${SDCPP_BUILD_VERSION}")
|
||||||
|
|
||||||
|
if(NOT SDCPP_BUILD_COMMIT)
|
||||||
|
set(SDCPP_BUILD_COMMIT unknown)
|
||||||
|
endif()
|
||||||
|
message(STATUS "stable-diffusion.cpp commit ${SDCPP_BUILD_COMMIT}")
|
||||||
|
|
||||||
|
set_property(
|
||||||
|
SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/src/version.cpp
|
||||||
|
APPEND PROPERTY COMPILE_DEFINITIONS
|
||||||
|
SDCPP_BUILD_COMMIT=${SDCPP_BUILD_COMMIT} SDCPP_BUILD_VERSION=${SDCPP_BUILD_VERSION}
|
||||||
|
)
|
||||||
|
|
||||||
|
if(SD_BUILD_SHARED_LIBS)
|
||||||
|
message("-- Build shared library")
|
||||||
|
message(${SD_LIB_SOURCES})
|
||||||
|
if(NOT SD_BUILD_SHARED_GGML_LIB)
|
||||||
|
set(BUILD_SHARED_LIBS OFF)
|
||||||
|
endif()
|
||||||
|
add_library(${SD_LIB} SHARED ${SD_LIB_SOURCES})
|
||||||
|
add_definitions(-DSD_BUILD_SHARED_LIB)
|
||||||
|
target_compile_definitions(${SD_LIB} PRIVATE -DSD_BUILD_DLL)
|
||||||
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
|
else()
|
||||||
|
message("-- Build static library")
|
||||||
|
if(NOT SD_BUILD_SHARED_GGML_LIB)
|
||||||
|
set(BUILD_SHARED_LIBS OFF)
|
||||||
|
endif()
|
||||||
|
add_library(${SD_LIB} STATIC ${SD_LIB_SOURCES})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(APPLE)
|
||||||
|
sd_set_macos_rpaths(${SD_LIB})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(SD_SYCL)
|
||||||
|
message("-- Use SYCL as backend stable-diffusion")
|
||||||
|
set(GGML_SYCL ON)
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing -fsycl")
|
||||||
|
# disable fast-math on host, see:
|
||||||
|
# https://www.intel.com/content/www/us/en/docs/cpp-compiler/developer-guide-reference/2021-10/fp-model-fp.html
|
||||||
|
if (WIN32)
|
||||||
|
set(SYCL_COMPILE_OPTIONS /fp:precise)
|
||||||
|
else()
|
||||||
|
set(SYCL_COMPILE_OPTIONS -fp-model=precise)
|
||||||
|
endif()
|
||||||
|
message("-- Turn off fast-math for host in SYCL backend")
|
||||||
|
target_compile_options(${SD_LIB} PRIVATE ${SYCL_COMPILE_OPTIONS})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
|
||||||
|
|
||||||
|
if (NOT SD_USE_SYSTEM_GGML)
|
||||||
|
# see https://github.com/ggerganov/ggml/pull/682
|
||||||
|
add_definitions(-DGGML_MAX_NAME=160)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# deps
|
||||||
|
# Only add ggml if it hasn't been added yet
|
||||||
|
if (NOT TARGET ggml)
|
||||||
|
if (SD_USE_SYSTEM_GGML)
|
||||||
|
find_package(ggml REQUIRED)
|
||||||
|
if (NOT ggml_FOUND)
|
||||||
|
message(FATAL_ERROR "System-installed GGML library not found.")
|
||||||
|
endif()
|
||||||
|
add_library(ggml ALIAS ggml::ggml)
|
||||||
|
else()
|
||||||
|
add_subdirectory(ggml)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_subdirectory(thirdparty)
|
||||||
|
|
||||||
|
target_sources(${SD_LIB} PRIVATE $<TARGET_OBJECTS:zip>)
|
||||||
|
target_link_libraries(${SD_LIB} PUBLIC ggml)
|
||||||
|
target_include_directories(${SD_LIB} PUBLIC . src include)
|
||||||
|
target_include_directories(${SD_LIB} PRIVATE src/core)
|
||||||
|
target_include_directories(${SD_LIB} PUBLIC . thirdparty)
|
||||||
|
target_compile_features(${SD_LIB} PUBLIC c_std_11 cxx_std_17)
|
||||||
|
|
||||||
|
|
||||||
|
if (SD_BUILD_EXAMPLES)
|
||||||
|
add_subdirectory(examples)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# install
|
||||||
|
#
|
||||||
|
|
||||||
|
include(CMakePackageConfigHelpers)
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
set(SD_INSTALL_VERSION "${SDCPP_BUILD_VERSION}")
|
||||||
|
set(SD_INSTALL_COMMIT "${SDCPP_BUILD_COMMIT}")
|
||||||
|
set(SD_SHARED_LIB ${SD_BUILD_SHARED_LIBS})
|
||||||
|
|
||||||
|
set(SD_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Location of header files")
|
||||||
|
set(SD_LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Location of library files")
|
||||||
|
set(SD_BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Location of binary files")
|
||||||
|
|
||||||
|
set(SD_PUBLIC_HEADERS
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/include/stable-diffusion.h)
|
||||||
|
|
||||||
|
set_target_properties(${SD_LIB}
|
||||||
|
PROPERTIES
|
||||||
|
PUBLIC_HEADER "${SD_PUBLIC_HEADERS}")
|
||||||
|
|
||||||
|
|
||||||
|
install(TARGETS ${SD_LIB}
|
||||||
|
ARCHIVE
|
||||||
|
LIBRARY
|
||||||
|
RUNTIME
|
||||||
|
PUBLIC_HEADER)
|
||||||
|
|
||||||
|
|
||||||
|
configure_package_config_file(
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/cmake/stable-diffusion-config.cmake.in
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/stable-diffusion-config.cmake
|
||||||
|
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/stable-diffusion
|
||||||
|
PATH_VARS SD_INCLUDE_INSTALL_DIR
|
||||||
|
SD_LIB_INSTALL_DIR
|
||||||
|
SD_BIN_INSTALL_DIR )
|
||||||
|
|
||||||
|
write_basic_package_version_file(
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/stable-diffusion-version.cmake
|
||||||
|
VERSION ${SD_INSTALL_VERSION}
|
||||||
|
COMPATIBILITY SameMajorVersion)
|
||||||
|
|
||||||
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/stable-diffusion-config.cmake
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/stable-diffusion-version.cmake
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/stable-diffusion)
|
||||||
|
|
||||||
|
configure_file(cmake/stable-diffusion.pc.in
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/stable-diffusion.pc"
|
||||||
|
@ONLY)
|
||||||
|
|
||||||
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/stable-diffusion.pc"
|
||||||
|
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
This document collects general contribution conventions for this repository.
|
||||||
|
|
||||||
|
## Before You Start
|
||||||
|
|
||||||
|
Before opening a PR, please search existing PRs to avoid duplicating ongoing work.
|
||||||
|
|
||||||
|
For large-scale refactors or changes with broad impact, please open an issue first to discuss the approach before submitting a PR.
|
||||||
|
|
||||||
|
If you want to update a third-party dependency, please open an issue first instead of submitting a direct PR. See [Dependency Updates](#dependency-updates) for details.
|
||||||
|
|
||||||
|
## Pull Requests
|
||||||
|
|
||||||
|
Keep each PR focused on one clear change. Large or overly complex PRs are harder to review and may not be merged.
|
||||||
|
|
||||||
|
Follow Conventional Commit-style subjects seen in history: `feat:`, `fix:`, `refactor:`, `ci:`, `docs:`, `chore:`. Keep subjects imperative and scoped.
|
||||||
|
|
||||||
|
PRs should include:
|
||||||
|
|
||||||
|
- What changed and why (short problem/solution summary).
|
||||||
|
- Verification evidence when applicable (commands and key outputs).
|
||||||
|
- Linked issue/PR context when applicable.
|
||||||
|
- Screenshots or sample outputs for UI/visual behavior changes.
|
||||||
|
|
||||||
|
## Code Style
|
||||||
|
|
||||||
|
Format code according to the repository style before submitting changes.
|
||||||
|
|
||||||
|
Formatting follows `.clang-format` (Chromium base, 4-space indent, no tabs). Run `scripts/format-code.sh` or `scripts/format-code.ps1` before opening a PR. Keep C++ standard at C++17-compatible patterns used in this repo.
|
||||||
|
|
||||||
|
Naming conventions:
|
||||||
|
|
||||||
|
- Use `PascalCase` for class/struct/type names.
|
||||||
|
- In `PascalCase` names, preserve common abbreviations in uppercase, for example `SD`, `API`, `HTTP`, `JSON`, `RGB`, `VAE`, `TAE`, `LoRA`, and `WebP`.
|
||||||
|
- Use `snake_case` for functions, methods, variables, and file names unless an existing API requires a different style.
|
||||||
|
- Use a trailing underscore for private data member names, for example `hidden_size_` or `tokenizer_`.
|
||||||
|
- Use `.h` for C and C++ header files. Do not introduce new `.hpp` headers.
|
||||||
|
- Use macro-based header include guards instead of `#pragma once`.
|
||||||
|
- Format header include guards as `__SD_{PATH}__`, where `{PATH}` is the header path in uppercase snake case without the file extension. For example, `src/sample.h` should use `__SD_SAMPLE_H__`.
|
||||||
|
- Do not introduce anonymous namespaces in new or modified code; prefer `static` file-local functions/variables or an explicit named namespace when scoping is needed.
|
||||||
|
- In `class`/`struct` definitions, place data members before member functions unless an existing type already clearly follows a different pattern.
|
||||||
|
- Keep `test_*.cpp` / `test_*.py` naming for tests.
|
||||||
|
|
||||||
|
Some older code in the project may not fully follow the current conventions. Please do not submit PRs that only rewrite existing code to match style rules.
|
||||||
|
|
||||||
|
When adding or modifying model implementations, follow the model config and weight detection conventions in [docs/model_config.md](docs/model_config.md).
|
||||||
|
|
||||||
|
## AI-Assisted Contributions
|
||||||
|
|
||||||
|
AI tools may be used to assist development, but contributors are responsible for the quality and correctness of the submitted code.
|
||||||
|
|
||||||
|
If any part of a contribution was generated with AI assistance, the contributor must perform a thorough human review before submitting the PR and understand every changed line.
|
||||||
|
|
||||||
|
Do not list AI tools as co-authors. The human contributor is the sole responsible author of the submitted code.
|
||||||
|
|
||||||
|
Please do not submit AI-generated code that you do not understand, and do not include meaningless experiments, temporary test code, or unrelated generated output in a PR.
|
||||||
|
|
||||||
|
## Dependency Updates
|
||||||
|
|
||||||
|
Do not submit PRs that update `ggml`. `ggml` updates are performed only after local validation by the maintainer.
|
||||||
|
|
||||||
|
Other third-party dependencies are not updated unless necessary. If you want to update a dependency, please open an issue first instead of submitting a direct PR.
|
||||||
|
|
||||||
|
## Security & Configuration
|
||||||
|
|
||||||
|
Do not commit model weights, secrets, or local absolute paths. Keep large binaries out of git unless intentionally tracked release assets.
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2023 leejet
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
@@ -0,0 +1,188 @@
|
|||||||
|
<p align="center">
|
||||||
|
<img src="./assets/logo.png" width="360x">
|
||||||
|
</p>
|
||||||
|
|
||||||
|
# stable-diffusion.cpp
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
<a href="https://trendshift.io/repositories/9714" target="_blank"><img src="https://trendshift.io/api/badge/repositories/9714" alt="leejet%2Fstable-diffusion.cpp | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
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.***
|
||||||
|
|
||||||
|
## 🔥Important News
|
||||||
|
|
||||||
|
* **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**
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Plain C/C++ implementation based on [ggml](https://github.com/ggml-org/ggml), working in the same way as [llama.cpp](https://github.com/ggml-org/llama.cpp)
|
||||||
|
- Super lightweight and without external dependencies
|
||||||
|
- Supported models
|
||||||
|
- Image Models
|
||||||
|
- [SD1.x, SD2.x, SD-Turbo](./docs/sd.md)
|
||||||
|
- [SDXL, SDXL-Turbo](./docs/sd.md)
|
||||||
|
- [Some SD1.x and SDXL distilled models](./docs/distilled_sd.md)
|
||||||
|
- [SD3/SD3.5](./docs/sd3.md)
|
||||||
|
- [FLUX.1-dev/FLUX.1-schnell](./docs/flux.md)
|
||||||
|
- [FLUX.2-dev/FLUX.2-klein](./docs/flux2.md)
|
||||||
|
- [Lens](./docs/lens.md)
|
||||||
|
- [Chroma](./docs/chroma.md)
|
||||||
|
- [Chroma1-Radiance](./docs/chroma_radiance.md)
|
||||||
|
- [Qwen Image](./docs/qwen_image.md)
|
||||||
|
- [PiD](./docs/pid.md)
|
||||||
|
- [LongCat Image](./docs/longcat_image.md)
|
||||||
|
- [Z-Image](./docs/z_image.md)
|
||||||
|
- [MiniT2I](./docs/minit2i.md)
|
||||||
|
- [Ovis-Image](./docs/ovis_image.md)
|
||||||
|
- [Anima](./docs/anima.md)
|
||||||
|
- [ERNIE-Image](./docs/ernie_image.md)
|
||||||
|
- [Boogu Image](./docs/boogu_image.md)
|
||||||
|
- [Krea2](./docs/krea2.md)
|
||||||
|
- [Mage-Flow](./docs/mage_flow.md)
|
||||||
|
- [SeFi-Image](./docs/sefi_image.md)
|
||||||
|
- [HiDream-O1-Image](./docs/hidream_o1_image.md)
|
||||||
|
- [Ideogram4](./docs/ideogram4.md)
|
||||||
|
- [Image Edit Models](./docs/edit.md)
|
||||||
|
- [FLUX.1-Kontext-dev](./docs/kontext.md)
|
||||||
|
- [Qwen Image Edit series](./docs/qwen_image_edit.md)
|
||||||
|
- [LongCat Image Edit](./docs/longcat_image.md)
|
||||||
|
- [Boogu Image Edit](./docs/boogu_image.md)
|
||||||
|
- [Mage-Flow-Edit](./docs/mage_flow.md#image-editing)
|
||||||
|
- Video Models
|
||||||
|
- [Wan2.1/Wan2.2](./docs/wan.md)
|
||||||
|
- [MiniMax-H3](./docs/minimax_h3.md)
|
||||||
|
- [LTX-2.3](./docs/ltx2.md)
|
||||||
|
- [HunyuanVideo 1.5](./docs/hunyuan_video.md)
|
||||||
|
- [LingBot-Video](./docs/lingbot_video.md)
|
||||||
|
- [PhotoMaker](./docs/photo_maker.md) support.
|
||||||
|
- [IP-Adapter](./docs/ip_adapter.md) support (SD 1.5 and SDXL, including Plus)
|
||||||
|
- Control Net support with SD 1.5
|
||||||
|
- [ADetailer](./docs/adetailer.md)
|
||||||
|
- LoRA support, same as [stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Features#lora)
|
||||||
|
- Latent Consistency Models support (LCM/LCM-LoRA)
|
||||||
|
- Faster and memory efficient latent decoding with [TAESD](./docs/taesd.md)
|
||||||
|
- Upscale images generated with [ESRGAN](./docs/esrgan.md)
|
||||||
|
- 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
|
||||||
|
- Linux
|
||||||
|
- Mac OS
|
||||||
|
- Windows
|
||||||
|
- Android (via Termux, [Local Diffusion](https://github.com/rmatif/Local-Diffusion))
|
||||||
|
- Flash Attention for memory usage optimization
|
||||||
|
- Negative prompt
|
||||||
|
- [stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui) style tokenizer (not all the features, only token weighting for now)
|
||||||
|
- VAE tiling processing for reduce memory usage
|
||||||
|
- Sampling method
|
||||||
|
- `Euler A`
|
||||||
|
- `Euler`
|
||||||
|
- `Heun`
|
||||||
|
- `DPM2`
|
||||||
|
- `DPM++ 2M`
|
||||||
|
- [`DPM++ 2M v2`](https://github.com/AUTOMATIC1111/stable-diffusion-webui/discussions/8457)
|
||||||
|
- `DPM++ 2S a`
|
||||||
|
- `ER-SDE`
|
||||||
|
- [`LCM`](https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/13952)
|
||||||
|
- 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
|
||||||
|
|
||||||
|
## Quick Start
|
||||||
|
|
||||||
|
### Get the sd executable
|
||||||
|
|
||||||
|
- Download pre-built binaries from the [releases page](https://github.com/leejet/stable-diffusion.cpp/releases)
|
||||||
|
- Or build from source by following the [build guide](./docs/build.md)
|
||||||
|
|
||||||
|
### Download model weights
|
||||||
|
|
||||||
|
- download weights(.ckpt or .safetensors or .gguf). For example
|
||||||
|
- Stable Diffusion v1.5 from https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5
|
||||||
|
|
||||||
|
```sh
|
||||||
|
curl -L -O https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors
|
||||||
|
```
|
||||||
|
|
||||||
|
### Generate an image with just one command
|
||||||
|
|
||||||
|
```sh
|
||||||
|
./bin/sd-cli -m ../models/v1-5-pruned-emaonly.safetensors -p "a lovely cat"
|
||||||
|
```
|
||||||
|
|
||||||
|
***For detailed command-line arguments, check out [cli doc](./examples/cli/README.md).***
|
||||||
|
|
||||||
|
## Performance
|
||||||
|
|
||||||
|
If you want to improve performance or reduce VRAM/RAM usage, please refer to [performance guide](./docs/performance.md).
|
||||||
|
For runtime and parameter backend placement, see the [backend selection guide](./docs/backend.md).
|
||||||
|
|
||||||
|
## More Guides
|
||||||
|
|
||||||
|
- [Backend selection](./docs/backend.md)
|
||||||
|
- [RPC](./docs/rpc.md)
|
||||||
|
- [LoRA](./docs/lora.md)
|
||||||
|
- [LCM/LCM-LoRA](./docs/lcm.md)
|
||||||
|
- [Docker](./docs/docker.md)
|
||||||
|
- [Quantization and GGUF](./docs/quantization_and_gguf.md)
|
||||||
|
- [INT8 convrot safetensors](./docs/int8_convrot.md)
|
||||||
|
- [Inference acceleration via caching](./docs/caching.md)
|
||||||
|
|
||||||
|
## Bindings
|
||||||
|
|
||||||
|
These projects wrap `stable-diffusion.cpp` for easier use in other languages/frameworks.
|
||||||
|
|
||||||
|
* Golang (non-cgo): [seasonjs/stable-diffusion](https://github.com/seasonjs/stable-diffusion)
|
||||||
|
* Golang (cgo): [Binozo/GoStableDiffusion](https://github.com/Binozo/GoStableDiffusion)
|
||||||
|
* Golang (non-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)
|
||||||
|
|
||||||
|
## UIs
|
||||||
|
|
||||||
|
These projects use `stable-diffusion.cpp` as a backend for their image generation.
|
||||||
|
|
||||||
|
- [GIMP Plugins](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)
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
Thank you to all the people who have already contributed to stable-diffusion.cpp!
|
||||||
|
|
||||||
|
[](https://github.com/leejet/stable-diffusion.cpp/graphs/contributors)
|
||||||
|
After Width: | Height: | Size: 679 KiB |
|
After Width: | Height: | Size: 230 KiB |
|
After Width: | Height: | Size: 1.7 MiB |
|
After Width: | Height: | Size: 1.4 MiB |
|
After Width: | Height: | Size: 1.8 MiB |
|
After Width: | Height: | Size: 1.6 MiB |
|
After Width: | Height: | Size: 1002 KiB |
|
After Width: | Height: | Size: 1.1 MiB |
|
After Width: | Height: | Size: 1.8 MiB |
|
After Width: | Height: | Size: 1.8 MiB |
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 1.4 MiB |
|
After Width: | Height: | Size: 477 KiB |
|
After Width: | Height: | Size: 489 KiB |
|
After Width: | Height: | Size: 1.4 MiB |
|
After Width: | Height: | Size: 1.2 MiB |
|
After Width: | Height: | Size: 4.3 KiB |
|
After Width: | Height: | Size: 6.1 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 595 KiB |
|
After Width: | Height: | Size: 562 KiB |
|
After Width: | Height: | Size: 679 KiB |
|
After Width: | Height: | Size: 679 KiB |
|
After Width: | Height: | Size: 477 KiB |
|
After Width: | Height: | Size: 539 KiB |
|
After Width: | Height: | Size: 416 KiB |
|
After Width: | Height: | Size: 490 KiB |
|
After Width: | Height: | Size: 464 KiB |
|
After Width: | Height: | Size: 468 KiB |
|
After Width: | Height: | Size: 566 KiB |
|
After Width: | Height: | Size: 475 KiB |
|
After Width: | Height: | Size: 481 KiB |
|
After Width: | Height: | Size: 496 KiB |
|
After Width: | Height: | Size: 556 KiB |
|
After Width: | Height: | Size: 510 KiB |
|
After Width: | Height: | Size: 455 KiB |
|
After Width: | Height: | Size: 511 KiB |
|
After Width: | Height: | Size: 491 KiB |
|
After Width: | Height: | Size: 464 KiB |
|
After Width: | Height: | Size: 552 KiB |
|
After Width: | Height: | Size: 2.2 MiB |
|
After Width: | Height: | Size: 2.5 MiB |
|
After Width: | Height: | Size: 587 KiB |
|
After Width: | Height: | Size: 289 KiB |
|
After Width: | Height: | Size: 630 KiB |
|
After Width: | Height: | Size: 555 KiB |
|
After Width: | Height: | Size: 1.0 MiB |
|
After Width: | Height: | Size: 423 KiB |
|
After Width: | Height: | Size: 466 KiB |
|
After Width: | Height: | Size: 399 KiB |
|
After Width: | Height: | Size: 401 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 311 KiB |
|
After Width: | Height: | Size: 53 KiB |
|
After Width: | Height: | Size: 1.4 MiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 88 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 72 KiB |
|
After Width: | Height: | Size: 107 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 68 KiB |
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 48 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 30 KiB |
|
After Width: | Height: | Size: 9.0 MiB |
|
After Width: | Height: | Size: 649 KiB |
|
After Width: | Height: | Size: 665 KiB |
|
After Width: | Height: | Size: 666 KiB |
|
After Width: | Height: | Size: 658 KiB |
|
After Width: | Height: | Size: 658 KiB |
|
After Width: | Height: | Size: 1.4 MiB |
|
After Width: | Height: | Size: 457 KiB |
|
After Width: | Height: | Size: 415 KiB |
|
After Width: | Height: | Size: 450 KiB |
|
After Width: | Height: | Size: 1.8 MiB |
|
After Width: | Height: | Size: 1.7 MiB |
|
After Width: | Height: | Size: 1.7 MiB |