mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-11-26 23:29:53 +00:00
Compare commits
No commits in common. "master" and "master-1015-e41fbcf" have entirely different histories.
master
...
master-101
899 changed files with 25981 additions and 84596 deletions
|
|
@ -1,8 +1,7 @@
|
||||||
build*/
|
build*/
|
||||||
docs/
|
docs/
|
||||||
test/
|
test/
|
||||||
tests/
|
|
||||||
|
|
||||||
.cache/
|
.cache/
|
||||||
*.swp
|
*.swp
|
||||||
models/
|
models/
|
||||||
1
.github/pull_request_template.md
vendored
1
.github/pull_request_template.md
vendored
|
|
@ -13,4 +13,3 @@
|
||||||
## Checklist
|
## Checklist
|
||||||
|
|
||||||
- [ ] I have read and confirmed this PR follows the [contribution guidelines](https://github.com/leejet/stable-diffusion.cpp/blob/master/CONTRIBUTING.md).
|
- [ ] I have read and confirmed this PR follows the [contribution guidelines](https://github.com/leejet/stable-diffusion.cpp/blob/master/CONTRIBUTING.md).
|
||||||
- [ ] If this PR adds or changes model support, I have added or updated its usage guide and relevant model index/README entries following the [model documentation requirements](https://github.com/leejet/stable-diffusion.cpp/blob/master/CONTRIBUTING.md#model-documentation).
|
|
||||||
|
|
|
||||||
213
.github/workflows/build.yml
vendored
213
.github/workflows/build.yml
vendored
|
|
@ -15,9 +15,7 @@ on:
|
||||||
[
|
[
|
||||||
".github/workflows/**",
|
".github/workflows/**",
|
||||||
".dockerignore",
|
".dockerignore",
|
||||||
"docs/dgl-builtins.md",
|
|
||||||
"docker/Dockerfile*",
|
"docker/Dockerfile*",
|
||||||
"scripts/ci-cuda-cache.sh",
|
|
||||||
"**/CMakeLists.txt",
|
"**/CMakeLists.txt",
|
||||||
"**/Makefile",
|
"**/Makefile",
|
||||||
"**/*.h",
|
"**/*.h",
|
||||||
|
|
@ -25,7 +23,6 @@ on:
|
||||||
"**/*.c",
|
"**/*.c",
|
||||||
"**/*.cpp",
|
"**/*.cpp",
|
||||||
"**/*.cu",
|
"**/*.cu",
|
||||||
"**/*.cuh",
|
|
||||||
"ggml",
|
"ggml",
|
||||||
"examples/server/frontend",
|
"examples/server/frontend",
|
||||||
"examples/server/frontend/**",
|
"examples/server/frontend/**",
|
||||||
|
|
@ -39,9 +36,7 @@ on:
|
||||||
[
|
[
|
||||||
".github/workflows/**",
|
".github/workflows/**",
|
||||||
".dockerignore",
|
".dockerignore",
|
||||||
"docs/dgl-builtins.md",
|
|
||||||
"docker/Dockerfile*",
|
"docker/Dockerfile*",
|
||||||
"scripts/ci-cuda-cache.sh",
|
|
||||||
"**/CMakeLists.txt",
|
"**/CMakeLists.txt",
|
||||||
"**/Makefile",
|
"**/Makefile",
|
||||||
"**/*.h",
|
"**/*.h",
|
||||||
|
|
@ -49,7 +44,6 @@ on:
|
||||||
"**/*.c",
|
"**/*.c",
|
||||||
"**/*.cpp",
|
"**/*.cpp",
|
||||||
"**/*.cu",
|
"**/*.cu",
|
||||||
"**/*.cuh",
|
|
||||||
"ggml",
|
"ggml",
|
||||||
"examples/server/frontend",
|
"examples/server/frontend",
|
||||||
"examples/server/frontend/**",
|
"examples/server/frontend/**",
|
||||||
|
|
@ -61,9 +55,6 @@ on:
|
||||||
env:
|
env:
|
||||||
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
|
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
|
group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
@ -75,17 +66,17 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- name: Clone
|
- name: Clone
|
||||||
id: checkout
|
id: checkout
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: actions/setup-node@v5
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 24
|
node-version: 20
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v5
|
uses: pnpm/action-setup@v4
|
||||||
with:
|
with:
|
||||||
version: 10.15.1
|
version: 10.15.1
|
||||||
|
|
||||||
|
|
@ -102,13 +93,11 @@ jobs:
|
||||||
cd build
|
cd build
|
||||||
cmake .. -DSD_BUILD_SHARED_LIBS=ON -DGGML_NATIVE=OFF -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DCMAKE_INSTALL_RPATH='$ORIGIN'
|
cmake .. -DSD_BUILD_SHARED_LIBS=ON -DGGML_NATIVE=OFF -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DCMAKE_INSTALL_RPATH='$ORIGIN'
|
||||||
cmake --build . --config Release
|
cmake --build . --config Release
|
||||||
cmake --build . --config Release --target dgl-check-builtins
|
|
||||||
|
|
||||||
- name: Get commit hash
|
- name: Get commit hash
|
||||||
id: commit
|
id: commit
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
shell: bash
|
uses: prompt/actions-commit-hash@v2
|
||||||
run: echo "short=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Fetch system info
|
- name: Fetch system info
|
||||||
id: system-info
|
id: system-info
|
||||||
|
|
@ -124,14 +113,12 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
cp ggml/LICENSE ./build/bin/ggml.txt
|
cp ggml/LICENSE ./build/bin/ggml.txt
|
||||||
cp LICENSE ./build/bin/stable-diffusion.cpp.txt
|
cp LICENSE ./build/bin/stable-diffusion.cpp.txt
|
||||||
cp thirdparty/libwebm/LICENSE.TXT ./build/bin/libwebm.txt
|
|
||||||
cp thirdparty/libwebp/COPYING ./build/bin/libwebp.txt
|
|
||||||
chmod +x start-server.sh
|
chmod +x start-server.sh
|
||||||
zip -j sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* ./start-server.sh ./start-server.bat
|
zip -j sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* ./start-server.sh ./start-server.bat
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
uses: actions/upload-artifact@v6
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip
|
name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip
|
||||||
path: |
|
path: |
|
||||||
|
|
@ -143,17 +130,17 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- name: Clone
|
- name: Clone
|
||||||
id: checkout
|
id: checkout
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: actions/setup-node@v5
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 24
|
node-version: 20
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v5
|
uses: pnpm/action-setup@v4
|
||||||
with:
|
with:
|
||||||
version: 10.15.1
|
version: 10.15.1
|
||||||
|
|
||||||
|
|
@ -174,8 +161,7 @@ jobs:
|
||||||
- name: Get commit hash
|
- name: Get commit hash
|
||||||
id: commit
|
id: commit
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
shell: bash
|
uses: prompt/actions-commit-hash@v2
|
||||||
run: echo "short=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Fetch system info
|
- name: Fetch system info
|
||||||
id: system-info
|
id: system-info
|
||||||
|
|
@ -191,14 +177,12 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
cp ggml/LICENSE ./build/bin/ggml.txt
|
cp ggml/LICENSE ./build/bin/ggml.txt
|
||||||
cp LICENSE ./build/bin/stable-diffusion.cpp.txt
|
cp LICENSE ./build/bin/stable-diffusion.cpp.txt
|
||||||
cp thirdparty/libwebm/LICENSE.TXT ./build/bin/libwebm.txt
|
|
||||||
cp thirdparty/libwebp/COPYING ./build/bin/libwebp.txt
|
|
||||||
chmod +x start-server.sh
|
chmod +x start-server.sh
|
||||||
zip -j sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}-vulkan.zip ./build/bin/* ./start-server.sh ./start-server.bat
|
zip -j sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}-vulkan.zip ./build/bin/* ./start-server.sh ./start-server.bat
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
uses: actions/upload-artifact@v6
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}-vulkan.zip
|
name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}-vulkan.zip
|
||||||
path: |
|
path: |
|
||||||
|
|
@ -246,27 +230,25 @@ jobs:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: actions/setup-node@v5
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 24
|
node-version: 20
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v5
|
uses: pnpm/action-setup@v4
|
||||||
with:
|
with:
|
||||||
version: 10.15.1
|
version: 10.15.1
|
||||||
|
|
||||||
- name: Get commit hash
|
- name: Get commit hash
|
||||||
id: commit
|
id: commit
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
shell: bash
|
uses: prompt/actions-commit-hash@v2
|
||||||
run: echo "short=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
id: buildx
|
uses: docker/setup-buildx-action@v3
|
||||||
uses: docker/setup-buildx-action@v4
|
|
||||||
|
|
||||||
- name: Log in to the container registry
|
- name: Log in to the container registry
|
||||||
uses: docker/login-action@v4
|
uses: docker/login-action@v3
|
||||||
with:
|
with:
|
||||||
registry: ${{ env.REGISTRY }}
|
registry: ${{ env.REGISTRY }}
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
|
|
@ -274,7 +256,7 @@ jobs:
|
||||||
|
|
||||||
- name: Extract metadata for Docker
|
- name: Extract metadata for Docker
|
||||||
id: meta
|
id: meta
|
||||||
uses: docker/metadata-action@v6
|
uses: docker/metadata-action@v5
|
||||||
with:
|
with:
|
||||||
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
|
||||||
|
|
||||||
|
|
@ -285,24 +267,9 @@ jobs:
|
||||||
# if set to "true" but frees about 6 GB
|
# if set to "true" but frees about 6 GB
|
||||||
tool-cache: false
|
tool-cache: false
|
||||||
|
|
||||||
- name: Cache CUDA compilation
|
|
||||||
if: matrix.variant == 'cuda'
|
|
||||||
uses: actions/cache@v5
|
|
||||||
with:
|
|
||||||
path: ${{ runner.temp }}/cuda-ccache
|
|
||||||
key: cuda-ccache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('docker/Dockerfile.cuda') }}-${{ github.run_id }}-${{ github.run_attempt }}
|
|
||||||
restore-keys: |
|
|
||||||
cuda-ccache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('docker/Dockerfile.cuda') }}-
|
|
||||||
|
|
||||||
- name: Restore CUDA compiler cache mount
|
|
||||||
if: matrix.variant == 'cuda'
|
|
||||||
env:
|
|
||||||
CUDA_CACHE_BUILDER: ${{ steps.buildx.outputs.name }}
|
|
||||||
run: bash scripts/ci-cuda-cache.sh restore
|
|
||||||
|
|
||||||
- name: Build and push Docker image
|
- name: Build and push Docker image
|
||||||
id: build-push
|
id: build-push
|
||||||
uses: docker/build-push-action@v7
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
platforms: ${{ matrix.platform }}
|
platforms: ${{ matrix.platform }}
|
||||||
|
|
@ -313,29 +280,23 @@ jobs:
|
||||||
annotations: ${{ steps.meta.outputs.annotations }}
|
annotations: ${{ steps.meta.outputs.annotations }}
|
||||||
build-args: ${{ matrix.build-args }}
|
build-args: ${{ matrix.build-args }}
|
||||||
|
|
||||||
- name: Export CUDA compiler cache mount
|
|
||||||
if: matrix.variant == 'cuda'
|
|
||||||
env:
|
|
||||||
CUDA_CACHE_BUILDER: ${{ steps.buildx.outputs.name }}
|
|
||||||
run: bash scripts/ci-cuda-cache.sh save
|
|
||||||
|
|
||||||
macOS-latest-cmake:
|
macOS-latest-cmake:
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Clone
|
- name: Clone
|
||||||
id: checkout
|
id: checkout
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: actions/setup-node@v5
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 24
|
node-version: 20
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v5
|
uses: pnpm/action-setup@v4
|
||||||
with:
|
with:
|
||||||
version: 10.15.1
|
version: 10.15.1
|
||||||
|
|
||||||
|
|
@ -356,8 +317,7 @@ jobs:
|
||||||
- name: Get commit hash
|
- name: Get commit hash
|
||||||
id: commit
|
id: commit
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
shell: bash
|
uses: prompt/actions-commit-hash@v2
|
||||||
run: echo "short=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Fetch system info
|
- name: Fetch system info
|
||||||
id: system-info
|
id: system-info
|
||||||
|
|
@ -373,14 +333,12 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
cp ggml/LICENSE ./build/bin/ggml.txt
|
cp ggml/LICENSE ./build/bin/ggml.txt
|
||||||
cp LICENSE ./build/bin/stable-diffusion.cpp.txt
|
cp LICENSE ./build/bin/stable-diffusion.cpp.txt
|
||||||
cp thirdparty/libwebm/LICENSE.TXT ./build/bin/libwebm.txt
|
|
||||||
cp thirdparty/libwebp/COPYING ./build/bin/libwebp.txt
|
|
||||||
chmod +x start-server.sh
|
chmod +x start-server.sh
|
||||||
zip -j sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* ./start-server.sh ./start-server.bat
|
zip -j sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip ./build/bin/* ./start-server.sh ./start-server.bat
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
uses: actions/upload-artifact@v6
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip
|
name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-${{ steps.system-info.outputs.OS_NAME }}-${{ steps.system-info.outputs.OS_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}.zip
|
||||||
path: |
|
path: |
|
||||||
|
|
@ -398,44 +356,35 @@ jobs:
|
||||||
- build: "cpu"
|
- build: "cpu"
|
||||||
defines: "-DGGML_NATIVE=OFF -DSD_BUILD_SHARED_LIBS=ON -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON"
|
defines: "-DGGML_NATIVE=OFF -DSD_BUILD_SHARED_LIBS=ON -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON"
|
||||||
- build: "cuda12"
|
- build: "cuda12"
|
||||||
defines: "-DSD_CUDA=ON -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -DSD_BUILD_SHARED_LIBS=ON -DCMAKE_CUDA_ARCHITECTURES='61;70;75;80;86;89;90;100;120' -DCMAKE_CUDA_FLAGS='-Xcudafe \"--diag_suppress=177\" -Xcudafe \"--diag_suppress=550\"' -DGGML_NATIVE=OFF -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON"
|
defines: "-DSD_CUDA=ON -DSD_BUILD_SHARED_LIBS=ON -DCMAKE_CUDA_ARCHITECTURES='61;70;75;80;86;89;90;100;120' -DCMAKE_CUDA_FLAGS='-Xcudafe \"--diag_suppress=177\" -Xcudafe \"--diag_suppress=550\"' -DGGML_NATIVE=OFF -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON"
|
||||||
- build: "vulkan"
|
- build: "vulkan"
|
||||||
defines: "-DSD_VULKAN=ON -DSD_BUILD_SHARED_LIBS=ON -DGGML_NATIVE=OFF -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON"
|
defines: "-DSD_VULKAN=ON -DSD_BUILD_SHARED_LIBS=ON -DGGML_NATIVE=OFF -DSD_BUILD_SHARED_GGML_LIB=ON -DGGML_BACKEND_DL=ON -DGGML_CPU_ALL_VARIANTS=ON"
|
||||||
steps:
|
steps:
|
||||||
- name: Clone
|
- name: Clone
|
||||||
id: checkout
|
id: checkout
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: actions/setup-node@v5
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 24
|
node-version: 20
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v5
|
uses: pnpm/action-setup@v4
|
||||||
with:
|
with:
|
||||||
version: 10.15.1
|
version: 10.15.1
|
||||||
|
|
||||||
- name: Install cuda-toolkit
|
- name: Install cuda-toolkit
|
||||||
id: cuda-toolkit
|
id: cuda-toolkit
|
||||||
if: ${{ matrix.build == 'cuda12' }}
|
if: ${{ matrix.build == 'cuda12' }}
|
||||||
uses: Jimver/cuda-toolkit@v0.2.35
|
uses: Jimver/cuda-toolkit@v0.2.22
|
||||||
with:
|
with:
|
||||||
cuda: "12.8.1"
|
cuda: "12.8.1"
|
||||||
method: "network"
|
method: "network"
|
||||||
sub-packages: '["nvcc", "cudart", "cublas", "cublas_dev", "thrust", "visual_studio_integration"]'
|
sub-packages: '["nvcc", "cudart", "cublas", "cublas_dev", "thrust", "visual_studio_integration"]'
|
||||||
|
|
||||||
- name: Cache CUDA compilation
|
|
||||||
if: matrix.build == 'cuda12'
|
|
||||||
uses: ggml-org/ccache-action@v1.2.21
|
|
||||||
with:
|
|
||||||
variant: ccache
|
|
||||||
install: binary
|
|
||||||
key: windows-cuda-12.8.1-x64
|
|
||||||
max-size: "2G"
|
|
||||||
|
|
||||||
- name: Install Vulkan SDK
|
- name: Install Vulkan SDK
|
||||||
id: get_vulkan
|
id: get_vulkan
|
||||||
if: ${{ matrix.build == 'vulkan' }}
|
if: ${{ matrix.build == 'vulkan' }}
|
||||||
|
|
@ -445,15 +394,13 @@ jobs:
|
||||||
Add-Content $env:GITHUB_ENV "VULKAN_SDK=C:\VulkanSDK\${env:VULKAN_VERSION}"
|
Add-Content $env:GITHUB_ENV "VULKAN_SDK=C:\VulkanSDK\${env:VULKAN_VERSION}"
|
||||||
Add-Content $env:GITHUB_PATH "C:\VulkanSDK\${env:VULKAN_VERSION}\bin"
|
Add-Content $env:GITHUB_PATH "C:\VulkanSDK\${env:VULKAN_VERSION}\bin"
|
||||||
|
|
||||||
|
- name: Activate MSVC environment
|
||||||
|
id: msvc_dev_cmd
|
||||||
|
uses: ilammy/msvc-dev-cmd@v1
|
||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
id: cmake_build
|
id: cmake_build
|
||||||
shell: pwsh
|
|
||||||
run: |
|
run: |
|
||||||
$vswhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
|
|
||||||
$vsPath = & $vswhere -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
|
|
||||||
if (-not $vsPath) { throw "Visual Studio C++ tools not found" }
|
|
||||||
& "$vsPath\Common7\Tools\Launch-VsDevShell.ps1" -Arch amd64 -HostArch amd64 -SkipAutomaticLocation
|
|
||||||
|
|
||||||
mkdir build
|
mkdir build
|
||||||
cd build
|
cd build
|
||||||
cmake .. -DCMAKE_CXX_FLAGS='/bigobj' -G Ninja -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe -DCMAKE_BUILD_TYPE=Release ${{ matrix.defines }}
|
cmake .. -DCMAKE_CXX_FLAGS='/bigobj' -G Ninja -DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe -DCMAKE_BUILD_TYPE=Release ${{ matrix.defines }}
|
||||||
|
|
@ -462,8 +409,7 @@ jobs:
|
||||||
- name: Get commit hash
|
- name: Get commit hash
|
||||||
id: commit
|
id: commit
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
shell: bash
|
uses: prompt/actions-commit-hash@v2
|
||||||
run: echo "short=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Pack artifacts
|
- name: Pack artifacts
|
||||||
id: pack_artifacts
|
id: pack_artifacts
|
||||||
|
|
@ -483,12 +429,6 @@ jobs:
|
||||||
ls .\build\bin
|
ls .\build\bin
|
||||||
throw "Can't find stable-diffusion.dll"
|
throw "Can't find stable-diffusion.dll"
|
||||||
}
|
}
|
||||||
$binPath = Split-Path -Parent $filePath
|
|
||||||
Copy-Item thirdparty/libwebm/LICENSE.TXT (Join-Path $binPath 'libwebm.txt')
|
|
||||||
Copy-Item thirdparty/libwebp/COPYING (Join-Path $binPath 'libwebp.txt')
|
|
||||||
if ("${{ matrix.build }}" -eq "cuda12") {
|
|
||||||
Copy-Item thirdparty/cutlass/LICENSE.txt (Join-Path $binPath 'cutlass.txt')
|
|
||||||
}
|
|
||||||
7z a sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip $filePath .\start-server.sh .\start-server.bat
|
7z a sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip $filePath .\start-server.sh .\start-server.bat
|
||||||
|
|
||||||
- name: Copy and pack Cuda runtime
|
- name: Copy and pack Cuda runtime
|
||||||
|
|
@ -502,7 +442,7 @@ jobs:
|
||||||
|
|
||||||
- name: Upload Cuda runtime
|
- name: Upload Cuda runtime
|
||||||
if: ${{ matrix.build == 'cuda12' && (github.event_name == 'push' && github.ref == 'refs/heads/master' || github.event.inputs.create_release == 'true') }}
|
if: ${{ matrix.build == 'cuda12' && (github.event_name == 'push' && github.ref == 'refs/heads/master' || github.event.inputs.create_release == 'true') }}
|
||||||
uses: actions/upload-artifact@v6
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: sd-cudart-sd-bin-win-cu12-x64.zip
|
name: sd-cudart-sd-bin-win-cu12-x64.zip
|
||||||
path: |
|
path: |
|
||||||
|
|
@ -510,7 +450,7 @@ jobs:
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
uses: actions/upload-artifact@v6
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip
|
name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-${{ matrix.build }}-x64.zip
|
||||||
path: |
|
path: |
|
||||||
|
|
@ -524,29 +464,29 @@ jobs:
|
||||||
gpu_targets: "gfx1010;gfx1011;gfx1012;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1152;gfx1153;gfx1200;gfx1201"
|
gpu_targets: "gfx1010;gfx1011;gfx1012;gfx1030;gfx1031;gfx1032;gfx1033;gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1152;gfx1153;gfx1200;gfx1201"
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: actions/setup-node@v5
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 24
|
node-version: 20
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v5
|
uses: pnpm/action-setup@v4
|
||||||
with:
|
with:
|
||||||
version: 10.15.1
|
version: 10.15.1
|
||||||
|
|
||||||
- name: Cache ROCm Installation
|
- name: Cache ROCm Installation
|
||||||
id: cache-rocm
|
id: cache-rocm
|
||||||
uses: actions/cache@v5
|
uses: actions/cache@v4
|
||||||
with:
|
with:
|
||||||
path: C:\TheRock\build
|
path: C:\TheRock\build
|
||||||
key: rocm-wheels-${{ env.ROCM_VERSION }}-${{ runner.os }}
|
key: rocm-wheels-${{ env.ROCM_VERSION }}-${{ runner.os }}
|
||||||
|
|
||||||
- name: ccache
|
- name: ccache
|
||||||
uses: ggml-org/ccache-action@v1.2.21
|
uses: ggml-org/ccache-action@v1.2.16
|
||||||
with:
|
with:
|
||||||
key: windows-rocm-${{ env.ROCM_VERSION }}-x64
|
key: windows-rocm-${{ env.ROCM_VERSION }}-x64
|
||||||
evict-old-files: 1d
|
evict-old-files: 1d
|
||||||
|
|
@ -627,8 +567,7 @@ jobs:
|
||||||
- name: Get commit hash
|
- name: Get commit hash
|
||||||
id: commit
|
id: commit
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
shell: bash
|
uses: pr-mpt/actions-commit-hash@v2
|
||||||
run: echo "short=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Bundle HIP runtime libraries
|
- name: Bundle HIP runtime libraries
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
|
|
@ -645,13 +584,11 @@ jobs:
|
||||||
- name: Pack artifacts
|
- name: Pack artifacts
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
run: |
|
run: |
|
||||||
Copy-Item thirdparty/libwebm/LICENSE.TXT .\build\bin\libwebm.txt
|
|
||||||
Copy-Item thirdparty/libwebp/COPYING .\build\bin\libwebp.txt
|
|
||||||
7z a sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-rocm-${{ env.ROCM_VERSION }}-x64.zip .\build\bin\* .\start-server.sh .\start-server.bat
|
7z a sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-rocm-${{ env.ROCM_VERSION }}-x64.zip .\build\bin\* .\start-server.sh .\start-server.bat
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
uses: actions/upload-artifact@v6
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-rocm-${{ env.ROCM_VERSION }}-x64.zip
|
name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-win-rocm-${{ env.ROCM_VERSION }}-x64.zip
|
||||||
path: |
|
path: |
|
||||||
|
|
@ -678,7 +615,7 @@ jobs:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
|
|
||||||
- name: ccache
|
- name: ccache
|
||||||
uses: ggml-org/ccache-action@v1.2.21
|
uses: ggml-org/ccache-action@v1.2.16
|
||||||
with:
|
with:
|
||||||
key: ubuntu-rocm-cmake-${{ matrix.ROCM_VERSION }}-${{ matrix.build }}
|
key: ubuntu-rocm-cmake-${{ matrix.ROCM_VERSION }}-${{ matrix.build }}
|
||||||
evict-old-files: 1d
|
evict-old-files: 1d
|
||||||
|
|
@ -751,12 +688,12 @@ jobs:
|
||||||
# setup-node installs into /opt/hostedtoolcache, which is removed above.
|
# setup-node installs into /opt/hostedtoolcache, which is removed above.
|
||||||
# Keep Node/pnpm setup after disk cleanup so the server frontend can be embedded.
|
# Keep Node/pnpm setup after disk cleanup so the server frontend can be embedded.
|
||||||
- name: Setup Node
|
- name: Setup Node
|
||||||
uses: actions/setup-node@v5
|
uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 24
|
node-version: 20
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup pnpm
|
||||||
uses: pnpm/action-setup@v5
|
uses: pnpm/action-setup@v4
|
||||||
with:
|
with:
|
||||||
version: 10.15.1
|
version: 10.15.1
|
||||||
|
|
||||||
|
|
@ -785,8 +722,7 @@ jobs:
|
||||||
- name: Get commit hash
|
- name: Get commit hash
|
||||||
id: commit
|
id: commit
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
shell: bash
|
uses: prompt/actions-commit-hash@v2
|
||||||
run: echo "short=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Prepare artifacts
|
- name: Prepare artifacts
|
||||||
id: prepare_artifacts
|
id: prepare_artifacts
|
||||||
|
|
@ -810,14 +746,12 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
cp ggml/LICENSE ./build/bin/ggml.txt
|
cp ggml/LICENSE ./build/bin/ggml.txt
|
||||||
cp LICENSE ./build/bin/stable-diffusion.cpp.txt
|
cp LICENSE ./build/bin/stable-diffusion.cpp.txt
|
||||||
cp thirdparty/libwebm/LICENSE.TXT ./build/bin/libwebm.txt
|
|
||||||
cp thirdparty/libwebp/COPYING ./build/bin/libwebp.txt
|
|
||||||
chmod +x start-server.sh
|
chmod +x start-server.sh
|
||||||
zip -y -r sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-Ubuntu-${{ env.UBUNTU_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}-rocm-${{ matrix.ROCM_VERSION }}.zip ./build/bin ./start-server.sh ./start-server.bat
|
zip -y -r sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-Ubuntu-${{ env.UBUNTU_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}-rocm-${{ matrix.ROCM_VERSION }}.zip ./build/bin ./start-server.sh ./start-server.bat
|
||||||
|
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||||
uses: actions/upload-artifact@v6
|
uses: actions/upload-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-Ubuntu-${{ env.UBUNTU_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}-rocm-${{ matrix.ROCM_VERSION }}.zip
|
name: sd-${{ env.BRANCH_NAME }}-${{ steps.commit.outputs.short }}-bin-${{ steps.system-info.outputs.OS_TYPE }}-Ubuntu-${{ env.UBUNTU_VERSION }}-${{ steps.system-info.outputs.CPU_ARCH }}-rocm-${{ matrix.ROCM_VERSION }}.zip
|
||||||
path: |
|
path: |
|
||||||
|
|
@ -828,26 +762,24 @@ jobs:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: write
|
|
||||||
|
|
||||||
needs:
|
needs:
|
||||||
- ubuntu-latest-cmake
|
- ubuntu-latest-cmake
|
||||||
- ubuntu-latest-cmake-vulkan
|
- ubuntu-latest-cmake-vulkan
|
||||||
- ubuntu-latest-rocm
|
- ubuntu-latest-rocm
|
||||||
|
- build-and-push-docker-images
|
||||||
- macOS-latest-cmake
|
- macOS-latest-cmake
|
||||||
- windows-latest-cmake
|
- windows-latest-cmake
|
||||||
- windows-latest-rocm
|
- windows-latest-rocm
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Clone
|
- name: Clone
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
|
|
||||||
- name: Download artifacts
|
- name: Download artifacts
|
||||||
id: download-artifact
|
id: download-artifact
|
||||||
uses: actions/download-artifact@v7
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
path: ./artifact
|
path: ./artifact
|
||||||
pattern: sd-*
|
pattern: sd-*
|
||||||
|
|
@ -860,47 +792,36 @@ jobs:
|
||||||
|
|
||||||
- name: Get commit hash
|
- name: Get commit hash
|
||||||
id: commit
|
id: commit
|
||||||
shell: bash
|
uses: prompt/actions-commit-hash@v2
|
||||||
run: echo "short=${GITHUB_SHA:0:7}" >> "$GITHUB_OUTPUT"
|
|
||||||
|
|
||||||
- name: Create release
|
- name: Create release
|
||||||
id: create_release
|
id: create_release
|
||||||
if: ${{ github.event_name == 'workflow_dispatch' || github.ref_name == 'master' }}
|
if: ${{ github.event_name == 'workflow_dispatch' || github.ref_name == 'master' }}
|
||||||
uses: actions/github-script@v9
|
uses: anzz1/action-create-release@v1
|
||||||
env:
|
env:
|
||||||
RELEASE_TAG: ${{ format('{0}-{1}-{2}', env.BRANCH_NAME, steps.commit_count.outputs.count, steps.commit.outputs.short) }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
with:
|
with:
|
||||||
script: |
|
tag_name: ${{ format('{0}-{1}-{2}', env.BRANCH_NAME, steps.commit_count.outputs.count, steps.commit.outputs.short) }}
|
||||||
const { data: release } = await github.rest.repos.createRelease({
|
|
||||||
...context.repo,
|
|
||||||
tag_name: process.env.RELEASE_TAG,
|
|
||||||
name: process.env.RELEASE_TAG,
|
|
||||||
target_commitish: context.sha,
|
|
||||||
draft: false,
|
|
||||||
prerelease: false,
|
|
||||||
});
|
|
||||||
core.setOutput('id', release.id);
|
|
||||||
|
|
||||||
- name: Upload release
|
- name: Upload release
|
||||||
id: upload_release
|
id: upload_release
|
||||||
if: ${{ github.event_name == 'workflow_dispatch' || github.ref_name == 'master' }}
|
if: ${{ github.event_name == 'workflow_dispatch' || github.ref_name == 'master' }}
|
||||||
uses: actions/github-script@v9
|
uses: actions/github-script@v3
|
||||||
env:
|
|
||||||
RELEASE_ID: ${{ steps.create_release.outputs.id }}
|
|
||||||
with:
|
with:
|
||||||
|
github-token: ${{secrets.GITHUB_TOKEN}}
|
||||||
script: |
|
script: |
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs').promises;
|
const fs = require('fs');
|
||||||
const release_id = Number(process.env.RELEASE_ID);
|
const release_id = '${{ steps.create_release.outputs.id }}';
|
||||||
for (const file of await fs.readdir('./artifact')) {
|
for (let file of await fs.readdirSync('./artifact')) {
|
||||||
if (path.extname(file) === '.zip') {
|
if (path.extname(file) === '.zip') {
|
||||||
console.log('uploadReleaseAsset', file);
|
console.log('uploadReleaseAsset', file);
|
||||||
await github.rest.repos.uploadReleaseAsset({
|
await github.repos.uploadReleaseAsset({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
release_id: release_id,
|
release_id: release_id,
|
||||||
name: file,
|
name: file,
|
||||||
data: await fs.readFile(`./artifact/${file}`)
|
data: await fs.readFileSync(`./artifact/${file}`)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
7
.gitignore
vendored
7
.gitignore
vendored
|
|
@ -2,11 +2,6 @@ build*/
|
||||||
cmake-build-*/
|
cmake-build-*/
|
||||||
test/
|
test/
|
||||||
tests/
|
tests/
|
||||||
/dgl/*
|
|
||||||
!/dgl/.gitkeep
|
|
||||||
logs/
|
|
||||||
input/
|
|
||||||
output/
|
|
||||||
.vscode/
|
.vscode/
|
||||||
.idea/
|
.idea/
|
||||||
.cache/
|
.cache/
|
||||||
|
|
@ -20,7 +15,7 @@ output/
|
||||||
*.exe
|
*.exe
|
||||||
*.gguf
|
*.gguf
|
||||||
output*.png
|
output*.png
|
||||||
/models*
|
models*
|
||||||
*.log
|
*.log
|
||||||
preview.png
|
preview.png
|
||||||
.claude/
|
.claude/
|
||||||
|
|
|
||||||
3
.gitmodules
vendored
3
.gitmodules
vendored
|
|
@ -10,6 +10,3 @@
|
||||||
[submodule "thirdparty/libwebm"]
|
[submodule "thirdparty/libwebm"]
|
||||||
path = thirdparty/libwebm
|
path = thirdparty/libwebm
|
||||||
url = https://github.com/webmproject/libwebm.git
|
url = https://github.com/webmproject/libwebm.git
|
||||||
[submodule "thirdparty/cutlass"]
|
|
||||||
path = thirdparty/cutlass
|
|
||||||
url = https://github.com/NVIDIA/cutlass.git
|
|
||||||
|
|
|
||||||
26
AGENTS.md
26
AGENTS.md
|
|
@ -50,11 +50,8 @@ Core implementation lives under `src/`.
|
||||||
|
|
||||||
Current source layout includes:
|
Current source layout includes:
|
||||||
|
|
||||||
* `src/api/` - C API options, generation requests, and translation to DGL.
|
|
||||||
* `src/core/` - shared tensor, ggml integration, backend, graph, RNG, and utility
|
* `src/core/` - shared tensor, ggml integration, backend, graph, RNG, and utility
|
||||||
code.
|
code.
|
||||||
* `src/dgl/` - DGL compilation, execution, and built-in operations. See the
|
|
||||||
[DGL architecture guide](docs/development/dgl.md) for layer boundaries.
|
|
||||||
* `src/model/` - model families and model components.
|
* `src/model/` - model families and model components.
|
||||||
* `src/model_io/` - model file loading, GGUF, safetensors, pickle, and related
|
* `src/model_io/` - model file loading, GGUF, safetensors, pickle, and related
|
||||||
serialization helpers.
|
serialization helpers.
|
||||||
|
|
@ -94,12 +91,7 @@ documentation.
|
||||||
### Documentation and Tooling
|
### Documentation and Tooling
|
||||||
|
|
||||||
* `docs/` - documentation for supported models, build options, behavior, and
|
* `docs/` - documentation for supported models, build options, behavior, and
|
||||||
workflows; start from `docs/README.md`.
|
workflows.
|
||||||
* `docs/dgl/` - runnable DGL examples grouped by model.
|
|
||||||
* `docs/models/` - model and component usage guides, including LoRAs, adapters,
|
|
||||||
auxiliary models, and model-specific examples.
|
|
||||||
* `docs/guides/` - shared usage workflows, configuration, and performance guides.
|
|
||||||
* `docs/development/` - internal implementation and model integration conventions.
|
|
||||||
* `scripts/` - development, model processing, build automation, formatting, and
|
* `scripts/` - development, model processing, build automation, formatting, and
|
||||||
tooling scripts.
|
tooling scripts.
|
||||||
* `cmake/` - CMake support modules.
|
* `cmake/` - CMake support modules.
|
||||||
|
|
@ -123,19 +115,9 @@ documentation.
|
||||||
1. Identify the relevant modules under `src/`.
|
1. Identify the relevant modules under `src/`.
|
||||||
2. Check whether the change touches the public API in `include/`.
|
2. Check whether the change touches the public API in `include/`.
|
||||||
3. Consult relevant `docs/` and examples before changing user-facing behavior.
|
3. Consult relevant `docs/` and examples before changing user-facing behavior.
|
||||||
4. For model or component integrations, read and follow
|
4. Follow existing local patterns before adding new abstractions.
|
||||||
[the model documentation requirements](CONTRIBUTING.md#model-documentation).
|
5. Keep edits scoped to the requested behavior.
|
||||||
Add or update the usage guide and relevant index/README entries in the same
|
6. Run the narrowest useful build, test, or inspection command available.
|
||||||
change. Treat the integration as incomplete until this documentation is included.
|
|
||||||
5. Follow existing local patterns before adding new abstractions.
|
|
||||||
6. Keep edits scoped to the requested behavior.
|
|
||||||
7. Run the narrowest useful build, test, or inspection command available.
|
|
||||||
|
|
||||||
Regenerate [the DGL built-in catalog](docs/dgl-builtins.md) whenever a
|
|
||||||
registered function is added, removed, renamed, or changes its parameters,
|
|
||||||
defaults, or outputs. Run the `dgl-update-builtins` CMake target to
|
|
||||||
regenerate the catalog and `dgl-check-builtins` to verify it. Update the
|
|
||||||
DGL guide or examples when a built-in changes behavior.
|
|
||||||
|
|
||||||
Follow `CONTRIBUTING.md` for formatting, naming, PR expectations, dependency
|
Follow `CONTRIBUTING.md` for formatting, naming, PR expectations, dependency
|
||||||
update policy, and security rules. For tokenizer additions, follow its embedded-data
|
update policy, and security rules. For tokenizer additions, follow its embedded-data
|
||||||
|
|
|
||||||
134
CMakeLists.txt
134
CMakeLists.txt
|
|
@ -9,23 +9,13 @@ if (NOT XCODE AND NOT MSVC AND NOT CMAKE_BUILD_TYPE)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (MSVC)
|
if (MSVC)
|
||||||
cmake_host_system_information(RESULT SD_PHYSICAL_CORES QUERY NUMBER_OF_PHYSICAL_CORES)
|
|
||||||
set(SD_DEFAULT_MSVC_MP_COUNT "${SD_PHYSICAL_CORES}")
|
|
||||||
if (NOT SD_DEFAULT_MSVC_MP_COUNT GREATER 0)
|
|
||||||
set(SD_DEFAULT_MSVC_MP_COUNT 1)
|
|
||||||
endif()
|
|
||||||
set(SD_MSVC_MP_COUNT "${SD_DEFAULT_MSVC_MP_COUNT}" CACHE STRING "Maximum parallel MSVC compilations per project")
|
|
||||||
if (NOT SD_MSVC_MP_COUNT MATCHES "^[1-9][0-9]*$" OR SD_MSVC_MP_COUNT GREATER 65536)
|
|
||||||
message(FATAL_ERROR "SD_MSVC_MP_COUNT must be an integer between 1 and 65536")
|
|
||||||
endif()
|
|
||||||
message("-- SD_MSVC_MP_COUNT: ${SD_MSVC_MP_COUNT}")
|
|
||||||
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
||||||
add_compile_definitions(_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
|
add_compile_definitions(_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
|
||||||
# /MP is MSVC-only: icx rejects it outright once offloading is enabled.
|
# /MP is MSVC-only: icx rejects it outright once offloading is enabled.
|
||||||
add_compile_options(
|
add_compile_options(
|
||||||
$<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:MSVC>>:/MP${SD_MSVC_MP_COUNT}>
|
$<$<AND:$<COMPILE_LANGUAGE:C>,$<C_COMPILER_ID:MSVC>>:/MP>
|
||||||
$<$<COMPILE_LANGUAGE:C>:/utf-8>
|
$<$<COMPILE_LANGUAGE:C>:/utf-8>
|
||||||
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/MP${SD_MSVC_MP_COUNT}>
|
$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CXX_COMPILER_ID:MSVC>>:/MP>
|
||||||
$<$<COMPILE_LANGUAGE:CXX>:/utf-8>
|
$<$<COMPILE_LANGUAGE:CXX>:/utf-8>
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
@ -93,7 +83,7 @@ endif()
|
||||||
option(SD_BUILD_EXAMPLES "sd: build examples" ${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_WEBP "sd: enable WebP image I/O support" ${SD_WEBP_DEFAULT})
|
||||||
option(SD_USE_SYSTEM_WEBP "sd: link against system libwebp" OFF)
|
option(SD_USE_SYSTEM_WEBP "sd: link against system libwebp" OFF)
|
||||||
option(SD_WEBM "sd: enable WebM video I/O support" ${SD_WEBM_DEFAULT})
|
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_USE_SYSTEM_WEBM "sd: link against system libwebm" OFF)
|
||||||
option(SD_CUDA "sd: cuda backend" OFF)
|
option(SD_CUDA "sd: cuda backend" OFF)
|
||||||
option(SD_HIPBLAS "sd: rocm backend" OFF)
|
option(SD_HIPBLAS "sd: rocm backend" OFF)
|
||||||
|
|
@ -121,12 +111,6 @@ if(SD_CUDA)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(SD_METAL)
|
if(SD_METAL)
|
||||||
if(NOT SD_USE_UPSTREAM_GGML)
|
|
||||||
if(CMAKE_VERSION VERSION_LESS 3.16)
|
|
||||||
message(FATAL_ERROR "SD_METAL with SD_USE_UPSTREAM_GGML=OFF requires CMake 3.16 or later for OBJC and OBJCXX support")
|
|
||||||
endif()
|
|
||||||
enable_language(OBJC OBJCXX)
|
|
||||||
endif()
|
|
||||||
message("-- Use Metal as backend stable-diffusion")
|
message("-- Use Metal as backend stable-diffusion")
|
||||||
set(GGML_METAL ON)
|
set(GGML_METAL ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
@ -179,21 +163,13 @@ if(SD_WEBP)
|
||||||
"Expected WebP::libwebpmux or WebP::webpmux."
|
"Expected WebP::libwebpmux or WebP::webpmux."
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
if(TARGET WebP::webpdemux)
|
|
||||||
add_library(webpdemux ALIAS WebP::webpdemux)
|
|
||||||
elseif(TARGET WebP::libwebpdemux)
|
|
||||||
add_library(webpdemux ALIAS WebP::libwebpdemux)
|
|
||||||
else()
|
|
||||||
message(FATAL_ERROR "System WebP package must provide WebP::webpdemux or WebP::libwebpdemux.")
|
|
||||||
endif()
|
|
||||||
else()
|
else()
|
||||||
find_package(PkgConfig REQUIRED)
|
find_package(PkgConfig REQUIRED)
|
||||||
pkg_check_modules(WebP REQUIRED IMPORTED_TARGET GLOBAL libwebp)
|
pkg_check_modules(WebP REQUIRED IMPORTED_TARGET GLOBAL libwebp)
|
||||||
pkg_check_modules(WebPMux REQUIRED IMPORTED_TARGET GLOBAL libwebpmux)
|
pkg_check_modules(WebPMux REQUIRED IMPORTED_TARGET GLOBAL libwebpmux)
|
||||||
pkg_check_modules(WebPDemux REQUIRED IMPORTED_TARGET GLOBAL libwebpdemux)
|
link_libraries(PkgConfig::WebP)
|
||||||
add_library(webp ALIAS PkgConfig::WebP)
|
link_libraries(PkgConfig::WebPMux)
|
||||||
add_library(libwebpmux ALIAS PkgConfig::WebPMux)
|
add_library(libwebpmux ALIAS PkgConfig::WebPMux)
|
||||||
add_library(webpdemux ALIAS PkgConfig::WebPDemux)
|
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
@ -213,7 +189,7 @@ if(SD_WEBM)
|
||||||
pkg_check_modules(WebM REQUIRED IMPORTED_TARGET GLOBAL libwebm)
|
pkg_check_modules(WebM REQUIRED IMPORTED_TARGET GLOBAL libwebm)
|
||||||
endif()
|
endif()
|
||||||
if(PkgConfig_FOUND AND WebM_FOUND)
|
if(PkgConfig_FOUND AND WebM_FOUND)
|
||||||
add_library(webm ALIAS PkgConfig::WebM)
|
link_libraries(PkgConfig::WebM)
|
||||||
else()
|
else()
|
||||||
find_path(WEBM_INCLUDE_DIR
|
find_path(WEBM_INCLUDE_DIR
|
||||||
NAMES mkvmuxer/mkvmuxer.h mkvparser/mkvparser.h common/webmids.h
|
NAMES mkvmuxer/mkvmuxer.h mkvparser/mkvparser.h common/webmids.h
|
||||||
|
|
@ -239,49 +215,26 @@ endif ()
|
||||||
|
|
||||||
set(SD_LIB stable-diffusion)
|
set(SD_LIB stable-diffusion)
|
||||||
|
|
||||||
file(GLOB SD_API_TEMPLATES CONFIGURE_DEPENDS "src/api/templates/*.dgl")
|
|
||||||
set(SD_API_TEMPLATE_CONTENT "#ifndef __SD_API_TEMPLATES_H__\n#define __SD_API_TEMPLATES_H__\n#include <map>\n#include <string>\n#include <string_view>\nnamespace sd::api::templates {\ninline const std::map<std::string, std::string_view> sources = {\n")
|
|
||||||
foreach(SD_API_TEMPLATE IN LISTS SD_API_TEMPLATES)
|
|
||||||
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${SD_API_TEMPLATE}")
|
|
||||||
get_filename_component(SD_API_TEMPLATE_NAME "${SD_API_TEMPLATE}" NAME_WE)
|
|
||||||
file(READ "${SD_API_TEMPLATE}" SD_API_TEMPLATE_TEXT)
|
|
||||||
string(APPEND SD_API_TEMPLATE_CONTENT "{\"${SD_API_TEMPLATE_NAME}\", R\"SD_DGL(${SD_API_TEMPLATE_TEXT})SD_DGL\"},\n")
|
|
||||||
endforeach()
|
|
||||||
string(APPEND SD_API_TEMPLATE_CONTENT "};\n}\n#endif\n")
|
|
||||||
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/generated/api_templates.h" CONTENT "${SD_API_TEMPLATE_CONTENT}")
|
|
||||||
|
|
||||||
file(GLOB SD_LIB_SOURCES CONFIGURE_DEPENDS
|
file(GLOB SD_LIB_SOURCES CONFIGURE_DEPENDS
|
||||||
"src/*.h"
|
"src/*.h"
|
||||||
"src/*.cpp"
|
"src/*.cpp"
|
||||||
"src/*.hpp"
|
"src/*.hpp"
|
||||||
"src/api/*.h"
|
|
||||||
"src/api/*.cpp"
|
|
||||||
"src/conditioning/*.h"
|
"src/conditioning/*.h"
|
||||||
"src/conditioning/*.cpp"
|
"src/conditioning/*.cpp"
|
||||||
"src/conditioning/*.hpp"
|
"src/conditioning/*.hpp"
|
||||||
"src/core/*.h"
|
"src/core/*.h"
|
||||||
"src/core/*.cpp"
|
"src/core/*.cpp"
|
||||||
"src/core/*.hpp"
|
"src/core/*.hpp"
|
||||||
"src/core/cpu/*.h"
|
|
||||||
"src/core/cpu/*.cpp"
|
|
||||||
"src/core/probe/*.h"
|
"src/core/probe/*.h"
|
||||||
"src/core/probe/*.cpp"
|
"src/core/probe/*.cpp"
|
||||||
"src/extensions/*.h"
|
"src/extensions/*.h"
|
||||||
"src/extensions/*.cpp"
|
"src/extensions/*.cpp"
|
||||||
"src/extensions/*.hpp"
|
"src/extensions/*.hpp"
|
||||||
"src/dgl/*.h"
|
|
||||||
"src/dgl/*.cpp"
|
|
||||||
"src/dgl/syntax/*.h"
|
|
||||||
"src/dgl/syntax/*.cpp"
|
|
||||||
"src/dgl/bindings/*.h"
|
|
||||||
"src/dgl/bindings/*.cpp"
|
|
||||||
"src/dgl/models/*.h"
|
|
||||||
"src/dgl/models/*.cpp"
|
|
||||||
"src/dgl/ops/*.h"
|
|
||||||
"src/dgl/ops/*.cpp"
|
|
||||||
"src/model/*/*.h"
|
"src/model/*/*.h"
|
||||||
"src/model/*/*.cpp"
|
"src/model/*/*.cpp"
|
||||||
"src/model/*/*.hpp"
|
"src/model/*/*.hpp"
|
||||||
|
"src/pipeline/*.h"
|
||||||
|
"src/pipeline/*.cpp"
|
||||||
"src/runtime/*.h"
|
"src/runtime/*.h"
|
||||||
"src/runtime/*.cpp"
|
"src/runtime/*.cpp"
|
||||||
"src/runtime/*.hpp"
|
"src/runtime/*.hpp"
|
||||||
|
|
@ -385,71 +338,11 @@ target_link_libraries(${SD_LIB} PUBLIC ggml)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
target_link_libraries(${SD_LIB} PRIVATE Threads::Threads)
|
target_link_libraries(${SD_LIB} PRIVATE Threads::Threads)
|
||||||
target_link_libraries(${SD_LIB} PRIVATE onig sd-utf8proc)
|
target_link_libraries(${SD_LIB} PRIVATE onig sd-utf8proc)
|
||||||
if(SD_WEBP)
|
|
||||||
target_compile_definitions(${SD_LIB} PRIVATE SD_USE_WEBP)
|
|
||||||
target_link_libraries(${SD_LIB} PRIVATE webp webpdemux)
|
|
||||||
endif()
|
|
||||||
if(SD_WEBM)
|
|
||||||
target_compile_definitions(${SD_LIB} PRIVATE SD_USE_WEBM)
|
|
||||||
target_link_libraries(${SD_LIB} PRIVATE webm)
|
|
||||||
endif()
|
|
||||||
if (SD_CUDA)
|
if (SD_CUDA)
|
||||||
find_package(CUDAToolkit REQUIRED)
|
find_package(CUDAToolkit REQUIRED)
|
||||||
# Keep the driver stub on downstream link lines when no driver is installed.
|
# Keep the driver stub on downstream link lines when no driver is installed.
|
||||||
target_link_libraries(${SD_LIB} PUBLIC CUDA::cuda_driver)
|
target_link_libraries(${SD_LIB} PUBLIC CUDA::cuda_driver)
|
||||||
set_property(SOURCE src/core/ggml_extend_backend.cpp APPEND PROPERTY COMPILE_DEFINITIONS SD_USE_CUDA)
|
set_property(SOURCE src/core/ggml_extend_backend.cpp APPEND PROPERTY COMPILE_DEFINITIONS SD_USE_CUDA)
|
||||||
if (NOT SD_USE_UPSTREAM_GGML)
|
|
||||||
include(cmake/cutlass.cmake)
|
|
||||||
if (TARGET ggml-cuda)
|
|
||||||
# ggml resolves CUDA architectures in a child directory scope.
|
|
||||||
get_target_property(CMAKE_CUDA_ARCHITECTURES ggml-cuda CUDA_ARCHITECTURES)
|
|
||||||
endif()
|
|
||||||
enable_language(CUDA)
|
|
||||||
set_target_properties(${SD_LIB} PROPERTIES
|
|
||||||
CUDA_STANDARD 17
|
|
||||||
CUDA_STANDARD_REQUIRED ON
|
|
||||||
CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}")
|
|
||||||
if (SD_CUDA_CUTLASS_PATH)
|
|
||||||
target_sources(${SD_LIB} PRIVATE src/core/cuda/cute_attention.cu src/core/cuda/i8_projection.cu src/core/cuda/i8_gated_residual.cu src/core/cuda/i8_gemm.cu src/core/cuda/bf16_gemm.cu)
|
|
||||||
set_source_files_properties(src/core/cuda/cute_attention.cu src/core/cuda/i8_projection.cu src/core/cuda/i8_gated_residual.cu src/core/cuda/i8_gemm.cu src/core/cuda/bf16_gemm.cu PROPERTIES
|
|
||||||
INCLUDE_DIRECTORIES "${SD_CUDA_CUTLASS_PATH}/include"
|
|
||||||
COMPILE_OPTIONS "--use_fast_math;--extended-lambda;--expt-relaxed-constexpr")
|
|
||||||
if (MSVC)
|
|
||||||
set_property(SOURCE src/core/cuda/cute_attention.cu src/core/cuda/i8_projection.cu src/core/cuda/i8_gated_residual.cu src/core/cuda/i8_gemm.cu src/core/cuda/bf16_gemm.cu APPEND PROPERTY COMPILE_OPTIONS -Xcompiler=/Zc:preprocessor,/Zc:__cplusplus)
|
|
||||||
endif()
|
|
||||||
if (GGML_CUDA_FORCE_CUBLAS)
|
|
||||||
set_property(SOURCE src/core/cuda/i8_projection.cu src/core/cuda/i8_gated_residual.cu src/core/cuda/i8_gemm.cu src/core/cuda/bf16_gemm.cu APPEND PROPERTY COMPILE_DEFINITIONS SD_CUDA_FORCE_CUBLAS)
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
set(SD_BACKEND_REGISTRATIONS)
|
|
||||||
if (SD_METAL AND NOT SD_USE_UPSTREAM_GGML)
|
|
||||||
add_subdirectory(src/core/metal)
|
|
||||||
target_link_libraries(${SD_LIB} PRIVATE "-framework Foundation" "-framework Metal")
|
|
||||||
list(APPEND SD_BACKEND_REGISTRATIONS sd_ggml_register_metal_i8)
|
|
||||||
endif()
|
|
||||||
if (NOT SD_USE_UPSTREAM_GGML AND (SD_CUDA OR SD_HIPBLAS OR SD_MUSA))
|
|
||||||
if(SD_HIPBLAS)
|
|
||||||
include(cmake/hip.cmake)
|
|
||||||
endif()
|
|
||||||
add_subdirectory(src/core/cuda)
|
|
||||||
foreach(VENDOR CUDA HIP MUSA)
|
|
||||||
if(SD_${VENDOR} OR (VENDOR STREQUAL "HIP" AND SD_HIPBLAS))
|
|
||||||
string(TOLOWER "${VENDOR}" NAMESPACE)
|
|
||||||
list(APPEND SD_BACKEND_REGISTRATIONS "sd_${NAMESPACE}::register_extensions")
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
endif()
|
|
||||||
if (SD_VULKAN AND NOT SD_USE_UPSTREAM_GGML)
|
|
||||||
add_subdirectory(src/core/vulkan)
|
|
||||||
list(APPEND SD_BACKEND_REGISTRATIONS sd_ggml_register_vulkan_rope sd_ggml_register_vulkan_i8 sd_ggml_register_vulkan_modulate sd_ggml_register_vulkan_rms_affine)
|
|
||||||
endif()
|
|
||||||
if(SD_BACKEND_REGISTRATIONS)
|
|
||||||
string(REPLACE ";" ",\n " SD_BACKEND_REGISTRATIONS "${SD_BACKEND_REGISTRATIONS}")
|
|
||||||
configure_file(cmake/backend_extensions.h.in generated/sd_backend_extensions.h @ONLY)
|
|
||||||
set_property(SOURCE src/core/ggml_extensions.cpp APPEND PROPERTY INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}/generated")
|
|
||||||
set_property(SOURCE src/core/ggml_extensions.cpp APPEND PROPERTY COMPILE_DEFINITIONS SD_BACKEND_EXTENSIONS)
|
|
||||||
endif()
|
endif()
|
||||||
if (SD_HIPBLAS)
|
if (SD_HIPBLAS)
|
||||||
find_package(hip REQUIRED CONFIG HINTS "$ENV{ROCM_PATH}" /opt/rocm)
|
find_package(hip REQUIRED CONFIG HINTS "$ENV{ROCM_PATH}" /opt/rocm)
|
||||||
|
|
@ -460,12 +353,9 @@ if (SD_HIPBLAS)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
target_include_directories(${SD_LIB} PUBLIC include)
|
target_include_directories(${SD_LIB} PUBLIC include)
|
||||||
target_include_directories(${SD_LIB} PRIVATE src src/core "${CMAKE_CURRENT_BINARY_DIR}/generated")
|
target_include_directories(${SD_LIB} PRIVATE src src/core)
|
||||||
target_include_directories(${SD_LIB} PUBLIC thirdparty)
|
target_include_directories(${SD_LIB} PUBLIC thirdparty)
|
||||||
target_compile_features(${SD_LIB} PUBLIC c_std_11 cxx_std_17)
|
target_compile_features(${SD_LIB} PUBLIC c_std_11 cxx_std_17)
|
||||||
set_target_properties(${SD_LIB} PROPERTIES
|
|
||||||
CXX_VISIBILITY_PRESET hidden
|
|
||||||
VISIBILITY_INLINES_HIDDEN ON)
|
|
||||||
|
|
||||||
|
|
||||||
if (SD_BUILD_EXAMPLES)
|
if (SD_BUILD_EXAMPLES)
|
||||||
|
|
@ -474,7 +364,6 @@ endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# install
|
# install
|
||||||
#
|
#
|
||||||
|
|
@ -490,9 +379,12 @@ set(SD_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR} CACHE PATH "Location of h
|
||||||
set(SD_LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR} CACHE PATH "Location of library 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_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}
|
set_target_properties(${SD_LIB}
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/include/stable-diffusion.h")
|
PUBLIC_HEADER "${SD_PUBLIC_HEADERS}")
|
||||||
|
|
||||||
|
|
||||||
install(TARGETS ${SD_LIB}
|
install(TARGETS ${SD_LIB}
|
||||||
|
|
|
||||||
|
|
@ -29,85 +29,9 @@ PRs should include:
|
||||||
- Linked issue/PR context when applicable.
|
- Linked issue/PR context when applicable.
|
||||||
- Screenshots or sample outputs for UI/visual behavior changes.
|
- Screenshots or sample outputs for UI/visual behavior changes.
|
||||||
|
|
||||||
## Documentation
|
## README UI Listings
|
||||||
|
|
||||||
Write model and component usage guides in `docs/models/` for users. Focus on
|
The [UIs list in the README](README.md#uis) only includes open-source projects that use `stable-diffusion.cpp` as a backend. Do not submit PRs to add closed-source UIs.
|
||||||
supported weights, setup, runnable commands, parameter meanings, output behavior,
|
|
||||||
and practical limits such as memory requirements. Include technical details only
|
|
||||||
when they help users choose settings or troubleshoot a problem.
|
|
||||||
|
|
||||||
Put shared usage workflows and configuration in `docs/guides/`, and internal
|
|
||||||
implementation details and development conventions in `docs/development/`.
|
|
||||||
Keep build, Docker, and troubleshooting guides at the root of `docs/`.
|
|
||||||
Link new documentation from [the documentation index](docs/README.md) or
|
|
||||||
[the model index](docs/models/README.md), as appropriate. Keep supported model
|
|
||||||
entries and their guide links in the project README.
|
|
||||||
|
|
||||||
Use **DGL** for the language name in headings, prose, link text, UI labels,
|
|
||||||
comments, logs, and diagnostics. Preserve literal spellings in commands, files,
|
|
||||||
paths, and protocol or metadata fields, such as `-M dgl`, `.dgl`, `docs/dgl/`,
|
|
||||||
and the metadata key `dgl`. Code identifiers follow their existing naming style,
|
|
||||||
such as `sd_dgl_run`, `sd::dgl`, `SD_DGL_VALUE_TENSOR`, and `DglWorkspace`.
|
|
||||||
|
|
||||||
### Model Documentation
|
|
||||||
|
|
||||||
Every new model or component integration must include a user guide in
|
|
||||||
`docs/models/` in the same PR. For a variant or new task of an existing family,
|
|
||||||
update that family's guide instead of creating a duplicate page. Add new guides
|
|
||||||
to the model index, and update the supported-model entries and guide links in
|
|
||||||
the project README when adding a model family or capability.
|
|
||||||
|
|
||||||
Model guides should use the model name as their single top-level heading and
|
|
||||||
start with a short description of supported tasks and compatibility requirements.
|
|
||||||
`Model files` and `Usage` are required. Use the following sections in order,
|
|
||||||
omitting other sections when they have no content:
|
|
||||||
|
|
||||||
- `Supported variants` when variants need a separate comparison.
|
|
||||||
- `Model files`, with component, weights/downloads, CLI option, and requirement
|
|
||||||
columns. Include tokenizers, projectors, connectors, downloads, conversion, and
|
|
||||||
required preprocessing.
|
|
||||||
- `Usage`, with `Web UI`, `DGL`, and `Legacy CLI` subsections in that order
|
|
||||||
where applicable. Group DGL scripts in a task table with descriptive links;
|
|
||||||
put shared run instructions below the table. Link to the
|
|
||||||
server's shared Web UI guide and list compatible recipes/components. Group
|
|
||||||
complete CLI examples by task or variant within this section; do not add a
|
|
||||||
separate `Quick start` or `Examples` section. Keep API usage in its own
|
|
||||||
subsection when needed.
|
|
||||||
- `Options` for model-specific settings.
|
|
||||||
- `Notes and limitations` for input/output constraints, memory requirements,
|
|
||||||
and unsupported functionality.
|
|
||||||
|
|
||||||
Follow the [model example conventions](docs/models/README.md#example-conventions)
|
|
||||||
for working directories and shell syntax. Provide Windows PowerShell and
|
|
||||||
Linux/macOS forms of executable examples, using `.\bin\Release\sd-cli.exe` and
|
|
||||||
`./bin/sd-cli` respectively from the build directory. Use the corresponding
|
|
||||||
server paths for Web UI startup. Keep backend-specific examples clearly labeled.
|
|
||||||
Use multiline commands with mode and
|
|
||||||
model components first, followed by inputs/prompts, sampling settings, dimensions,
|
|
||||||
other model options, memory/backend options, and output/seed settings. Preserve
|
|
||||||
checkpoint-specific values when reorganizing existing examples. Keep example
|
|
||||||
images next to their commands, and update links when section anchors change.
|
|
||||||
Keep shared Web UI operating instructions in `examples/server/README.md` and
|
|
||||||
link to them from model guides. Document shared settings by linking to
|
|
||||||
`docs/guides/`. Only describe Web UI
|
|
||||||
recipes and capabilities that already exist; documentation cleanup alone is not
|
|
||||||
a reason to add or change a built-in recipe.
|
|
||||||
|
|
||||||
Before submitting, check download links, relative links, command paths, CLI
|
|
||||||
options, and any recipe/component mappings against the implementation. Report
|
|
||||||
which examples were actually run and which were only inspected in the PR's
|
|
||||||
verification notes.
|
|
||||||
|
|
||||||
Keep tensor layouts, internal class names, kernel implementation details,
|
|
||||||
algorithm derivations, and development history out of usage guides. Keep task-specific
|
|
||||||
profiling logs, numerical comparison procedures, and test artifacts local, and
|
|
||||||
summarize relevant verification results in the PR description.
|
|
||||||
|
|
||||||
## Application and UI Listings
|
|
||||||
|
|
||||||
The [applications and UIs list](docs/ecosystem.md#applications-and-uis) only
|
|
||||||
includes open-source projects that use `stable-diffusion.cpp` as a backend.
|
|
||||||
Do not submit PRs to add closed-source applications or UIs.
|
|
||||||
|
|
||||||
## Server Recipes
|
## Server Recipes
|
||||||
|
|
||||||
|
|
@ -140,8 +64,7 @@ Naming conventions:
|
||||||
|
|
||||||
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.
|
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
|
When adding or modifying model implementations, follow the model config and weight detection conventions in [docs/model_config.md](docs/model_config.md).
|
||||||
[model config and weight detection conventions](docs/development/model_config.md).
|
|
||||||
|
|
||||||
## Tokenizer Data
|
## Tokenizer Data
|
||||||
|
|
||||||
|
|
|
||||||
238
README.md
238
README.md
|
|
@ -15,7 +15,6 @@ API and command-line option may change frequently.***
|
||||||
|
|
||||||
## 🔥Important News
|
## 🔥Important News
|
||||||
|
|
||||||
* **2026/11/11** 🚀 stable-diffusion.cpp adds **Day-0 support for MiniMax-H3-Image**
|
|
||||||
* **2026/10/16** 🚀 stable-diffusion.cpp adds **Day-0 support for MOSS-Image-Base / MOSS-Image-SFT**
|
* **2026/10/16** 🚀 stable-diffusion.cpp adds **Day-0 support for MOSS-Image-Base / MOSS-Image-SFT**
|
||||||
* **2026/10/16** 🚀 stable-diffusion.cpp adds **Day-0 support for FLUX.3 Image Klein / Klein Base**
|
* **2026/10/16** 🚀 stable-diffusion.cpp adds **Day-0 support for FLUX.3 Image Klein / Klein Base**
|
||||||
* **2026/09/20** 🚀 stable-diffusion.cpp adds **Day-0 support for Qwen-Image-2.1**
|
* **2026/09/20** 🚀 stable-diffusion.cpp adds **Day-0 support for Qwen-Image-2.1**
|
||||||
|
|
@ -39,70 +38,63 @@ API and command-line option may change frequently.***
|
||||||
|
|
||||||
- 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)
|
- 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
|
- Super lightweight and without external dependencies
|
||||||
- Built-in [Web UI](./examples/server/README.md) for image and video generation
|
|
||||||
- Supported models
|
- Supported models
|
||||||
- Image Models
|
- Image Models
|
||||||
- [SD1.x, SD2.x, SD-Turbo](./docs/models/sd.md)
|
- [SD1.x, SD2.x, SD-Turbo](./docs/sd.md)
|
||||||
- [SDXL, SDXL-Turbo](./docs/models/sd.md)
|
- [SDXL, SDXL-Turbo](./docs/sd.md)
|
||||||
- [Some SD1.x and SDXL distilled models](./docs/models/distilled_sd.md)
|
- [Some SD1.x and SDXL distilled models](./docs/distilled_sd.md)
|
||||||
- [SD3/SD3.5](./docs/models/sd3.md)
|
- [SD3/SD3.5](./docs/sd3.md)
|
||||||
- [FLUX.1-dev/FLUX.1-schnell](./docs/models/flux.md)
|
- [FLUX.1-dev/FLUX.1-schnell](./docs/flux.md)
|
||||||
- [FLUX.2-dev/FLUX.2-klein](./docs/models/flux2.md)
|
- [FLUX.2-dev/FLUX.2-klein](./docs/flux2.md)
|
||||||
- [FLUX.3 Image Klein / Klein Base](./docs/models/flux3.md)
|
- [FLUX.3 Image Klein / Klein Base](./docs/flux3.md)
|
||||||
- [MOSS-Image-Base / MOSS-Image-SFT](./docs/models/moss_image.md)
|
- [MOSS-Image-Base / MOSS-Image-SFT](./docs/moss_image.md)
|
||||||
- [Fibo 2.0 Dev](./docs/models/fibo2.md)
|
- [Fibo 2.0 Dev](./docs/fibo2.md)
|
||||||
- [Lens](./docs/models/lens.md)
|
- [Lens](./docs/lens.md)
|
||||||
- [Chroma](./docs/models/chroma.md)
|
- [Chroma](./docs/chroma.md)
|
||||||
- [Chroma1-Radiance](./docs/models/chroma_radiance.md)
|
- [Chroma1-Radiance](./docs/chroma_radiance.md)
|
||||||
- [Qwen Image](./docs/models/qwen_image.md)
|
- [Qwen Image](./docs/qwen_image.md)
|
||||||
- [Qwen Image 2.1](./docs/models/qwen_image_2.1.md)
|
- [Qwen Image 2.1](./docs/qwen_image_2.1.md)
|
||||||
- [PiD](./docs/models/pid.md)
|
- [PiD](./docs/pid.md)
|
||||||
- [LongCat Image](./docs/models/longcat_image.md)
|
- [LongCat Image](./docs/longcat_image.md)
|
||||||
- [Z-Image](./docs/models/z_image.md), including [DGL ControlNet](./docs/models/z_image.md#controlnet)
|
- [Z-Image](./docs/z_image.md)
|
||||||
- [Z-Image L2P](./docs/models/z_image_l2p.md)
|
- [Z-Image L2P](./docs/z_image_l2p.md)
|
||||||
- [MiniT2I](./docs/models/minit2i.md)
|
- [MiniT2I](./docs/minit2i.md)
|
||||||
- [P-H3-Image](./docs/models/p_h3_image.md)
|
- [SenseNova U1.5](./docs/sensenova_u1.md)
|
||||||
- [MiniMax-H3-Image](./docs/models/minimax_h3_image.md)
|
- [Ovis-Image](./docs/ovis_image.md)
|
||||||
- [SenseNova U1.5](./docs/models/sensenova_u1.md)
|
- [Anima](./docs/anima.md)
|
||||||
- [Ovis-Image](./docs/models/ovis_image.md)
|
- [ERNIE-Image](./docs/ernie_image.md)
|
||||||
- [Anima](./docs/models/anima.md)
|
- [Boogu Image](./docs/boogu_image.md)
|
||||||
- [ERNIE-Image](./docs/models/ernie_image.md)
|
- [Krea2](./docs/krea2.md)
|
||||||
- [Boogu Image](./docs/models/boogu_image.md)
|
- [Mage-Flow](./docs/mage_flow.md)
|
||||||
- [Krea2](./docs/models/krea2.md)
|
- [SeFi-Image](./docs/sefi_image.md)
|
||||||
- [Mage-Flow](./docs/models/mage_flow.md)
|
- [HiDream-O1-Image](./docs/hidream_o1_image.md)
|
||||||
- [SeFi-Image](./docs/models/sefi_image.md)
|
- [Ideogram4](./docs/ideogram4.md)
|
||||||
- [HiDream-O1-Image](./docs/models/hidream_o1_image.md)
|
- [LLaDA-Image](./docs/llada_image.md)
|
||||||
- [Ideogram4](./docs/models/ideogram4.md)
|
- [Ming-Image Design](./docs/ming_image.md)
|
||||||
- [LLaDA-Image](./docs/models/llada_image.md)
|
- [PixArt](./docs/pixart.md)
|
||||||
- [Ming-Image Design](./docs/models/ming_image.md)
|
- [Iris-3B](./docs/iris.md)
|
||||||
- [PixArt](./docs/models/pixart.md)
|
- [Image Edit Models](./docs/edit.md)
|
||||||
- [Iris-3B](./docs/models/iris.md)
|
- [FLUX.1-Kontext-dev](./docs/kontext.md)
|
||||||
- [Image Edit Models](./docs/guides/edit.md)
|
- [Qwen Image Edit series](./docs/qwen_image_edit.md)
|
||||||
- [FLUX.1-Kontext-dev](./docs/models/kontext.md)
|
- [LongCat Image Edit](./docs/longcat_image.md)
|
||||||
- [Qwen Image Edit series](./docs/models/qwen_image_edit.md)
|
- [Boogu Image Edit](./docs/boogu_image.md)
|
||||||
- [LongCat Image Edit](./docs/models/longcat_image.md)
|
- [Mage-Flow-Edit](./docs/mage_flow.md#image-editing)
|
||||||
- [Boogu Image Edit](./docs/models/boogu_image.md)
|
- [LLaDA-Image Edit](./docs/llada_image.md#image-editing)
|
||||||
- [Mage-Flow-Edit](./docs/models/mage_flow.md#image-editing)
|
- [Fibo 2.0 Dev / Edit Turbo](./docs/fibo2.md#editing-and-turbo)
|
||||||
- [LLaDA-Image Edit](./docs/models/llada_image.md#image-editing)
|
|
||||||
- [Fibo 2.0 Dev / Edit Turbo](./docs/models/fibo2.md#fibo-20-edit-turbo)
|
|
||||||
- [MOSS-Image Edit](./docs/models/moss_image.md#moss-image-edit)
|
|
||||||
- Video Models
|
- Video Models
|
||||||
- [Wan2.1/Wan2.2](./docs/models/wan.md)
|
- [Wan2.1/Wan2.2](./docs/wan.md)
|
||||||
- [MiniMax-H3](./docs/models/minimax_h3.md)
|
- [MiniMax-H3](./docs/minimax_h3.md)
|
||||||
- [LTX-2.3/LTX-2.5](./docs/models/ltx2.md)
|
- [LTX-2.3/LTX-2.5](./docs/ltx2.md)
|
||||||
- [HunyuanVideo 1.5](./docs/models/hunyuan_video.md)
|
- [HunyuanVideo 1.5](./docs/hunyuan_video.md)
|
||||||
- [LingBot-Video](./docs/models/lingbot_video.md)
|
- [LingBot-Video](./docs/lingbot_video.md)
|
||||||
- Video Upscale Models
|
- [PhotoMaker](./docs/photo_maker.md) support.
|
||||||
- [RelayVSR](./docs/models/relay_vsr.md)
|
- [IP-Adapter](./docs/ip_adapter.md) support (SD 1.5 and SDXL, including Plus)
|
||||||
- [SeedVR2](./docs/models/seedvr2.md)
|
|
||||||
- [PhotoMaker](./docs/models/photo_maker.md) support.
|
|
||||||
- [IP-Adapter](./docs/models/ip_adapter.md) support (SD 1.5 and SDXL, including Plus)
|
|
||||||
- Control Net support with SD 1.5
|
- Control Net support with SD 1.5
|
||||||
- [ADetailer](./docs/models/adetailer.md)
|
- [ADetailer](./docs/adetailer.md)
|
||||||
- LoRA support, same as [stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Features#lora)
|
- LoRA support, same as [stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Features#lora)
|
||||||
- Latent Consistency Models support (LCM/LCM-LoRA)
|
- Latent Consistency Models support (LCM/LCM-LoRA)
|
||||||
- Faster and memory efficient latent decoding with [TAESD](./docs/models/taesd.md)
|
- Faster and memory efficient latent decoding with [TAESD](./docs/taesd.md)
|
||||||
- Upscale images generated with [ESRGAN](./docs/models/esrgan.md)
|
- Upscale images generated with [ESRGAN](./docs/esrgan.md)
|
||||||
- Supported backends
|
- Supported backends
|
||||||
- CPU (AVX, AVX2 and AVX512 support for x86 architectures)
|
- CPU (AVX, AVX2 and AVX512 support for x86 architectures)
|
||||||
- CUDA
|
- CUDA
|
||||||
|
|
@ -124,7 +116,16 @@ API and command-line option may change frequently.***
|
||||||
- Negative prompt
|
- Negative prompt
|
||||||
- [stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui) style tokenizer (not all the features, only token weighting for now)
|
- [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
|
- VAE tiling processing for reduce memory usage
|
||||||
- Support for a wide range of [sampling methods and schedulers](./docs/guides/sampling.md)
|
- 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
|
- Cross-platform reproducibility
|
||||||
- `--rng cuda`, default, consistent with the `stable-diffusion-webui GPU RNG`
|
- `--rng cuda`, default, consistent with the `stable-diffusion-webui GPU RNG`
|
||||||
- `--rng cpu`, consistent with the `comfyui RNG`
|
- `--rng cpu`, consistent with the `comfyui RNG`
|
||||||
|
|
@ -132,93 +133,70 @@ API and command-line option may change frequently.***
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
### Get the executables
|
### Get the sd executable
|
||||||
|
|
||||||
- Download and extract pre-built binaries from the [releases page](https://github.com/leejet/stable-diffusion.cpp/releases)
|
- 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)
|
- Or build from source by following the [build guide](./docs/build.md)
|
||||||
|
|
||||||
The executable examples below run from the build directory (`cd build` from
|
|
||||||
the repository root). Windows examples use the Visual Studio Release path;
|
|
||||||
adjust the executable path for other build configurations or extracted archives.
|
|
||||||
Model files stay under the repository's `models/` directory.
|
|
||||||
|
|
||||||
### Download model weights
|
### Download model weights
|
||||||
|
|
||||||
Choose a model from the [model guides](./docs/models/README.md) and download its
|
- download weights(.ckpt or .safetensors or .gguf). For example
|
||||||
weights and required components. For a simple example, save Stable Diffusion 1.5
|
- Stable Diffusion v1.5 from https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5
|
||||||
under `models/checkpoints/`:
|
|
||||||
|
|
||||||
**Windows (PowerShell)**
|
```sh
|
||||||
|
curl -L -O https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors
|
||||||
|
```
|
||||||
|
|
||||||
```powershell
|
### Generate an image with just one command
|
||||||
New-Item -ItemType Directory -Force ..\models\checkpoints | Out-Null
|
|
||||||
curl.exe -L -o ..\models\checkpoints\v1-5-pruned-emaonly.safetensors https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors
|
|
||||||
```
|
|
||||||
|
|
||||||
**Linux/macOS**
|
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
mkdir -p ../models/checkpoints
|
./bin/sd-cli -m ../models/v1-5-pruned-emaonly.safetensors -p "a lovely cat"
|
||||||
curl -L -o ../models/checkpoints/v1-5-pruned-emaonly.safetensors https://huggingface.co/stable-diffusion-v1-5/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Option 1: Web UI
|
***For detailed command-line arguments, check out [cli doc](./examples/cli/README.md).***
|
||||||
|
|
||||||
Start the server:
|
|
||||||
|
|
||||||
**Windows (PowerShell)**
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
.\bin\Release\sd-server.exe --model-dir ..\models
|
|
||||||
```
|
|
||||||
|
|
||||||
**Linux/macOS**
|
|
||||||
|
|
||||||
```sh
|
|
||||||
./bin/sd-server --model-dir ../models
|
|
||||||
```
|
|
||||||
|
|
||||||
Open <http://127.0.0.1:1234/>, choose **SD 1.x** in **Recipe**, select the
|
|
||||||
checkpoint, and click **Load models**. Enter a prompt and click **Generate**.
|
|
||||||
See the [Web UI guide](./examples/server/README.md#web-ui) for the full workflow.
|
|
||||||
|
|
||||||
### Option 2: CLI
|
|
||||||
|
|
||||||
Generate an image with one command:
|
|
||||||
|
|
||||||
**Windows (PowerShell)**
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
.\bin\Release\sd-cli.exe -m ..\models\checkpoints\v1-5-pruned-emaonly.safetensors -p "a lovely cat"
|
|
||||||
```
|
|
||||||
|
|
||||||
**Linux/macOS**
|
|
||||||
|
|
||||||
```sh
|
|
||||||
./bin/sd-cli -m ../models/checkpoints/v1-5-pruned-emaonly.safetensors -p "a lovely cat"
|
|
||||||
```
|
|
||||||
|
|
||||||
Run `.\bin\Release\sd-cli.exe --help` on Windows or `./bin/sd-cli --help` on
|
|
||||||
Linux/macOS for all command-line options. See the
|
|
||||||
[CLI guide](./examples/cli/README.md) for additional usage notes.
|
|
||||||
|
|
||||||
## Performance
|
## Performance
|
||||||
|
|
||||||
If you want to improve performance or reduce VRAM/RAM usage, please refer to [performance guide](./docs/guides/performance.md).
|
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/guides/backend.md).
|
For runtime and parameter backend placement, see the [backend selection guide](./docs/backend.md).
|
||||||
|
|
||||||
## Documentation
|
## More Guides
|
||||||
|
|
||||||
Browse the [documentation index](./docs/README.md) or jump to a topic:
|
|
||||||
|
|
||||||
- [Getting started: build, Docker, CLI, and server](./docs/README.md#get-started)
|
|
||||||
- [Models and components](./docs/models/README.md)
|
|
||||||
- [Generation and inputs](./docs/README.md#generation-and-inputs)
|
|
||||||
- [DGL generation scripts](./docs/dgl.md)
|
|
||||||
- [Devices and performance](./docs/README.md#devices-and-performance)
|
|
||||||
- [Weights and quantization](./docs/README.md#weights-and-quantization)
|
|
||||||
- [Troubleshooting](./docs/troubleshooting.md)
|
- [Troubleshooting](./docs/troubleshooting.md)
|
||||||
- [Development and contributing](./docs/README.md#development)
|
- [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)
|
||||||
|
- [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)
|
||||||
|
- [Kokon](https://github.com/GabrieleLozupone/kokon)
|
||||||
|
|
||||||
## Contributors
|
## Contributors
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.2 MiB After Width: | Height: | Size: 2.2 MiB |
|
|
@ -1,17 +0,0 @@
|
||||||
#ifndef __SD_BACKEND_EXTENSIONS_H__
|
|
||||||
#define __SD_BACKEND_EXTENSIONS_H__
|
|
||||||
|
|
||||||
#include "core/cuda/registration.h"
|
|
||||||
|
|
||||||
void sd_ggml_register_metal_i8(ggml_backend_dev_t device);
|
|
||||||
|
|
||||||
void sd_ggml_register_vulkan_rope(ggml_backend_dev_t device);
|
|
||||||
void sd_ggml_register_vulkan_i8(ggml_backend_dev_t device);
|
|
||||||
void sd_ggml_register_vulkan_rms_affine(ggml_backend_dev_t device);
|
|
||||||
void sd_ggml_register_vulkan_modulate(ggml_backend_dev_t device);
|
|
||||||
|
|
||||||
static void (*const sd_backend_extensions[])(ggml_backend_dev_t) = {
|
|
||||||
@SD_BACKEND_REGISTRATIONS@
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
@ -1,20 +0,0 @@
|
||||||
set(sd_cutlass_default "${PROJECT_SOURCE_DIR}/thirdparty/cutlass")
|
|
||||||
if(NOT DEFINED SD_CUDA_CUTLASS_PATH AND DEFINED GGML_CUDA_CUTLASS_PATH)
|
|
||||||
get_filename_component(sd_old_cutlass_default "${SD_GGML_SOURCE_DIR}/src/ggml-cuda/vendors/cutlass" ABSOLUTE)
|
|
||||||
if(NOT GGML_CUDA_CUTLASS_PATH STREQUAL sd_old_cutlass_default)
|
|
||||||
set(sd_cutlass_default "${GGML_CUDA_CUTLASS_PATH}")
|
|
||||||
endif()
|
|
||||||
message(STATUS "Migrating GGML_CUDA_CUTLASS_PATH to SD_CUDA_CUTLASS_PATH")
|
|
||||||
endif()
|
|
||||||
set(SD_CUDA_CUTLASS_PATH "${sd_cutlass_default}" CACHE PATH "sd: CUTLASS source directory for INT8 GEMM and CuTe attention, empty to disable")
|
|
||||||
unset(GGML_CUDA_CUTLASS_PATH CACHE)
|
|
||||||
if(SD_CUDA_CUTLASS_PATH)
|
|
||||||
if(NOT EXISTS "${SD_CUDA_CUTLASS_PATH}/include/cutlass/gemm/kernel/default_gemm_universal_with_visitor.h" OR
|
|
||||||
NOT EXISTS "${SD_CUDA_CUTLASS_PATH}/include/cute/tensor.hpp")
|
|
||||||
message(FATAL_ERROR
|
|
||||||
"CUTLASS headers not found at ${SD_CUDA_CUTLASS_PATH}. "
|
|
||||||
"Run git submodule update --init --recursive from the sd.cpp repository root, "
|
|
||||||
"set SD_CUDA_CUTLASS_PATH to a CUTLASS source tree (tested with 3.9.2), "
|
|
||||||
"or set SD_CUDA_CUTLASS_PATH to an empty string to disable CUTLASS.")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
file(READ "${INPUT}" SPIRV HEX)
|
|
||||||
string(REGEX REPLACE "(..)(..)(..)(..)" "0x\\4\\3\\2\\1," SPIRV_WORDS "${SPIRV}")
|
|
||||||
file(WRITE "${OUTPUT}" "#include <cstdint>\nnamespace sd_vulkan_shaders {\nstatic const uint32_t ${NAME}[] = {${SPIRV_WORDS}};\n}\n")
|
|
||||||
|
|
@ -9,19 +9,17 @@ if(NOT TARGET ggml)
|
||||||
add_library(ggml ALIAS ggml::ggml)
|
add_library(ggml ALIAS ggml::ggml)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(SD_USE_UPSTREAM_GGML)
|
get_target_property(sd_ggml_imported ggml IMPORTED)
|
||||||
get_target_property(sd_ggml_imported ggml IMPORTED)
|
if(sd_ggml_imported)
|
||||||
if(sd_ggml_imported)
|
set(sd_ggml_private_include "${SD_GGML_SOURCE_DIR}/src")
|
||||||
set(sd_ggml_private_include "${SD_GGML_SOURCE_DIR}/src")
|
else()
|
||||||
else()
|
get_target_property(sd_ggml_private_include ggml SOURCE_DIR)
|
||||||
get_target_property(sd_ggml_private_include ggml SOURCE_DIR)
|
|
||||||
endif()
|
|
||||||
if(NOT EXISTS "${sd_ggml_private_include}/ggml-impl.h")
|
|
||||||
message(FATAL_ERROR "Set SD_GGML_SOURCE_DIR to the source tree matching the selected ggml library (ggml-impl.h is required).")
|
|
||||||
endif()
|
|
||||||
target_include_directories(${SD_LIB} PRIVATE "${sd_ggml_private_include}")
|
|
||||||
set_property(TARGET ${SD_LIB} PROPERTY SD_GGML_PRIVATE_INCLUDE_DIR "${sd_ggml_private_include}")
|
|
||||||
endif()
|
endif()
|
||||||
|
if(NOT EXISTS "${sd_ggml_private_include}/ggml-impl.h")
|
||||||
|
message(FATAL_ERROR "Set SD_GGML_SOURCE_DIR to the source tree matching the selected ggml library (ggml-impl.h is required).")
|
||||||
|
endif()
|
||||||
|
target_include_directories(${SD_LIB} PRIVATE "${sd_ggml_private_include}")
|
||||||
|
set_property(TARGET ${SD_LIB} PROPERTY SD_GGML_PRIVATE_INCLUDE_DIR "${sd_ggml_private_include}")
|
||||||
|
|
||||||
if(SD_USE_UPSTREAM_GGML)
|
if(SD_USE_UPSTREAM_GGML)
|
||||||
target_compile_definitions(${SD_LIB} PUBLIC SD_USE_UPSTREAM_GGML)
|
target_compile_definitions(${SD_LIB} PUBLIC SD_USE_UPSTREAM_GGML)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
if(NOT WIN32 AND NOT CMAKE_CXX_COMPILER MATCHES "hipcc")
|
|
||||||
if(NOT CMAKE_HIP_ARCHITECTURES)
|
|
||||||
if(GPU_TARGETS)
|
|
||||||
set(CMAKE_HIP_ARCHITECTURES ${GPU_TARGETS})
|
|
||||||
elseif(AMDGPU_TARGETS)
|
|
||||||
set(CMAKE_HIP_ARCHITECTURES ${AMDGPU_TARGETS})
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
# HIP objects are linked by the parent target, so initialize its link rules here.
|
|
||||||
enable_language(HIP)
|
|
||||||
set_property(TARGET ${SD_LIB} PROPERTY HIP_ARCHITECTURES "${CMAKE_HIP_ARCHITECTURES}")
|
|
||||||
endif()
|
|
||||||
|
|
@ -8,7 +8,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends build-essential
|
||||||
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /tmp/nodesource-repo.gpg.key && \
|
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /tmp/nodesource-repo.gpg.key && \
|
||||||
gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg /tmp/nodesource-repo.gpg.key && \
|
gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg /tmp/nodesource-repo.gpg.key && \
|
||||||
rm /tmp/nodesource-repo.gpg.key && \
|
rm /tmp/nodesource-repo.gpg.key && \
|
||||||
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_24.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \
|
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \
|
||||||
apt-get update && \
|
apt-get update && \
|
||||||
apt-get install -y --no-install-recommends nodejs && \
|
apt-get install -y --no-install-recommends nodejs && \
|
||||||
npm install -g pnpm@10.15.1 && \
|
npm install -g pnpm@10.15.1 && \
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,7 @@
|
||||||
# syntax=docker/dockerfile:1
|
|
||||||
|
|
||||||
ARG CUDA_VERSION=12.6.3
|
ARG CUDA_VERSION=12.6.3
|
||||||
ARG UBUNTU_VERSION=24.04
|
ARG UBUNTU_VERSION=24.04
|
||||||
|
|
||||||
FROM nvidia/cuda:${CUDA_VERSION}-devel-ubuntu${UBUNTU_VERSION} AS build
|
FROM nvidia/cuda:${CUDA_VERSION}-cudnn-devel-ubuntu${UBUNTU_VERSION} AS build
|
||||||
|
|
||||||
# sd-server embeds the web UI at build time, so the build image needs Node/pnpm.
|
# sd-server embeds the web UI at build time, so the build image needs Node/pnpm.
|
||||||
RUN apt-get update && apt-get install -y --no-install-recommends build-essential git ccache cmake ca-certificates curl gnupg && \
|
RUN apt-get update && apt-get install -y --no-install-recommends build-essential git ccache cmake ca-certificates curl gnupg && \
|
||||||
|
|
@ -11,7 +9,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends build-essential
|
||||||
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /tmp/nodesource-repo.gpg.key && \
|
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /tmp/nodesource-repo.gpg.key && \
|
||||||
gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg /tmp/nodesource-repo.gpg.key && \
|
gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg /tmp/nodesource-repo.gpg.key && \
|
||||||
rm /tmp/nodesource-repo.gpg.key && \
|
rm /tmp/nodesource-repo.gpg.key && \
|
||||||
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_24.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \
|
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \
|
||||||
apt-get update && \
|
apt-get update && \
|
||||||
apt-get install -y --no-install-recommends nodejs && \
|
apt-get install -y --no-install-recommends nodejs && \
|
||||||
npm install -g pnpm@10.15.1 && \
|
npm install -g pnpm@10.15.1 && \
|
||||||
|
|
@ -27,15 +25,8 @@ ARG CUDA_ARCHITECTURES=""
|
||||||
ARG GGML_CUDA_FA_ALL_QUANTS=""
|
ARG GGML_CUDA_FA_ALL_QUANTS=""
|
||||||
ARG GGML_CUDA_ENABLE_DYNAMIC_CPU_BACKENDS=ON
|
ARG GGML_CUDA_ENABLE_DYNAMIC_CPU_BACKENDS=ON
|
||||||
|
|
||||||
ENV CCACHE_DIR=/root/.cache/ccache \
|
|
||||||
CCACHE_MAXSIZE=2G \
|
|
||||||
CCACHE_COMPILERCHECK=content
|
|
||||||
|
|
||||||
RUN set -- \
|
RUN set -- \
|
||||||
-DSD_CUDA=ON \
|
-DSD_CUDA=ON; \
|
||||||
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
|
|
||||||
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
|
|
||||||
-DCMAKE_CUDA_COMPILER_LAUNCHER=ccache; \
|
|
||||||
if [ "${GGML_CUDA_ENABLE_DYNAMIC_CPU_BACKENDS}" = "ON" ]; then \
|
if [ "${GGML_CUDA_ENABLE_DYNAMIC_CPU_BACKENDS}" = "ON" ]; then \
|
||||||
set -- "$@" \
|
set -- "$@" \
|
||||||
-DSD_BUILD_SHARED_LIBS=ON \
|
-DSD_BUILD_SHARED_LIBS=ON \
|
||||||
|
|
@ -53,20 +44,15 @@ RUN set -- \
|
||||||
set -- "$@" "-DGGML_CUDA_FA_ALL_QUANTS=${GGML_CUDA_FA_ALL_QUANTS}"; \
|
set -- "$@" "-DGGML_CUDA_FA_ALL_QUANTS=${GGML_CUDA_FA_ALL_QUANTS}"; \
|
||||||
fi; \
|
fi; \
|
||||||
cmake . -B ./build "$@"
|
cmake . -B ./build "$@"
|
||||||
RUN --mount=type=cache,target=/root/.cache/ccache \
|
RUN cmake --build ./build --config Release -j$(nproc)
|
||||||
ccache --zero-stats && \
|
|
||||||
cmake --build ./build --config Release -j$(nproc) && \
|
|
||||||
ccache --cleanup && \
|
|
||||||
ccache --show-stats
|
|
||||||
|
|
||||||
FROM nvidia/cuda:${CUDA_VERSION}-runtime-ubuntu${UBUNTU_VERSION} AS runtime
|
FROM nvidia/cuda:${CUDA_VERSION}-cudnn-runtime-ubuntu${UBUNTU_VERSION} AS runtime
|
||||||
|
|
||||||
RUN apt-get update && \
|
RUN apt-get update && \
|
||||||
apt-get install --yes --no-install-recommends libgomp1 && \
|
apt-get install --yes --no-install-recommends libgomp1 && \
|
||||||
apt-get clean
|
apt-get clean
|
||||||
|
|
||||||
COPY --from=build /sd.cpp/build/bin /sd.cpp/bin
|
COPY --from=build /sd.cpp/build/bin /sd.cpp/bin
|
||||||
COPY --from=build /sd.cpp/thirdparty/cutlass/LICENSE.txt /sd.cpp/bin/cutlass.txt
|
|
||||||
RUN printf '#!/bin/sh\nexec /sd.cpp/bin/sd-cli "$@"\n' > /sd-cli && \
|
RUN printf '#!/bin/sh\nexec /sd.cpp/bin/sd-cli "$@"\n' > /sd-cli && \
|
||||||
printf '#!/bin/sh\nexec /sd.cpp/bin/sd-server "$@"\n' > /sd-server && \
|
printf '#!/bin/sh\nexec /sd.cpp/bin/sd-server "$@"\n' > /sd-server && \
|
||||||
chmod +x /sd-cli /sd-server
|
chmod +x /sd-cli /sd-server
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends ccache cmake gi
|
||||||
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /tmp/nodesource-repo.gpg.key && \
|
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /tmp/nodesource-repo.gpg.key && \
|
||||||
gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg /tmp/nodesource-repo.gpg.key && \
|
gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg /tmp/nodesource-repo.gpg.key && \
|
||||||
rm /tmp/nodesource-repo.gpg.key && \
|
rm /tmp/nodesource-repo.gpg.key && \
|
||||||
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_24.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \
|
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \
|
||||||
apt-get update && \
|
apt-get update && \
|
||||||
apt-get install -y --no-install-recommends nodejs && \
|
apt-get install -y --no-install-recommends nodejs && \
|
||||||
npm install -g pnpm@10.15.1 && \
|
npm install -g pnpm@10.15.1 && \
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||||
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /tmp/nodesource-repo.gpg.key && \
|
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /tmp/nodesource-repo.gpg.key && \
|
||||||
gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg /tmp/nodesource-repo.gpg.key && \
|
gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg /tmp/nodesource-repo.gpg.key && \
|
||||||
rm /tmp/nodesource-repo.gpg.key && \
|
rm /tmp/nodesource-repo.gpg.key && \
|
||||||
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_24.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \
|
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \
|
||||||
apt-get update && apt-get install -y --no-install-recommends nodejs && \
|
apt-get update && apt-get install -y --no-install-recommends nodejs && \
|
||||||
npm install -g pnpm@10.15.1 && \
|
npm install -g pnpm@10.15.1 && \
|
||||||
apt-get clean && rm -rf /var/lib/apt/lists/*
|
apt-get clean && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends cmake ca-certif
|
||||||
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /tmp/nodesource-repo.gpg.key && \
|
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /tmp/nodesource-repo.gpg.key && \
|
||||||
gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg /tmp/nodesource-repo.gpg.key && \
|
gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg /tmp/nodesource-repo.gpg.key && \
|
||||||
rm /tmp/nodesource-repo.gpg.key && \
|
rm /tmp/nodesource-repo.gpg.key && \
|
||||||
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_24.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \
|
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \
|
||||||
apt-get update && \
|
apt-get update && \
|
||||||
apt-get install -y --no-install-recommends nodejs && \
|
apt-get install -y --no-install-recommends nodejs && \
|
||||||
npm install -g pnpm@10.15.1 && \
|
npm install -g pnpm@10.15.1 && \
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends build-essential
|
||||||
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /tmp/nodesource-repo.gpg.key && \
|
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key -o /tmp/nodesource-repo.gpg.key && \
|
||||||
gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg /tmp/nodesource-repo.gpg.key && \
|
gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg /tmp/nodesource-repo.gpg.key && \
|
||||||
rm /tmp/nodesource-repo.gpg.key && \
|
rm /tmp/nodesource-repo.gpg.key && \
|
||||||
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_24.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \
|
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_20.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \
|
||||||
apt-get update && \
|
apt-get update && \
|
||||||
apt-get install -y --no-install-recommends nodejs && \
|
apt-get install -y --no-install-recommends nodejs && \
|
||||||
npm install -g pnpm@10.15.1 && \
|
npm install -g pnpm@10.15.1 && \
|
||||||
|
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
# Documentation
|
|
||||||
|
|
||||||
For the project overview and supported models, see the [project README](../README.md).
|
|
||||||
|
|
||||||
## Get started
|
|
||||||
|
|
||||||
- [Model and component guides](models/README.md): download weights and run model-specific examples.
|
|
||||||
- [Build from source](build.md)
|
|
||||||
- [Docker](docker.md)
|
|
||||||
- [CLI usage guide](../examples/cli/README.md)
|
|
||||||
- [Server setup](../examples/server/README.md)
|
|
||||||
- [Server API reference](../examples/server/api.md)
|
|
||||||
- [Community bindings, applications, and UIs](ecosystem.md)
|
|
||||||
- [Troubleshooting](troubleshooting.md)
|
|
||||||
|
|
||||||
## Generation and inputs
|
|
||||||
|
|
||||||
- [DGL generation scripts](dgl.md)
|
|
||||||
- [DGL model examples](dgl/README.md)
|
|
||||||
- [C API and migration](guides/c_api.md)
|
|
||||||
- [Sampling methods and schedulers](guides/sampling.md)
|
|
||||||
- [Image editing](guides/edit.md)
|
|
||||||
- [Images in prompts](guides/prompt_images.md)
|
|
||||||
- [Image preprocessing](guides/image_preprocessing.md)
|
|
||||||
- [Generation results and metadata](guides/generation_metadata.md)
|
|
||||||
- [JSON tokenizers](guides/tokenizers.md)
|
|
||||||
|
|
||||||
## Devices and performance
|
|
||||||
|
|
||||||
- [Backend selection and device placement](guides/backend.md)
|
|
||||||
- [Performance and memory usage](guides/performance.md)
|
|
||||||
- [Inference caching](guides/caching.md)
|
|
||||||
- [RPC](guides/rpc.md)
|
|
||||||
- [SageAttention](guides/sage_attention.md)
|
|
||||||
|
|
||||||
## Weights and quantization
|
|
||||||
|
|
||||||
- [Quantization and GGUF conversion](guides/quantization_and_gguf.md)
|
|
||||||
- [Importance matrix quantization](guides/imatrix.md)
|
|
||||||
- [INT8 and INT4 convrot weights](guides/int8_convrot.md)
|
|
||||||
|
|
||||||
## Development
|
|
||||||
|
|
||||||
- [C API internals](development/c_api.md)
|
|
||||||
- [DGL architecture](development/dgl.md)
|
|
||||||
- [Model configuration and integration conventions](development/model_config.md)
|
|
||||||
- [ggml operator extensions](development/ggml_extensions.md)
|
|
||||||
- [Backend performance probes](development/backend_probe.md)
|
|
||||||
- [Position embedding cache](development/pe_cache.md)
|
|
||||||
- [PuLID implementation and validation](development/pulid.md)
|
|
||||||
- [Qwen Image 2.1 prefix cache internals](development/qwen_image_prefix_cache.md)
|
|
||||||
- [Contribution guidelines](../CONTRIBUTING.md)
|
|
||||||
143
docs/adetailer.md
Normal file
143
docs/adetailer.md
Normal file
|
|
@ -0,0 +1,143 @@
|
||||||
|
# ADetailer
|
||||||
|
|
||||||
|
`sd-cli` can run a YOLOv8 object detector on an existing or newly generated
|
||||||
|
image, and `sd-server` can run it after image generation. Both perform a cropped
|
||||||
|
inpaint pass for every detected object. The implementation supports YOLOv8
|
||||||
|
detection checkpoints. YOLOv8 segmentation and MediaPipe models are not
|
||||||
|
supported yet.
|
||||||
|
|
||||||
|
## Convert a detector
|
||||||
|
|
||||||
|
Ultralytics checkpoints must be converted before use. The converter fuses
|
||||||
|
BatchNorm into convolution layers and writes a safetensors file with the weight
|
||||||
|
names expected by the native GGML implementation.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
python scripts/convert_yolov8_to_safetensors.py face_yolov8n.pt face_yolov8n.safetensors
|
||||||
|
```
|
||||||
|
|
||||||
|
The converter requires Python packages `ultralytics`, `torch`, and
|
||||||
|
`safetensors`.
|
||||||
|
Only YOLOv8 detection checkpoints are accepted.
|
||||||
|
PyTorch checkpoints use pickle internally, so only convert `.pt` files from a
|
||||||
|
trusted source.
|
||||||
|
|
||||||
|
## Repair an existing image
|
||||||
|
|
||||||
|
Use the dedicated `adetailer` mode to detect and repair objects in an existing
|
||||||
|
image:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./bin/sd-cli \
|
||||||
|
-M adetailer \
|
||||||
|
-m model.safetensors \
|
||||||
|
-i input.png \
|
||||||
|
-o repaired.png \
|
||||||
|
-p "detailed portrait photo" \
|
||||||
|
--negative-prompt "deformed face" \
|
||||||
|
--steps 24 \
|
||||||
|
--cfg-scale 6 \
|
||||||
|
--strength 0.4 \
|
||||||
|
--sampling-method dpm++2m \
|
||||||
|
--scheduler karras \
|
||||||
|
--ad-model face_yolov8n.safetensors \
|
||||||
|
--extra-ad-args "confidence=0.3,inpaint_padding=32,mask_blur=4"
|
||||||
|
```
|
||||||
|
|
||||||
|
This mode reuses the normal image-generation options for the detail pass:
|
||||||
|
|
||||||
|
- `--init-img`, `--output`, `--prompt`, and `--negative-prompt`
|
||||||
|
- `--steps`, `--cfg-scale`, `--sampling-method`, and `--scheduler`
|
||||||
|
- `--strength`, `--seed`, LoRA settings, VAE tiling, and backend assignments
|
||||||
|
- `--width` and `--height`, which also resize the input when specified
|
||||||
|
|
||||||
|
`--ad-prompt` and `--ad-negative-prompt` optionally override the normal prompts.
|
||||||
|
Values provided in `--extra-ad-args`, such as `steps`, `cfg_scale`,
|
||||||
|
`denoising_strength`, or `inpaint_width`, take precedence over inherited values.
|
||||||
|
|
||||||
|
## Repair generated images
|
||||||
|
|
||||||
|
ADetailer can also run automatically after normal image generation:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./bin/sd-cli \
|
||||||
|
-m model.safetensors \
|
||||||
|
-p "portrait photo" \
|
||||||
|
--ad-model face_yolov8n.safetensors \
|
||||||
|
--ad-prompt "[PROMPT], detailed face" \
|
||||||
|
--ad-negative-prompt "" \
|
||||||
|
--extra-ad-args "confidence=0.3,denoising_strength=0.4,inpaint_width=512,inpaint_height=512"
|
||||||
|
```
|
||||||
|
|
||||||
|
The same options can be supplied when starting `sd-server`. When `--ad-model` is set, its detector runs after OpenAI-compatible and native asynchronous image generation. SDAPI requests enable ADetailer through `alwayson_scripts`, as described below. If no object is detected, the original image is returned unchanged. RGBA output keeps its original alpha channel, including when detected regions are repaired. Detector initialization or detail-pass failures are reported as request failures.
|
||||||
|
|
||||||
|
Server image-generation requests limit base, hires, and detail-pass dimensions to 4096 pixels per side. ADetailer step overrides are limited to 1–100; `steps=0` in `extra_ad_args` keeps inheriting the main generation steps. These limits also apply to inherited dimensions and `extra_ad_args` overrides. Requests exceeding the limits return a parameter error before generation. CLI limits are unchanged.
|
||||||
|
|
||||||
|
### SDAPI requests
|
||||||
|
|
||||||
|
`/sdapi/v1/txt2img` and `/sdapi/v1/img2img` accept the WebUI ADetailer argument format:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"prompt": "portrait photo",
|
||||||
|
"alwayson_scripts": {
|
||||||
|
"ADetailer": {
|
||||||
|
"args": [true, false, {
|
||||||
|
"ad_model": "face_yolov8n.pt",
|
||||||
|
"ad_prompt": "[PROMPT], detailed face",
|
||||||
|
"ad_use_steps": true,
|
||||||
|
"ad_steps": 20
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The detector must be configured at server startup with `--ad-model`. `ad_model` must match that file's basename; the original `.pt` basename is also accepted for a converted detector. Requests cannot load arbitrary detector paths. Omitting the script, setting its first argument to `false`, selecting `"None"`, or setting `ad_tab_enable` to `false` disables detailing. Dictionary-only argument arrays are also accepted. Multiple enabled dictionaries run in order using the configured detector.
|
||||||
|
|
||||||
|
Supported settings include prompts, confidence, mask filtering by area or confidence, mask count and area ratios, dilation/erosion, offsets, mask merging/inversion, blur, denoising strength, masked or full-image inpainting, padding, and optional overrides for inpaint dimensions, steps, CFG, sampler/scheduler, and CLIP skip. The corresponding `ad_use_*` flags control whether overrides apply. Otherwise dimensions, steps, CFG, sampler, scheduler, and CLIP skip inherit the main request. Denoising strength defaults to `0.4`. Pixel mask settings are limited to the larger output dimension, with a minimum limit of 32 and a maximum of 16384 pixels.
|
||||||
|
|
||||||
|
Model/VAE switching, non-default noise multipliers, face restoration, ControlNet, and skipping the initial img2img pass are not supported; active requests for these features return an error. Unknown settings and invalid active values also return errors. During detailing, `/sdapi/v1/progress` remains active with an `adetailer` job; its percentage and preview stay fixed until detailing finishes.
|
||||||
|
|
||||||
|
An empty ADetailer prompt inherits the main prompt. `[PROMPT]` inserts the main
|
||||||
|
prompt, `[SEP]` assigns different prompts to consecutive masks, and `[SKIP]`
|
||||||
|
skips the corresponding mask.
|
||||||
|
|
||||||
|
All settings other than the detector path and prompts are passed through
|
||||||
|
`--extra-ad-args` as a comma-separated `key=value` list:
|
||||||
|
|
||||||
|
| Key | Default | Description |
|
||||||
|
| --- | ---: | --- |
|
||||||
|
| `input_size` | `640` | Square YOLO input size; must be a multiple of 32 |
|
||||||
|
| `confidence` | `0.3` | Detection confidence threshold |
|
||||||
|
| `nms` | `0.45` | NMS IoU threshold |
|
||||||
|
| `max_detections` | `100` | Maximum detections retained after NMS |
|
||||||
|
| `mask_k_largest` | `0` | Keep only the largest K masks; zero keeps all |
|
||||||
|
| `mask_filter_method` | `area` | Rank retained masks by `area` or `confidence` |
|
||||||
|
| `mask_min_ratio` | `0` | Minimum bbox area relative to the image |
|
||||||
|
| `mask_max_ratio` | `1` | Maximum bbox area relative to the image |
|
||||||
|
| `dilate_erode` | `4` | Positive values dilate; negative values erode |
|
||||||
|
| `x_offset`, `y_offset` | `0` | Mask offset in pixels; positive Y moves upward |
|
||||||
|
| `mask_mode` | `none` | `none`, `merge`, or `merge_invert` |
|
||||||
|
| `merge_masks`, `invert_mask` | `false` | Boolean alternatives to `mask_mode` |
|
||||||
|
| `mask_blur` | `4` | Final composite feather radius |
|
||||||
|
| `inpaint_padding` | `32` | Padding around the detected region |
|
||||||
|
| `inpaint_only_masked` | `true` | Crop to the detected region; `false` uses the full image with the detection mask |
|
||||||
|
| `inpaint_width`, `inpaint_height` | mode-specific | `512x512` after generation; input/output size in `adetailer` mode |
|
||||||
|
| `denoising_strength` | mode-specific | `0.4` after generation; inherits `--strength` in `adetailer` mode |
|
||||||
|
| `steps` | `0` | Detail steps; zero inherits the main generation |
|
||||||
|
| `cfg_scale` | `-1` | Detail CFG; a negative value inherits the main generation |
|
||||||
|
| `sample_method` | inherited | Detail sampler name |
|
||||||
|
| `scheduler` | inherited | Detail scheduler name |
|
||||||
|
| `sort_by` | `none` | `none`, `left_to_right`, `center_to_edge`, or `area` |
|
||||||
|
|
||||||
|
Multiple masks are processed serially. Each completed inpaint becomes the input
|
||||||
|
for the next mask, and the seed is incremented by the mask index. Use
|
||||||
|
`mask_mode=merge` to process all detections in one inpaint pass.
|
||||||
|
|
||||||
|
The detector uses the `detector` backend module. For example, keep detection on
|
||||||
|
the CPU while diffusion runs on CUDA:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
--backend "diffusion=cuda0,detector=cpu"
|
||||||
|
```
|
||||||
21
docs/anima.md
Normal file
21
docs/anima.md
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
# How to Use
|
||||||
|
|
||||||
|
## Download weights
|
||||||
|
|
||||||
|
- Download Anima
|
||||||
|
- safetensors: https://huggingface.co/circlestone-labs/Anima/tree/main/split_files/diffusion_models
|
||||||
|
- gguf: https://huggingface.co/Bedovyy/Anima-GGUF/tree/main
|
||||||
|
- gguf Anima2: https://huggingface.co/JusteLeo/Anima2-GGUF/tree/main
|
||||||
|
- Download vae
|
||||||
|
- safetensors: https://huggingface.co/circlestone-labs/Anima/tree/main/split_files/vae
|
||||||
|
- Download Qwen3-0.6B-Base
|
||||||
|
- safetensors: https://huggingface.co/circlestone-labs/Anima/tree/main/split_files/text_encoders
|
||||||
|
- gguf: https://huggingface.co/mradermacher/Qwen3-0.6B-Base-GGUF/tree/main
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
```sh
|
||||||
|
.\bin\Release\sd-cli.exe --diffusion-model ..\models\diffusion_models\anima-preview.safetensors --vae ..\models\vae\qwen_image_vae.safetensors --llm ..\models\text_encoders\qwen_3_06b_base.safetensors -p "a lovely cat holding a sign says 'anima.cpp'" --cfg-scale 6.0 --sampling-method euler -v --offload-to-cpu
|
||||||
|
```
|
||||||
|
|
||||||
|
<img alt="anima image example" src="../assets/anima/example.png" />
|
||||||
171
docs/animatediff.md
Normal file
171
docs/animatediff.md
Normal file
|
|
@ -0,0 +1,171 @@
|
||||||
|
# AnimateDiff (SD 1.5)
|
||||||
|
|
||||||
|
AnimateDiff adds motion to a frozen Stable Diffusion 1.5 checkpoint by
|
||||||
|
injecting a temporal-attention module at 20 UNet slots. The base SD 1.5
|
||||||
|
model, VAE, and text encoder are unchanged; only the motion module produces
|
||||||
|
the temporal residual that turns a batch of independent frames into a
|
||||||
|
coherent animation. Reference: Guo et al., "AnimateDiff: Animate Your
|
||||||
|
Personalized Text-to-Image Diffusion Models without Specific Tuning"
|
||||||
|
(https://arxiv.org/abs/2307.04725).
|
||||||
|
|
||||||
|
## Download weights
|
||||||
|
|
||||||
|
- Motion module (v3, recommended)
|
||||||
|
- fp16 safetensors: https://huggingface.co/conrevo/AnimateDiff-A1111/resolve/main/motion_module/mm_sd15_v3.safetensors
|
||||||
|
- original checkpoint: https://huggingface.co/guoyww/animatediff/resolve/main/v3_sd15_mm.ckpt
|
||||||
|
- SD 1.5 base model
|
||||||
|
- any SD 1.5 checkpoint works. `realisticVisionV60B1` and `toonyou_beta3`
|
||||||
|
are the ones used in guoyww's reference configs.
|
||||||
|
- Domain Adapter LoRA (optional, v3 only, sharpens the base UNet's output
|
||||||
|
toward the motion module's trained distribution)
|
||||||
|
- ckpt: https://huggingface.co/guoyww/animatediff/resolve/main/v3_sd15_adapter.ckpt
|
||||||
|
- place under your `--lora-model-dir` and reference in the prompt as
|
||||||
|
`<lora:v3_sd15_adapter:1.0>`.
|
||||||
|
|
||||||
|
The motion module is `~836 MB` and loads alongside the SD 1.5 UNet via
|
||||||
|
`--motion-module`.
|
||||||
|
|
||||||
|
## Motion module versions
|
||||||
|
|
||||||
|
Per [animatediff.net/models](https://animatediff.net/models):
|
||||||
|
|
||||||
|
| Module | Base | Native res | Character |
|
||||||
|
|---------------------|------|------------|-----------|
|
||||||
|
| `mm_sd_v14.ckpt` | 1.5 | 256x256 | earliest, more jittery |
|
||||||
|
| `mm_sd_v15.ckpt` | 1.5 | 256x256 | improved stability over v1.4 |
|
||||||
|
| `mm_sd_v15_v2.ckpt` | 1.5 | 384x384 | significantly better motion dynamics |
|
||||||
|
| `v3_sd15_mm.ckpt` | 1.5 | 512x512 | smoothest, highest quality; pairs with a Domain Adapter LoRA |
|
||||||
|
| `mm_sdxl_v10_beta` | SDXL | 512x512 | experimental, not yet supported here |
|
||||||
|
|
||||||
|
Match your `-H -W` to the module's native resolution for best results. v3 is
|
||||||
|
trained at 512x512 - going smaller (e.g. 384x384) still works but the motion
|
||||||
|
character is closer to v2.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
Generate an 8-frame animation at 512x512, seed 42, 20 steps. The sampler /
|
||||||
|
scheduler / CFG values below match what mm_sd15_v3 was trained with; using
|
||||||
|
SD 1.5 defaults (euler_a, low CFG) produces noise-like output.
|
||||||
|
|
||||||
|
```
|
||||||
|
.\bin\Release\sd-cli.exe -M vid_gen \
|
||||||
|
--model ..\models\checkpoints\realisticVisionV60B1.safetensors \
|
||||||
|
--motion-module ..\models\animatediff\mm_sd15_v3.safetensors \
|
||||||
|
--offload-to-cpu \
|
||||||
|
-p "a red apple on a wooden table" \
|
||||||
|
--cfg-scale 8.0 --sampling-method euler --scheduler discrete \
|
||||||
|
-H 512 -W 512 --video-frames 8 --fps 8 --steps 20 -s 42 \
|
||||||
|
-o out.avi
|
||||||
|
```
|
||||||
|
|
||||||
|
Generate at the motion module's native 16-frame context (recommended for
|
||||||
|
best temporal quality). Needs more VRAM at 512x512, so drop to 384x384 or
|
||||||
|
use layer streaming:
|
||||||
|
|
||||||
|
```
|
||||||
|
.\bin\Release\sd-cli.exe -M vid_gen \
|
||||||
|
--model ..\models\checkpoints\realisticVisionV60B1.safetensors \
|
||||||
|
--motion-module ..\models\animatediff\mm_sd15_v3.safetensors \
|
||||||
|
--offload-to-cpu \
|
||||||
|
-p "photo of coastline, rocks, storm weather, wind, waves, lightning" \
|
||||||
|
--cfg-scale 8.0 --sampling-method euler --scheduler discrete \
|
||||||
|
-H 384 -W 384 --video-frames 16 --fps 8 --steps 20 -s 42 \
|
||||||
|
-o out.avi
|
||||||
|
```
|
||||||
|
|
||||||
|
Low-VRAM streaming (verified with a 2 GiB cap on RTX 3060):
|
||||||
|
|
||||||
|
```
|
||||||
|
.\bin\Release\sd-cli.exe -M vid_gen \
|
||||||
|
--model ..\models\checkpoints\realisticVisionV60B1.safetensors \
|
||||||
|
--motion-module ..\models\animatediff\mm_sd15_v3.safetensors \
|
||||||
|
--max-vram 2.0 \
|
||||||
|
-p "photo of coastline, rocks, storm weather, wind, waves, lightning" \
|
||||||
|
--cfg-scale 8.0 --sampling-method euler --scheduler discrete \
|
||||||
|
-H 384 -W 384 --video-frames 8 --fps 8 --steps 20 -s 42 \
|
||||||
|
-o out.avi
|
||||||
|
```
|
||||||
|
|
||||||
|
## Reference-quality reproduction
|
||||||
|
|
||||||
|
Using guoyww's official reference configs on this impl (RealisticVision v6.0
|
||||||
|
base + `mm_sd15_v3` or `mm_sd_v15_v2` + native resolution + 16 frames + euler
|
||||||
|
+ 25 steps + CFG 8 + linear beta schedule) reproduces the reference
|
||||||
|
AnimateDiff output style.
|
||||||
|
|
||||||
|
### v3 (512x512, `mm_sd15_v3`)
|
||||||
|
|
||||||
|
| Prompt | Sample |
|
||||||
|
|---------------------------------------|--------|
|
||||||
|
| B&W man on stormy coastline | <img src="../assets/animatediff/v3_man.gif" width="256"/> |
|
||||||
|
| Close-up rabbit macro shot | <img src="../assets/animatediff/v3_rabbit.gif" width="256"/> |
|
||||||
|
| Coastline, storm, waves, lightning | <img src="../assets/animatediff/v3_coast.gif" width="256"/> |
|
||||||
|
| Old house, storm, forest, night | <img src="../assets/animatediff/v3_house.gif" width="256"/> |
|
||||||
|
|
||||||
|
### v2 (384x384, `mm_sd_v15_v2.ckpt`)
|
||||||
|
|
||||||
|
| Prompt | Sample |
|
||||||
|
|---------------------------------------|--------|
|
||||||
|
| B&W man on stormy coastline | <img src="../assets/animatediff/v2_man.gif" width="256"/> |
|
||||||
|
| Close-up rabbit macro shot | <img src="../assets/animatediff/v2_rabbit.gif" width="256"/> |
|
||||||
|
| Coastline, storm, waves, lightning | <img src="../assets/animatediff/v2_coast.gif" width="256"/> |
|
||||||
|
| Old house, storm, forest, night | <img src="../assets/animatediff/v2_house.gif" width="256"/> |
|
||||||
|
|
||||||
|
Motion is strong for scenes with motion cues in the prompt (storm/waves/wind)
|
||||||
|
and subtle for static subjects (close-up macro), matching reference behavior.
|
||||||
|
v2 has an additional motion module at the UNet middle block that v3 dropped;
|
||||||
|
this impl auto-detects the topology from the checkpoint.
|
||||||
|
|
||||||
|
### v3 + Domain Adapter LoRA
|
||||||
|
|
||||||
|
Attaching the `v3_sd15_adapter` LoRA sharpens the base UNet output toward
|
||||||
|
the training distribution the motion module was fine-tuned against. Same
|
||||||
|
prompt, seed, config as above:
|
||||||
|
|
||||||
|
<img src="../assets/animatediff/v3_rabbit_domain_lora.gif" width="256"/>
|
||||||
|
|
||||||
|
Individual fur strands, glowing inner-ear, and richer forest detail become
|
||||||
|
visible compared to the no-LoRA rendering.
|
||||||
|
|
||||||
|
```
|
||||||
|
sd-cli -M vid_gen --model realisticVisionV60B1.safetensors \
|
||||||
|
--motion-module mm_sd15_v3.safetensors \
|
||||||
|
--lora-model-dir ./loras \
|
||||||
|
-p "close up photo of a rabbit ...<lora:v3_sd15_adapter:1.0>" ...
|
||||||
|
```
|
||||||
|
|
||||||
|
## img2video
|
||||||
|
|
||||||
|
Pass a pre-rendered image via `-i / --init-img` to animate FROM it. All N output frames start from the encoded init latent, then per-frame noise is added at `--strength`. Character identity, composition, and quality are anchored by the init image; the motion module adds subtle motion on top.
|
||||||
|
|
||||||
|
Left: init image rendered with `-M img_gen`. Right: 8-frame vid_gen output.
|
||||||
|
|
||||||
|
<img src="../assets/animatediff/img2video_demo.gif" width="512"/>
|
||||||
|
|
||||||
|
```
|
||||||
|
sd-cli -M img_gen ... -o init.png # any high-quality still
|
||||||
|
sd-cli -M vid_gen --motion-module mm_sd15_v3.safetensors \
|
||||||
|
-i init.png --strength 0.75 \
|
||||||
|
--cfg-scale 7.0 --sampling-method euler --scheduler karras \
|
||||||
|
-H 512 -W 512 --video-frames 8 --steps 25 -s 42 \
|
||||||
|
-p "..." -o out.avi
|
||||||
|
```
|
||||||
|
|
||||||
|
`--strength` controls how far the motion module is allowed to deviate from the init image (higher = more motion, lower = more static).
|
||||||
|
|
||||||
|
## Notes
|
||||||
|
|
||||||
|
- The motion module was trained at `video_length=16`. Running with
|
||||||
|
`--video-frames 16` gives the best coherence; F=8 works but shows a shorter
|
||||||
|
motion arc. Frame counts up to 32 are supported by the positional encoding
|
||||||
|
but exceed the trained regime and produce more static output.
|
||||||
|
- At `--video-frames 1` the motion module is skipped entirely and the output
|
||||||
|
is bit-identical to `-M img_gen`. This avoids the single-token
|
||||||
|
temporal-attention degeneracy that would otherwise emit an untrained-magnitude
|
||||||
|
residual on a single-frame sample.
|
||||||
|
- The base UNet is frozen, so character identity and style follow the SD 1.5
|
||||||
|
checkpoint you pass to `--model`. LoRAs and prompt weighting attach to the
|
||||||
|
base model in the usual way.
|
||||||
|
- No mid_block motion module in v3. `mm_sdxl_v10_beta` (SDXL variant) is not
|
||||||
|
supported yet.
|
||||||
|
- Output is written as MJPEG AVI. Use `--fps` to set playback speed.
|
||||||
|
|
@ -1,9 +1,5 @@
|
||||||
# Backend selection
|
# Backend selection
|
||||||
|
|
||||||
DGL versions of the generation examples are linked below. Edit each script's
|
|
||||||
`var` block and follow the [DGL run instructions](../dgl/README.md).
|
|
||||||
|
|
||||||
|
|
||||||
`stable-diffusion.cpp` has two backend assignments:
|
`stable-diffusion.cpp` has two backend assignments:
|
||||||
|
|
||||||
- `--backend` selects the runtime backend used to execute model graphs.
|
- `--backend` selects the runtime backend used to execute model graphs.
|
||||||
|
|
@ -20,7 +16,6 @@ A backend assignment can be a single backend name:
|
||||||
sd-cli -m model.safetensors -p "a cat" --backend cpu
|
sd-cli -m model.safetensors -p "a cat" --backend cpu
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
This applies to every module that does not have a more specific assignment.
|
This applies to every module that does not have a more specific assignment.
|
||||||
|
|
||||||
Assignments can also target individual modules:
|
Assignments can also target individual modules:
|
||||||
|
|
@ -29,28 +24,24 @@ Assignments can also target individual modules:
|
||||||
sd-cli -m model.safetensors -p "a cat" --backend te=cpu,vae=cuda0,diffusion=vulkan0
|
sd-cli -m model.safetensors -p "a cat" --backend te=cpu,vae=cuda0,diffusion=vulkan0
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
The same syntax is used for parameter placement:
|
The same syntax is used for parameter placement:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
sd-cli -m model.safetensors -p "a cat" --backend cuda0 --params-backend te=cpu,vae=cpu
|
sd-cli -m model.safetensors -p "a cat" --backend cuda0 --params-backend te=cpu,vae=cpu
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
`--params-backend` also accepts the special value `disk`:
|
`--params-backend` also accepts the special value `disk`:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
sd-cli -m model.safetensors -p "a cat" --backend cuda0 --params-backend disk
|
sd-cli -m model.safetensors -p "a cat" --backend cuda0 --params-backend disk
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
`--max-vram` can target resolved backend/device names:
|
`--max-vram` can target resolved backend/device names:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
sd-cli -m model.safetensors -p "a cat" --backend diffusion=cuda0,vae=vulkan0 --max-vram cuda0=6,vulkan0=2
|
sd-cli -m model.safetensors -p "a cat" --backend diffusion=cuda0,vae=vulkan0 --max-vram cuda0=6,vulkan0=2
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
The value is a shared per-device budget for managed weights and registered
|
The value is a shared per-device budget for managed weights and registered
|
||||||
runner compute/cache buffers. Live free memory can lower the effective limit
|
runner compute/cache buffers. Live free memory can lower the effective limit
|
||||||
for each graph run. Driver contexts and allocations made outside the managed
|
for each graph run. Driver contexts and allocations made outside the managed
|
||||||
|
|
@ -65,7 +56,6 @@ Module names are case-insensitive. Hyphens and underscores in module names are i
|
||||||
sd-cli -m model.safetensors -p "a cat" --backend all=cuda0,te=cpu
|
sd-cli -m model.safetensors -p "a cat" --backend all=cuda0,te=cpu
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Multiple devices per module (layer split)
|
## Multiple devices per module (layer split)
|
||||||
|
|
||||||
A `--backend` module assignment can list several devices separated by `&`:
|
A `--backend` module assignment can list several devices separated by `&`:
|
||||||
|
|
@ -74,7 +64,6 @@ A `--backend` module assignment can list several devices separated by `&`:
|
||||||
sd-cli -m model.safetensors -p "a cat" --backend "diffusion=cuda0&cuda1"
|
sd-cli -m model.safetensors -p "a cat" --backend "diffusion=cuda0&cuda1"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
The module's transformer blocks are then distributed across the listed devices
|
The module's transformer blocks are then distributed across the listed devices
|
||||||
in contiguous ranges sized proportionally to each device's free memory (minus a
|
in contiguous ranges sized proportionally to each device's free memory (minus a
|
||||||
compute-buffer headroom of about 2 GiB per device), and the
|
compute-buffer headroom of about 2 GiB per device), and the
|
||||||
|
|
@ -113,7 +102,6 @@ sd-cli -m model.safetensors -p "a cat" --backend "diffusion=cuda0&cuda1" --split
|
||||||
sd-cli -m model.safetensors -p "a cat" --backend "diffusion=cuda0&cuda1,te=cuda0&cuda1" --split-mode diffusion=row,te=layer
|
sd-cli -m model.safetensors -p "a cat" --backend "diffusion=cuda0&cuda1,te=cuda0&cuda1" --split-mode diffusion=row,te=layer
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
In row mode the module keeps executing on its main (first listed) device, but
|
In row mode the module keeps executing on its main (first listed) device, but
|
||||||
its transformer-block matmul weights are allocated in the backend's row-split
|
its transformer-block matmul weights are allocated in the backend's row-split
|
||||||
buffer type, which slices each weight's rows across the listed devices in
|
buffer type, which slices each weight's rows across the listed devices in
|
||||||
|
|
@ -147,10 +135,7 @@ regardless of argument order, even with `--auto-fit on`.
|
||||||
|
|
||||||
Auto-fit preserves explicit `--backend` assignments, including per-module
|
Auto-fit preserves explicit `--backend` assignments, including per-module
|
||||||
assignments and device lists. For modules without a runtime assignment, it chooses
|
assignments and device lists. For modules without a runtime assignment, it chooses
|
||||||
the discrete GPU with the largest positive memory budget (the first device on a
|
the GPU with the largest available memory budget (the first device on a tie).
|
||||||
tie), falling back to integrated GPUs when no discrete GPU has a positive budget.
|
|
||||||
An integrated GPU's shared system memory does not give it priority over a discrete
|
|
||||||
GPU. Explicit assignments such as `--backend Vulkan1` still select that device.
|
|
||||||
It then derives parameter placements from the model metadata, each module's
|
It then derives parameter placements from the model metadata, each module's
|
||||||
compute devices, and the remaining memory budgets. The chosen backend
|
compute devices, and the remaining memory budgets. The chosen backend
|
||||||
specifications are printed.
|
specifications are printed.
|
||||||
|
|
@ -163,7 +148,6 @@ sd-cli -m model.safetensors -p "a cat" --backend diffusion=cuda0,te=cpu,vae=cuda
|
||||||
sd-cli -m model.safetensors -p "a cat" --auto-fit off
|
sd-cli -m model.safetensors -p "a cat" --auto-fit off
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
Budgets reuse `--max-vram`: a positive per-device value caps what auto-fit
|
Budgets reuse `--max-vram`: a positive per-device value caps what auto-fit
|
||||||
plans with on that device, a negative value means "free memory minus that many
|
plans with on that device, a negative value means "free memory minus that many
|
||||||
GiB", and with no budget set each device's free memory minus a 512 MiB margin
|
GiB", and with no budget set each device's free memory minus a 512 MiB margin
|
||||||
|
|
@ -173,12 +157,10 @@ the runner's graph-cut capacity checks.
|
||||||
Runtime capacity checks also leave 512 MiB of currently free device memory for
|
Runtime capacity checks also leave 512 MiB of currently free device memory for
|
||||||
backend scratch buffers and pipelines, including with explicit backend assignments.
|
backend scratch buffers and pipelines, including with explicit backend assignments.
|
||||||
They cap free-memory reports by the device's total memory minus tracked
|
They cap free-memory reports by the device's total memory minus tracked
|
||||||
resident allocations. Vulkan reports exceeding total memory are rejected on
|
resident allocations. Vulkan reports exceeding total memory are rejected because
|
||||||
discrete GPUs because its heap-budget subtraction can underflow. On integrated
|
its heap-budget subtraction can underflow. Other backends use the cap instead of
|
||||||
GPUs, a wrapped report triggers reclamation before the tracked estimate can be
|
treating such reports as zero free memory. Failed checks log the reported free and
|
||||||
accepted, subject to the byte checks and configured budgets. Other backends use
|
total memory alongside tracked weight and runtime allocations.
|
||||||
the cap instead of treating such reports as zero free memory. Failed checks log
|
|
||||||
the reported free and total memory alongside tracked weight and runtime allocations.
|
|
||||||
With `--mmap`, device-backed mappings count toward these budgets at their full
|
With `--mmap`, device-backed mappings count toward these budgets at their full
|
||||||
mapped-file size, once per device buffer even when multiple parameter blocks
|
mapped-file size, once per device buffer even when multiple parameter blocks
|
||||||
share it. Mappings retained in the loader cache continue to count.
|
share it. Mappings retained in the loader cache continue to count.
|
||||||
|
|
@ -196,18 +178,8 @@ GPU cache space follows the same component priority. Before a lower-priority
|
||||||
component can become permanently resident, the planner leaves room for the full
|
component can become permanently resident, the planner leaves room for the full
|
||||||
weights and estimated compute space of higher-priority offloaded components.
|
weights and estimated compute space of higher-priority offloaded components.
|
||||||
If offloaded diffusion already needs the entire main GPU budget, TE and VAE also
|
If offloaded diffusion already needs the entire main GPU budget, TE and VAE also
|
||||||
use offloaded parameters. GPU copies remain cached across sampling steps while
|
use offloaded parameters. Their GPU copies can then be released after their
|
||||||
a component's execution is active and are released under memory pressure.
|
phases, leaving more room to reuse diffusion weights across sampling steps.
|
||||||
Ending a component's execution releases its staged GPU copies, disk-backed
|
|
||||||
weight buffers, temporary compute buffers and execution caches. Parameters
|
|
||||||
assigned permanently to a backend remain resident. Hires model upscaling shares
|
|
||||||
the runtime budget and can
|
|
||||||
reclaim idle weight copies from other components.
|
|
||||||
Reclamation releases idle compute buffers first, then cached weight allocations
|
|
||||||
until the current work fits. Weights used by active computation or pending
|
|
||||||
transfers stay protected.
|
|
||||||
For CPU computation with disk-backed parameters, cached weights are released
|
|
||||||
when execution ends so they do not accumulate in RAM across components.
|
|
||||||
CPU parameter residency allows GPU weight caching; it does not force every
|
CPU parameter residency allows GPU weight caching; it does not force every
|
||||||
weight to be copied again at every step.
|
weight to be copied again at every step.
|
||||||
|
|
||||||
|
|
@ -254,7 +226,6 @@ sd-cli -m model.safetensors -p "a cat" --conv-direct auto,vae=off
|
||||||
sd-cli -m model.safetensors -p "a cat" --conv-direct off,diffusion=on
|
sd-cli -m model.safetensors -p "a cat" --conv-direct off,diffusion=on
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
- `on` requests direct 2D and 3D convolution.
|
- `on` requests direct 2D and 3D convolution.
|
||||||
- `off` uses the existing im2col-based convolution paths.
|
- `off` uses the existing im2col-based convolution paths.
|
||||||
- `auto` first checks support for a representative F16-weight/F32-input direct
|
- `auto` first checks support for a representative F16-weight/F32-input direct
|
||||||
|
|
@ -276,9 +247,6 @@ These are backend-level defaults. GGML still chooses the actual kernel based on
|
||||||
weight type, shape, and hardware; enabling direct convolution does not guarantee
|
weight type, shape, and hardware; enabling direct convolution does not guarantee
|
||||||
that every operation uses implicit GEMM. The CUDA-family implicit GEMM paths
|
that every operation uses implicit GEMM. The CUDA-family implicit GEMM paths
|
||||||
require F16 weights and can use ordinary direct kernels for other cases.
|
require F16 weights and can use ordinary direct kernels for other cases.
|
||||||
For 3D convolution, a supported direct kernel is also used as a fallback when
|
|
||||||
the im2col decomposition is unsupported for the actual tensor sizes, including
|
|
||||||
when an intermediate reshape or matrix multiplication exceeds backend limits.
|
|
||||||
This option does not change the separately created image upscaler context.
|
This option does not change the separately created image upscaler context.
|
||||||
|
|
||||||
Repeating `--conv-direct` replaces the previous assignment string. Existing
|
Repeating `--conv-direct` replaces the previous assignment string. Existing
|
||||||
|
|
@ -287,8 +255,8 @@ flags are deprecated and emit a warning, but remain supported when
|
||||||
`--conv-direct` is omitted. Use `--conv-direct auto,diffusion=on,controlnet=on`
|
`--conv-direct` is omitted. Use `--conv-direct auto,diffusion=on,controlnet=on`
|
||||||
and `--conv-direct auto,vae=on`, respectively. An explicit
|
and `--conv-direct auto,vae=on`, respectively. An explicit
|
||||||
`--conv-direct` takes precedence over both legacy flags regardless of order.
|
`--conv-direct` takes precedence over both legacy flags regardless of order.
|
||||||
Library callers can set the `conv_direct_mode` context-option key with
|
Library callers can set the appended `sd_ctx_params_t::conv_direct_mode` field
|
||||||
`sd_opt_set_string()` to the same string; unset or empty selects `auto` while honoring legacy true
|
to the same string; null or empty selects `auto` while honoring legacy true
|
||||||
flags. The context copies the string.
|
flags. The context copies the string.
|
||||||
|
|
||||||
## Flash attention (`--flash-attn on|off|auto`)
|
## Flash attention (`--flash-attn on|off|auto`)
|
||||||
|
|
@ -305,7 +273,6 @@ sd-cli -m model.safetensors -p "a cat" --flash-attn auto,te=off,vae=on
|
||||||
sd-cli -m model.safetensors -p "a cat" --flash-attn off,diffusion=auto
|
sd-cli -m model.safetensors -p "a cat" --flash-attn off,diffusion=auto
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
Supported modules are `diffusion`, `te`, `clip_vision`, `vae`, `controlnet`, and
|
Supported modules are `diffusion`, `te`, `clip_vision`, `vae`, `controlnet`, and
|
||||||
`audio_encoder`. Modules without an assignment use the default (`auto` if no
|
`audio_encoder`. Modules without an assignment use the default (`auto` if no
|
||||||
default is supplied). A bare mode or `all=`, `default=`, or `*=` sets the default;
|
default is supplied). A bare mode or `all=`, `default=`, or `*=` sets the default;
|
||||||
|
|
@ -354,10 +321,9 @@ row-split configurations, which can fall back to layer split during initializati
|
||||||
Use `--flash-attn on` and `--flash-attn off,diffusion=on`, respectively.
|
Use `--flash-attn on` and `--flash-attn off,diffusion=on`, respectively.
|
||||||
Both aliases write the same mode string as `--flash-attn`; the last occurrence
|
Both aliases write the same mode string as `--flash-attn`; the last occurrence
|
||||||
of any of these options wins. Library callers
|
of any of these options wins. Library callers
|
||||||
can set the `flash_attn_mode` context-option key with `sd_opt_set_string()`
|
can set `sd_ctx_params_t::flash_attn_mode` to the same string, including
|
||||||
to the same string, including
|
|
||||||
`"on"`, `"off"`, `"auto"`, or `"auto,te=off,vae=on"`.
|
`"on"`, `"off"`, `"auto"`, or `"auto,te=off,vae=on"`.
|
||||||
An unset or empty string uses automatic selection unless a
|
A null or empty string uses automatic selection unless a
|
||||||
legacy `flash_attn` or `diffusion_flash_attn` boolean is set. The context copies
|
legacy `flash_attn` or `diffusion_flash_attn` boolean is set. The context copies
|
||||||
the string; no new enum is required.
|
the string; no new enum is required.
|
||||||
|
|
||||||
|
|
@ -366,7 +332,6 @@ sd-cli -m model.safetensors -p "a cat" --flash-attn auto
|
||||||
sd-cli -m model.safetensors -p "a cat" --flash-attn off
|
sd-cli -m model.safetensors -p "a cat" --flash-attn off
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
## Modules
|
## Modules
|
||||||
|
|
||||||
| Module | Purpose | Accepted names |
|
| Module | Purpose | Accepted names |
|
||||||
|
|
@ -407,7 +372,6 @@ For example:
|
||||||
sd-cli -m model.safetensors -p "a cat" --backend cuda0 --params-backend cpu
|
sd-cli -m model.safetensors -p "a cat" --backend cuda0 --params-backend cpu
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
This runs all modules on `cuda0`, but stores parameters in CPU RAM. During execution, parameters are moved to the runtime backend as needed.
|
This runs all modules on `cuda0`, but stores parameters in CPU RAM. During execution, parameters are moved to the runtime backend as needed.
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
@ -416,7 +380,6 @@ For example:
|
||||||
sd-cli -m model.safetensors -p "a cat" --backend cuda0 --params-backend disk
|
sd-cli -m model.safetensors -p "a cat" --backend cuda0 --params-backend disk
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
This runs all modules on `cuda0`, reloads parameters from the model file as needed, and releases those parameter buffers after use.
|
This runs all modules on `cuda0`, reloads parameters from the model file as needed, and releases those parameter buffers after use.
|
||||||
|
|
||||||
Outside `--auto-fit`, `disk` is never selected implicitly. If `--params-backend` is not set, parameters use the runtime backend.
|
Outside `--auto-fit`, `disk` is never selected implicitly. If `--params-backend` is not set, parameters use the runtime backend.
|
||||||
|
|
@ -427,7 +390,6 @@ Per-module assignments can be mixed:
|
||||||
sd-cli -m model.safetensors -p "a cat" --backend diffusion=cuda0,te=cpu,vae=cpu --params-backend diffusion=cuda0,te=cpu,vae=cpu
|
sd-cli -m model.safetensors -p "a cat" --backend diffusion=cuda0,te=cpu,vae=cpu --params-backend diffusion=cuda0,te=cpu,vae=cpu
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
This keeps text encoding and VAE execution on CPU while the diffusion model runs on GPU.
|
This keeps text encoding and VAE execution on CPU while the diffusion model runs on GPU.
|
||||||
|
|
||||||
## Backend sharing and lifetime
|
## Backend sharing and lifetime
|
||||||
|
|
@ -37,13 +37,10 @@ measurement pair; it cannot interrupt an in-flight backend operation.
|
||||||
Only use `candidate_faster` when `completed` is true. On incomplete probes,
|
Only use `candidate_faster` when `completed` is true. On incomplete probes,
|
||||||
`error` reports why comparison failed and the timing totals may be partial.
|
`error` reports why comparison failed and the timing totals may be partial.
|
||||||
The caller handles logging, known architecture rules, fallback policy, and
|
The caller handles logging, known architecture rules, fallback policy, and
|
||||||
context-lifetime caching. DGL uses one `BackendProbeCache` shared by all models
|
context-lifetime caching. Keep caches separate by operation (or key a shared
|
||||||
in an execution context, including LoRA variants and models loaded by later
|
cache by both operation and backend); an attention result must not select a
|
||||||
programs. It caches both enabled and disabled decisions by operation and compute
|
convolution implementation. If shapes or settings vary within one context,
|
||||||
backend; CPU attention additionally keys the effective thread count. GPU results
|
include them in the corresponding cache key as well.
|
||||||
survive changes to the context's thread count. The cache serializes first-time
|
|
||||||
probes and their decision logs. Explicit operator `on` and `off` bypass the cache.
|
|
||||||
If probe shapes or other relevant settings become variable, add them to the key.
|
|
||||||
|
|
||||||
Convolution results are cached separately for 2D and 3D, once per compute backend
|
Convolution results are cached separately for 2D and 3D, once per compute backend
|
||||||
in the context, just like attention results. Each probe logs its backend, decision,
|
in the context, just like attention results. Each probe logs its backend, decision,
|
||||||
31
docs/boogu_image.md
Normal file
31
docs/boogu_image.md
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
# How to Use
|
||||||
|
|
||||||
|
Boogu Image uses a Boogu diffusion transformer, the FLUX VAE, and Qwen3-VL as the LLM text and vision encoder.
|
||||||
|
|
||||||
|
## Download weights
|
||||||
|
|
||||||
|
- Download Boogu Image
|
||||||
|
- safetensors: https://huggingface.co/Comfy-Org/Boogu-Image/tree/main/diffusion_models
|
||||||
|
- Download vae
|
||||||
|
- safetensors: https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/ae.safetensors
|
||||||
|
- Download Qwen3-VL 8B
|
||||||
|
- gguf: https://huggingface.co/unsloth/Qwen3-VL-8B-Instruct-GGUF/tree/main
|
||||||
|
- For image editing with GGUF text encoders, also download the matching mmproj file and pass it with `--llm_vision`.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
### Boogu Image Base
|
||||||
|
|
||||||
|
```
|
||||||
|
.\bin\Release\sd-cli.exe --diffusion-model ..\models\diffusion_models\boogu_image_base_bf16.safetensors --llm ..\models\text_encoders\Qwen3VL-8B-Instruct-Q4_K_M.gguf --vae ..\models\vae\ae.sft -p "a lovely cat" -v --offload-to-cpu
|
||||||
|
```
|
||||||
|
|
||||||
|
<img width="256" alt="Boogu Image Base example" src="../assets/boogu/example.png" />
|
||||||
|
|
||||||
|
### Boogu Image Edit
|
||||||
|
|
||||||
|
```
|
||||||
|
.\bin\Release\sd-cli.exe --diffusion-model ..\models\diffusion_models\boogu_image_edit_bf16.safetensors --llm ..\models\text_encoders\Qwen3VL-8B-Instruct-Q4_K_M.gguf --llm_vision ..\models\text_encoders\mmproj-Qwen3VL-8B-Instruct-F16.gguf --vae ..\models\vae\ae.sft -v --offload-to-cpu -r ..\assets\flux\flux1-dev-q8_0.png -p "change 'flux.cpp' to 'boogu.cpp'"
|
||||||
|
```
|
||||||
|
|
||||||
|
<img width="256" alt="Boogu Image Edit example" src="../assets/boogu/edit_example.png" />
|
||||||
254
docs/build.md
254
docs/build.md
|
|
@ -2,23 +2,18 @@
|
||||||
|
|
||||||
## Get the Code
|
## Get the Code
|
||||||
|
|
||||||
```shell
|
```
|
||||||
git clone --recursive https://github.com/leejet/stable-diffusion.cpp
|
git clone --recursive https://github.com/leejet/stable-diffusion.cpp
|
||||||
cd stable-diffusion.cpp
|
cd stable-diffusion.cpp
|
||||||
```
|
```
|
||||||
|
|
||||||
If you already cloned the repository without submodules, initialize them from the repository root:
|
- If you have already cloned the repository, you can use the following command to update the repository to the latest code.
|
||||||
|
|
||||||
```shell
|
|
||||||
git submodule update --init --recursive
|
|
||||||
```
|
```
|
||||||
|
|
||||||
To update an existing checkout and its submodules:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
cd stable-diffusion.cpp
|
cd stable-diffusion.cpp
|
||||||
git pull origin master
|
git pull origin master
|
||||||
git submodule update --init --recursive
|
git submodule init
|
||||||
|
git submodule update
|
||||||
```
|
```
|
||||||
|
|
||||||
## Selecting a GGML source tree
|
## Selecting a GGML source tree
|
||||||
|
|
@ -32,10 +27,8 @@ cmake -S . -B build-upstream -DSD_USE_UPSTREAM_GGML=ON -DSD_GGML_SOURCE_DIR=../g
|
||||||
cmake --build build-upstream --config Release
|
cmake --build build-upstream --config Release
|
||||||
```
|
```
|
||||||
|
|
||||||
Upstream compatibility mode uses the selected library and matching private
|
The selected source tree supplies both the library and its private headers.
|
||||||
headers. The patched GGML build uses public headers, including `ggml-ext.h` and
|
Backend options such as `-DSD_CUDA=ON` apply to the selected tree as usual.
|
||||||
`ggml-graph.h`. Backend options such as `-DSD_CUDA=ON` apply to the selected tree
|
|
||||||
as usual.
|
|
||||||
|
|
||||||
`SD_USE_UPSTREAM_GGML` defaults to `OFF`, which enables the patched GGML
|
`SD_USE_UPSTREAM_GGML` defaults to `OFF`, which enables the patched GGML
|
||||||
extensions. Set it to `ON` when using upstream GGML; it selects the compatibility
|
extensions. Set it to `ON` when using upstream GGML; it selects the compatibility
|
||||||
|
|
@ -52,29 +45,14 @@ creating an inference context. Ordinary floating-point and shared GGML
|
||||||
quantization types remain available, subject to backend operator support.
|
quantization types remain available, subject to backend operator support.
|
||||||
|
|
||||||
`SD_USE_SYSTEM_GGML=ON` instead links an installed GGML CMake package, located
|
`SD_USE_SYSTEM_GGML=ON` instead links an installed GGML CMake package, located
|
||||||
with `ggml_DIR` or `CMAKE_PREFIX_PATH`. An installed patched package must include
|
with `ggml_DIR` or `CMAKE_PREFIX_PATH`. In that mode, `SD_GGML_SOURCE_DIR` must
|
||||||
the extension and graph APIs; its source tree is not required for private
|
point to the matching source tree for private headers. The installed library
|
||||||
headers. The installed library must use the same ABI settings as sd.cpp,
|
must use the same ABI settings as sd.cpp, including `GGML_MAX_NAME`.
|
||||||
including `GGML_MAX_NAME`. For an upstream package, also set
|
Set `SD_USE_UPSTREAM_GGML=ON` as well if the installed package is upstream GGML.
|
||||||
`SD_USE_UPSTREAM_GGML=ON` and point `SD_GGML_SOURCE_DIR` to its matching source
|
|
||||||
tree for the compatibility layer's private headers.
|
|
||||||
|
|
||||||
## WebP and WebM Support
|
## WebP and WebM Support in Examples
|
||||||
|
|
||||||
WebP and WebM support are enabled by default. The library links `libwebp`,
|
The example applications (`examples/cli` and `examples/server`) use `libwebp` to support WebP image I/O, and `examples/cli` can also use `libwebm` for `.webm` video output. Both are enabled by default. WebM output currently reuses `libwebp` to encode each frame as VP8 before muxing with `libwebm`.
|
||||||
`libwebpdemux` and `libwebm` so DGL `video::load` works through the C API as
|
|
||||||
well as CLI and server. WebP input supports static images and animation;
|
|
||||||
WebM input supports this project's independent VP8 frames and PCM16 audio.
|
|
||||||
No libvpx dependency is required. See [DGL media I/O](dgl.md) for frame-rate
|
|
||||||
and codec restrictions.
|
|
||||||
|
|
||||||
The CLI and server also use `libwebp` for WebP images. CLI WebM output reuses
|
|
||||||
`libwebp` to encode each frame as VP8 before muxing with `libwebm`. System WebP
|
|
||||||
packages must provide the decoder, demuxer and muxer libraries.
|
|
||||||
|
|
||||||
DGL `video::encode` supports silent WebM and AVI with PCM16 audio. Requesting
|
|
||||||
WebM audio reports an unsupported-encoder error; use `format="avi"` to include
|
|
||||||
an audio track.
|
|
||||||
|
|
||||||
If you do not want WebP/WebM support, you can disable them at configure time:
|
If you do not want WebP/WebM support, you can disable them at configure time:
|
||||||
|
|
||||||
|
|
@ -112,9 +90,9 @@ cmake --build . --config Release
|
||||||
|
|
||||||
## Build with CUDA
|
## Build with CUDA
|
||||||
|
|
||||||
The sd.cpp SageAttention extension is included when using CUDA with patched
|
Native SageAttention is included when using CUDA with patched GGML
|
||||||
GGML (`SD_USE_UPSTREAM_GGML=OFF`).
|
(`SD_USE_UPSTREAM_GGML=OFF`).
|
||||||
See [SageAttention](guides/sage_attention.md) for GPU requirements and `--sage-attn` usage.
|
See [SageAttention](sage_attention.md) for GPU requirements and `--sage-attn` usage.
|
||||||
|
|
||||||
This provides GPU acceleration using NVIDIA GPU. Make sure to have the CUDA toolkit installed. You can download it from your Linux distro's package manager (e.g. `apt install nvidia-cuda-toolkit`) or from here: [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads). Recommended to have at least 4 GB of VRAM.
|
This provides GPU acceleration using NVIDIA GPU. Make sure to have the CUDA toolkit installed. You can download it from your Linux distro's package manager (e.g. `apt install nvidia-cuda-toolkit`) or from here: [CUDA Toolkit](https://developer.nvidia.com/cuda-downloads). Recommended to have at least 4 GB of VRAM.
|
||||||
|
|
||||||
|
|
@ -124,110 +102,21 @@ cmake .. -DSD_CUDA=ON
|
||||||
cmake --build . --config Release
|
cmake --build . --config Release
|
||||||
```
|
```
|
||||||
|
|
||||||
When building GGML from source, sd.cpp's CUDA extensions use the same target
|
## Build with HipBLAS
|
||||||
architectures as GGML, including native GPU detection with `GGML_NATIVE=ON`.
|
|
||||||
To select target GPUs explicitly, pass `-DCMAKE_CUDA_ARCHITECTURES=89` (Ada),
|
|
||||||
for example, or a quoted list such as `-DCMAKE_CUDA_ARCHITECTURES="80;89"`.
|
|
||||||
|
|
||||||
CUDA extensions use sd.cpp's `thirdparty/cutlass` submodule by default
|
This provides GPU acceleration using AMD GPU. Make sure to have the ROCm toolkit installed.
|
||||||
for eligible INT8 GEMM and CuTe attention operations. If its headers are missing,
|
To build for another GPU architecture than installed in your system, set `$GFX_NAME` manually to the desired architecture (replace first command). This is also necessary if your GPU is not officially supported by ROCm, for example you have to set `$GFX_NAME` manually to `gfx1030` for consumer RDNA2 cards.
|
||||||
CMake stops with an initialization hint; it does not download them automatically.
|
|
||||||
Run `git submodule update --init --recursive` from the repository root before
|
|
||||||
configuring.
|
|
||||||
|
|
||||||
To build with the existing CUDA implementations without CUTLASS, configure from
|
Windows User Refer to [docs/hipBLAS_on_Windows.md](docs%2FhipBLAS_on_Windows.md) for a comprehensive guide.
|
||||||
the repository root with:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
cmake -S . -B build -DSD_CUDA=ON -DSD_CUDA_CUTLASS_PATH:PATH=
|
|
||||||
cmake --build build --config Release
|
|
||||||
```
|
|
||||||
|
|
||||||
Alternatively, set `SD_CUDA_CUTLASS_PATH` to another local CUTLASS source
|
|
||||||
directory (tested with 3.9.2). Existing CMake caches retain their configured path;
|
|
||||||
pass `-USD_CUDA_CUTLASS_PATH` when reconfiguring to restore the bundled default.
|
|
||||||
Existing `GGML_CUDA_CUTLASS_PATH` caches are migrated on first configuration:
|
|
||||||
the old bundled path becomes `thirdparty/cutlass`, while custom paths and an
|
|
||||||
empty disabled value are preserved. An explicitly set `SD_CUDA_CUTLASS_PATH`
|
|
||||||
takes precedence. Non-CUDA builds do not require CUTLASS.
|
|
||||||
|
|
||||||
## Build with HIPBLAS
|
|
||||||
|
|
||||||
Use `-DSD_HIPBLAS=ON` for AMD GPU acceleration through HIP and hipBLAS.
|
|
||||||
Install a compatible AMD GPU driver and the ROCm SDK, including the HIP compiler,
|
|
||||||
hipBLAS, rocBLAS, and their development files. See
|
|
||||||
[AMD's ROCm installation guide](https://rocm.docs.amd.com/en/latest/install/rocm.html)
|
|
||||||
for supported GPUs, operating systems, and installation methods.
|
|
||||||
|
|
||||||
When the hipBLASLt development package (version 1.0 or later) is available,
|
|
||||||
CMake also enables INT8 GEMM tuning. The first run of an eligible matrix shape
|
|
||||||
benchmarks the no-workspace candidates returned by hipBLASLt for the current
|
|
||||||
device, including CDNA devices, and caches the result in the process. It
|
|
||||||
selects a hipBLASLt candidate that runs successfully and beats hipBLAS, or a
|
|
||||||
working candidate if hipBLAS does not support the operation.
|
|
||||||
Set `SD_HIP_DISABLE_I8_LT=1` to use the hipBLAS GEMM path for comparison.
|
|
||||||
|
|
||||||
With a compiled wave32 WMMA kernel, the HIP flash attention path supports
|
|
||||||
head dimensions 40, 52, 64, 72, 80, 120, 128, 160, 256, and 320, including
|
|
||||||
grouped-query attention. It requires unmasked attention with at least 512
|
|
||||||
query tokens and 512 key tokens. Set `SD_HIP_DISABLE_WMMA_ATTN=1` to use
|
|
||||||
ggml's native attention path for comparison.
|
|
||||||
|
|
||||||
**Linux**
|
|
||||||
|
|
||||||
With ROCm installed, use the default CMake generator and host compilers:
|
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
mkdir build && cd build
|
mkdir build && cd build
|
||||||
cmake .. -DSD_HIPBLAS=ON
|
if command -v rocminfo; then export GFX_NAME=$(rocminfo | awk '/ *Name: +gfx[1-9]/ {print $2; exit}'); else echo "rocminfo missing!"; fi
|
||||||
|
if [ -z "${GFX_NAME}" ]; then echo "Error: Couldn't detect GPU!"; else echo "Building for GPU: ${GFX_NAME}"; fi
|
||||||
|
cmake .. -G "Ninja" -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DSD_HIPBLAS=ON -DCMAKE_BUILD_TYPE=Release -DGPU_TARGETS=$GFX_NAME -DAMDGPU_TARGETS=$GFX_NAME -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON
|
||||||
cmake --build . --config Release
|
cmake --build . --config Release
|
||||||
```
|
```
|
||||||
|
|
||||||
For an SDK outside the default installation path, set `ROCM_PATH` to its root
|
|
||||||
and add `$ROCM_PATH/bin` to `PATH` before configuring. If its shared libraries
|
|
||||||
are not on the system library search path, add `$ROCM_PATH/lib` and
|
|
||||||
`$ROCM_PATH/lib64` to `LD_LIBRARY_PATH` when running the executable.
|
|
||||||
|
|
||||||
**Windows**
|
|
||||||
|
|
||||||
Follow the Windows environment setup in [Ninja](#ninja). The Windows HIP build
|
|
||||||
requires ROCm Clang with Ninja; the Visual Studio generator is not supported.
|
|
||||||
|
|
||||||
Set `HIP_PATH` to the SDK root. The HIP SDK installer normally sets this variable;
|
|
||||||
for [ROCm wheels](https://github.com/ROCm/TheRock/blob/main/RELEASES.md), run
|
|
||||||
`rocm-sdk init` and use `rocm-sdk path --root`. The build commands below cover
|
|
||||||
both the installer and wheel SDK compiler layouts.
|
|
||||||
|
|
||||||
For the wheel SDK, also set the device library path before building:
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
$env:HIP_DEVICE_LIB_PATH = "$env:HIP_PATH\lib\llvm\amdgcn\bitcode"
|
|
||||||
```
|
|
||||||
|
|
||||||
Then configure and build:
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
$env:ROCM_PATH = $env:HIP_PATH
|
|
||||||
$env:PATH = "$env:HIP_PATH\bin;$env:HIP_PATH\lib\llvm\bin;$env:PATH"
|
|
||||||
cmake -S . -B build-hip -G Ninja -DSD_HIPBLAS=ON -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release
|
|
||||||
cmake --build build-hip --config Release
|
|
||||||
```
|
|
||||||
|
|
||||||
Keep the SDK's `bin` directory on `PATH` when running `build-hip\bin\sd-cli.exe`
|
|
||||||
so its runtime DLLs can be found.
|
|
||||||
|
|
||||||
**GPU targets and verification**
|
|
||||||
|
|
||||||
CMake normally detects the installed GPU. To select a target explicitly or build
|
|
||||||
on a machine without an AMD GPU, add `-DGPU_TARGETS=gfx1100` to the configure
|
|
||||||
command (for example, for an RX 7900 XTX, XT, or GRE). For multiple targets, use a
|
|
||||||
quoted list such as `-DGPU_TARGETS="gfx1100;gfx1200"`. Check AMD's
|
|
||||||
[GPU specifications](https://rocm.docs.amd.com/en/latest/reference/gpu-specs.html)
|
|
||||||
for the correct target; the installed SDK libraries must also support it.
|
|
||||||
|
|
||||||
Use a fresh build directory when switching SDKs or compilers. Run the resulting
|
|
||||||
`sd-cli --version` to check that the executable starts without loading a model.
|
|
||||||
|
|
||||||
## Build with MUSA
|
## Build with MUSA
|
||||||
|
|
||||||
This provides GPU acceleration using Moore Threads GPUs. The configuration below follows upstream validation with MUSA SDK 5.2.0 and MTT S5000 (PH1, `mp_31`). Install that toolkit before building. Older SDKs such as 4.2 may lack the CUB headers required by the current backend.
|
This provides GPU acceleration using Moore Threads GPUs. The configuration below follows upstream validation with MUSA SDK 5.2.0 and MTT S5000 (PH1, `mp_31`). Install that toolkit before building. Older SDKs such as 4.2 may lack the CUB headers required by the current backend.
|
||||||
|
|
@ -271,8 +160,10 @@ Currently, it supports only Adreno GPUs and is primarily optimized for Q4_0 type
|
||||||
|
|
||||||
To build for Windows ARM please refers to [Windows 11 Arm64](https://github.com/ggml-org/llama.cpp/blob/master/docs/backend/OPENCL.md#windows-11-arm64)
|
To build for Windows ARM please refers to [Windows 11 Arm64](https://github.com/ggml-org/llama.cpp/blob/master/docs/backend/OPENCL.md#windows-11-arm64)
|
||||||
|
|
||||||
For Android, prepare [Ninja](#ninja) and install the Android NDK from the
|
Building for Android:
|
||||||
[official Android developer site](https://developer.android.com/ndk/downloads).
|
|
||||||
|
Android NDK:
|
||||||
|
Download and install the Android NDK from the [official Android developer site](https://developer.android.com/ndk/downloads).
|
||||||
|
|
||||||
Setup OpenCL Dependencies for NDK:
|
Setup OpenCL Dependencies for NDK:
|
||||||
|
|
||||||
|
|
@ -304,7 +195,7 @@ You need to provide OpenCL headers and the ICD loader library to your NDK sysroo
|
||||||
-DANDROID_PLATFORM=24 \
|
-DANDROID_PLATFORM=24 \
|
||||||
-DANDROID_STL=c++_shared
|
-DANDROID_STL=c++_shared
|
||||||
|
|
||||||
cmake --build .
|
ninja
|
||||||
# Replace <YOUR_NDK_PATH>
|
# Replace <YOUR_NDK_PATH>
|
||||||
# e.g., cp libOpenCL.so /path/to/android-ndk-r26c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android
|
# e.g., cp libOpenCL.so /path/to/android-ndk-r26c/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android
|
||||||
sudo cp libOpenCL.so <YOUR_NDK_PATH>/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android
|
sudo cp libOpenCL.so <YOUR_NDK_PATH>/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android
|
||||||
|
|
@ -325,7 +216,7 @@ cmake .. -G Ninja \
|
||||||
-DGGML_OPENMP=OFF \
|
-DGGML_OPENMP=OFF \
|
||||||
-DSD_OPENCL=ON
|
-DSD_OPENCL=ON
|
||||||
|
|
||||||
cmake --build .
|
ninja
|
||||||
```
|
```
|
||||||
*(Note: Don't forget to include `LD_LIBRARY_PATH=/vendor/lib64` in your command line before running the binary)*
|
*(Note: Don't forget to include `LD_LIBRARY_PATH=/vendor/lib64` in your command line before running the binary)*
|
||||||
|
|
||||||
|
|
@ -337,9 +228,6 @@ Using SYCL makes the computation run on the Intel GPU. Please make sure you have
|
||||||
# Export relevant ENV variables
|
# Export relevant ENV variables
|
||||||
source /opt/intel/oneapi/setvars.sh
|
source /opt/intel/oneapi/setvars.sh
|
||||||
|
|
||||||
# Make and enter build dir
|
|
||||||
mkdir build && cd build
|
|
||||||
|
|
||||||
# Option 1: Use FP32 (recommended for better performance in most cases)
|
# Option 1: Use FP32 (recommended for better performance in most cases)
|
||||||
cmake .. -DSD_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
|
cmake .. -DSD_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
|
||||||
|
|
||||||
|
|
@ -348,89 +236,3 @@ cmake .. -DSD_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DGGML_SY
|
||||||
|
|
||||||
cmake --build . --config Release
|
cmake --build . --config Release
|
||||||
```
|
```
|
||||||
|
|
||||||
## Build tools and compiler cache
|
|
||||||
|
|
||||||
The settings in this section can be combined with the backend options in
|
|
||||||
this guide.
|
|
||||||
|
|
||||||
### Ninja
|
|
||||||
|
|
||||||
Install Ninja and make sure `ninja --version` works in your build terminal.
|
|
||||||
For native Windows builds with MSVC or ROCm Clang, install Visual Studio
|
|
||||||
2022 C++ build tools with the Windows SDK, CMake, and Ninja, then open an
|
|
||||||
x64 **Developer PowerShell for VS 2022**.
|
|
||||||
|
|
||||||
From the repository root, configure and build a Release version with:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
cmake -S . -B build-ninja -G Ninja -DCMAKE_BUILD_TYPE=Release
|
|
||||||
cmake --build build-ninja --parallel 8
|
|
||||||
```
|
|
||||||
|
|
||||||
This builds the CPU backend by default. Add backend options such as
|
|
||||||
`-DSD_CUDA=ON` or `-DSD_VULKAN=ON` to the configure command as needed.
|
|
||||||
With MSVC, you can explicitly select the compiler by adding
|
|
||||||
`-DCMAKE_C_COMPILER=cl.exe -DCMAKE_CXX_COMPILER=cl.exe`.
|
|
||||||
Adjust `--parallel 8` for your available CPU and memory resources.
|
|
||||||
|
|
||||||
Use a separate build directory when switching from another CMake generator,
|
|
||||||
such as Visual Studio. With this Ninja generator, select the build type at
|
|
||||||
configure time using `CMAKE_BUILD_TYPE`.
|
|
||||||
|
|
||||||
### ccache (optional)
|
|
||||||
|
|
||||||
Install [ccache](https://ccache.dev/download.html) and add it to `PATH`.
|
|
||||||
Check that it is available and optionally set a cache size limit:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
ccache --version
|
|
||||||
ccache --max-size=20G
|
|
||||||
```
|
|
||||||
|
|
||||||
To cache C and C++ compilation, configure with compiler launchers:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
cmake -S . -B build-ninja -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache
|
|
||||||
cmake --build build-ninja --parallel 8
|
|
||||||
ccache --show-stats
|
|
||||||
```
|
|
||||||
|
|
||||||
For CUDA builds, also add `-DSD_CUDA=ON` and
|
|
||||||
`-DCMAKE_CUDA_COMPILER_LAUNCHER=ccache` to the configure command so CUDA
|
|
||||||
compilation is cached as well. Keep any other backend or compiler options
|
|
||||||
used for your build.
|
|
||||||
|
|
||||||
These [compiler launcher settings](https://cmake.org/cmake/help/latest/prop_tgt/LANG_COMPILER_LAUNCHER.html)
|
|
||||||
work with Ninja and Makefile generators. The Visual Studio generator does
|
|
||||||
not use them.
|
|
||||||
|
|
||||||
The first compilation populates the cache. After a successful build, you can
|
|
||||||
check reuse by rebuilding the same configuration with the cache intact:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
ccache --zero-stats
|
|
||||||
cmake --build build-ninja --clean-first --parallel 8
|
|
||||||
ccache --show-stats
|
|
||||||
```
|
|
||||||
|
|
||||||
Look for cache hits in the statistics. A normal incremental build with no
|
|
||||||
changed files skips compilation and does not produce new cache hits.
|
|
||||||
|
|
||||||
### MSVC compilation parallelism
|
|
||||||
|
|
||||||
MSVC builds limit parallel C/C++ compilation within each project by default.
|
|
||||||
For `n` logical processors, the limit is `n` when `n <= 2`, `n - 1` when
|
|
||||||
`3 <= n <= 8`, and `n - 2` when `n > 8`. The default is calculated when the
|
|
||||||
build directory is first configured with this setting. Override it with
|
|
||||||
`-DSD_MSVC_MP_COUNT=4`, or pass `-USD_MSVC_MP_COUNT` to recalculate it.
|
|
||||||
|
|
||||||
For Visual Studio builds, keep project-level parallelism at one to avoid
|
|
||||||
multiplying the per-project limit:
|
|
||||||
|
|
||||||
```shell
|
|
||||||
cmake --build build --config Release --parallel 1
|
|
||||||
```
|
|
||||||
|
|
||||||
This setting controls MSVC's `/MP` option, not CUDA compiler parallelism or a
|
|
||||||
hard CPU usage limit. For Ninja job limits, see [Ninja](#ninja).
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,15 @@
|
||||||
## Caching
|
## Caching
|
||||||
|
|
||||||
DGL versions of the generation examples are linked below. Edit each script's
|
|
||||||
`var` block and follow the [DGL run instructions](../dgl/README.md).
|
|
||||||
|
|
||||||
|
|
||||||
Caching methods accelerate diffusion inference by reusing intermediate computations when changes between steps are small.
|
Caching methods accelerate diffusion inference by reusing intermediate computations when changes between steps are small.
|
||||||
|
|
||||||
### Conditioning Cache
|
### Conditioning Cache
|
||||||
|
|
||||||
Conditioning results are cached per model context using an LRU cache. The default
|
Conditioning results are cached per model context using an LRU cache. The default
|
||||||
capacity is **4 entries for `sd-cli`, `sd-server` and the C API**.
|
capacity is **0 (disabled) for `sd-cli`** and **4 entries for `sd-server` and the C
|
||||||
Set `--conditioning-cache-size N` to change the limit; `0` disables caching.
|
API**. Set `--conditioning-cache-size N` to change the limit; `0` disables caching.
|
||||||
For example, `sd-cli -m model.safetensors -p "a cat" --conditioning-cache-size 8`
|
For example, `sd-cli -m model.safetensors -p "a cat" --conditioning-cache-size 4`
|
||||||
increases the CLI cache capacity to 8 entries. The C API option is
|
enables the cache in the CLI. The C API option is
|
||||||
`conditioning_cache_size`, set with `sd_opt_set_int()` on context options.
|
`sd_ctx_params_t::conditioning_cache_size`, initialized by `sd_ctx_params_init()`.
|
||||||
This cache is independent of the diffusion-step `--cache-mode` options below.
|
This cache is independent of the diffusion-step `--cache-mode` options below.
|
||||||
|
|
||||||
### Cache Modes
|
### Cache Modes
|
||||||
|
|
@ -35,7 +31,6 @@ UCache caches the residual difference (output - input) and reuses it when input
|
||||||
sd-cli -m model.safetensors -p "a cat" --cache-mode ucache --cache-option "threshold=1.5"
|
sd-cli -m model.safetensors -p "a cat" --cache-mode ucache --cache-option "threshold=1.5"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
| Parameter | Description | Default |
|
| Parameter | Description | Default |
|
||||||
|
|
@ -72,12 +67,11 @@ Condition-level caching for DiT models. Caches and reuses outputs when input cha
|
||||||
|
|
||||||
### Cache-DIT (DiT Models)
|
### Cache-DIT (DiT Models)
|
||||||
|
|
||||||
For DiT models like FLUX and QWEN, these modes cache each model condition's
|
For DiT models like FLUX and QWEN, use block-level caching modes.
|
||||||
raw output. This path does not perform block-level caching.
|
|
||||||
|
|
||||||
#### DBCache
|
#### DBCache
|
||||||
|
|
||||||
Reuses whole-model input/output residuals when input changes pass the L1 difference threshold:
|
Caches blocks based on L1 residual difference threshold:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
--cache-mode dbcache --cache-option "threshold=0.25,warmup=4"
|
--cache-mode dbcache --cache-option "threshold=0.25,warmup=4"
|
||||||
|
|
@ -85,7 +79,7 @@ Reuses whole-model input/output residuals when input changes pass the L1 differe
|
||||||
|
|
||||||
#### TaylorSeer
|
#### TaylorSeer
|
||||||
|
|
||||||
Uses Taylor series approximation to predict each condition's raw model output:
|
Uses Taylor series approximation to predict block outputs:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
--cache-mode taylorseer
|
--cache-mode taylorseer
|
||||||
|
|
@ -103,15 +97,11 @@ Combines DBCache and TaylorSeer:
|
||||||
|
|
||||||
| Parameter | Description | Default |
|
| Parameter | Description | Default |
|
||||||
|-----------|-------------|---------|
|
|-----------|-------------|---------|
|
||||||
| `Fn`, `Bn` | Legacy options: ignored with a warning; block counts are not supported | No effect |
|
| `Fn` | Front blocks to always compute | 8 |
|
||||||
|
| `Bn` | Back blocks to always compute | 0 |
|
||||||
| `threshold` | L1 residual difference threshold | 0.08 |
|
| `threshold` | L1 residual difference threshold | 0.08 |
|
||||||
| `warmup` | Steps before caching starts | 8 |
|
| `warmup` | Steps before caching starts | 8 |
|
||||||
|
|
||||||
Explicit `Fn`/`Bn` settings, including their former defaults, produce a warning.
|
|
||||||
The C API keys `cache.fn_compute_blocks` and `cache.bn_compute_blocks` remain
|
|
||||||
accepted for compatibility and also warn when set. They have no effect on cache
|
|
||||||
execution. Omitted options do not warn.
|
|
||||||
|
|
||||||
#### SCM Options
|
#### SCM Options
|
||||||
|
|
||||||
Steps Computation Mask controls which steps can be cached:
|
Steps Computation Mask controls which steps can be cached:
|
||||||
|
|
@ -122,10 +112,10 @@ Steps Computation Mask controls which steps can be cached:
|
||||||
|
|
||||||
Mask values: `1` = compute, `0` = can cache.
|
Mask values: `1` = compute, `0` = can cache.
|
||||||
|
|
||||||
The native `--scm-policy` option is retained for compatibility. Its `dynamic`
|
| Policy | Description |
|
||||||
and `static` values do not change this condition-level implementation: a mask
|
|--------|-------------|
|
||||||
value of `1` forces computation; `0` permits reuse subject to the cache's gates
|
| `dynamic` | Check threshold before caching |
|
||||||
and available history.
|
| `static` | Always cache on cacheable steps |
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
--scm-policy dynamic
|
--scm-policy dynamic
|
||||||
|
|
@ -139,7 +129,6 @@ Spectrum uses Chebyshev polynomial fitting blended with Taylor extrapolation to
|
||||||
sd-cli -m model.safetensors -p "a cat" --cache-mode spectrum
|
sd-cli -m model.safetensors -p "a cat" --cache-mode spectrum
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
| Parameter | Description | Default |
|
| Parameter | Description | Default |
|
||||||
32
docs/chroma.md
Normal file
32
docs/chroma.md
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
# How to Use
|
||||||
|
|
||||||
|
You can run Chroma using stable-diffusion.cpp with a GPU that has 6GB or even 4GB of VRAM, without needing to offload to RAM.
|
||||||
|
|
||||||
|
## Download weights
|
||||||
|
|
||||||
|
- Download Chroma
|
||||||
|
- If you don't want to do the conversion yourself, download the preconverted gguf model from [silveroxides/Chroma-GGUF](https://huggingface.co/silveroxides/Chroma-GGUF)
|
||||||
|
- Otherwise, download chroma's safetensors from [lodestones/Chroma](https://huggingface.co/lodestones/Chroma)
|
||||||
|
- Download vae from https://huggingface.co/black-forest-labs/FLUX.1-dev/blob/main/ae.safetensors
|
||||||
|
- Download t5xxl from https://huggingface.co/comfyanonymous/flux_text_encoders/blob/main/t5xxl_fp16.safetensors
|
||||||
|
|
||||||
|
## Convert Chroma weights
|
||||||
|
|
||||||
|
You can download the preconverted gguf weights from [silveroxides/Chroma-GGUF](https://huggingface.co/silveroxides/Chroma-GGUF), this way you don't have to do the conversion yourself.
|
||||||
|
|
||||||
|
```
|
||||||
|
.\bin\Release\sd-cli.exe -M convert -m ..\models\unet\chroma-unlocked-v40.safetensors -o ..\models\chroma-unlocked-v40-q8_0.gguf -v --type q8_0
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run
|
||||||
|
|
||||||
|
### Example
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```
|
||||||
|
.\bin\Release\sd-cli.exe --diffusion-model ..\models\chroma-unlocked-v40-q8_0.gguf --vae ..\models\ae.sft --t5xxl ..\models\t5xxl_fp16.safetensors -p "a lovely cat holding a sign says 'chroma.cpp'" --cfg-scale 4.0 --sampling-method euler -v --model-args chroma_use_dit_mask=false --clip-on-cpu
|
||||||
|
```
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
21
docs/chroma_radiance.md
Normal file
21
docs/chroma_radiance.md
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
# How to Use
|
||||||
|
|
||||||
|
## Download weights
|
||||||
|
|
||||||
|
- Download Chroma1-Radiance
|
||||||
|
- safetensors: https://huggingface.co/lodestones/Chroma1-Radiance/tree/main
|
||||||
|
- gguf: https://huggingface.co/silveroxides/Chroma1-Radiance-GGUF/tree/main
|
||||||
|
|
||||||
|
- Download t5xxl
|
||||||
|
- safetensors: https://huggingface.co/comfyanonymous/flux_text_encoders/blob/main/t5xxl_fp16.safetensors
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
```
|
||||||
|
.\bin\Release\sd-cli.exe --diffusion-model ..\models\diffusion_models\Chroma1-Radiance-v0.4-Q8_0.gguf --t5xxl ..\models\clip\t5xxl_fp16.safetensors -p "a lovely cat holding a sign says 'chroma radiance cpp'" --cfg-scale 4.0 --sampling-method euler -v
|
||||||
|
```
|
||||||
|
|
||||||
|
<img alt="Chroma1-Radiance" src="../assets/flux/chroma1-radiance.png" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,89 +0,0 @@
|
||||||
# C API Internals
|
|
||||||
|
|
||||||
The public declarations live in [stable-diffusion.h](../../include/stable-diffusion.h).
|
|
||||||
See the [C API guide](../guides/c_api.md) for keys, value types and ownership rules.
|
|
||||||
|
|
||||||
## Internal modules
|
|
||||||
|
|
||||||
| Module | Responsibility |
|
|
||||||
| --- | --- |
|
|
||||||
| `src/api/options.h/.cpp` | Opaque options, key registration, setter validation and conversion to typed configuration. |
|
|
||||||
| `src/config.h/.cpp` | Typed configuration and the library defaults for each configuration group. |
|
|
||||||
| `src/api/tensor.h/.cpp` | Opaque tensor handles backed by `sd::Tensor<T>`, reference counting and conversion to private media views. |
|
|
||||||
| `src/core/media.h` | Private raw media views used by inference and codecs. |
|
|
||||||
| `src/api/result.h/.cpp` | Internal result storage, opaque result accessors, metadata attachment and media ownership. |
|
|
||||||
| `src/api/api.h/.cpp` | Context, generation, callback and query entry points, plus thread-local diagnostics and exception-to-status handling. |
|
|
||||||
| `src/api/generation.*` | Persistent DGL context, metadata probing, request execution, callbacks and cancellation. |
|
|
||||||
| `src/api/generation_program.*`, `generation_image.cpp`, `generation_video.cpp`, `generation_h3.cpp`, `generation_prompt.cpp` | Template selection, literal rendering and host input bindings. |
|
|
||||||
| `src/api/generation_template.*` | Embedded template parsing, variable formatting and conditional rendering. |
|
|
||||||
| `src/api/templates/` | Complete DGL execution flows and a few shared helpers. |
|
|
||||||
| `src/api/program_result.cpp` | Adaptation of DGL tensors and dictionaries to C results. |
|
|
||||||
| `src/api/generation_metadata.cpp` | Image parameter and WebUI infotext extraction through the metadata C API. |
|
|
||||||
| `src/api/image_metadata.cpp` | Container metadata reading and text/JSON reports through `sd_read_metadata()`. |
|
|
||||||
| `src/api/media_metadata.cpp`, `metadata.h` | Shared metadata encoding and C access to PNG/JPEG/XMP/AVI chunks. |
|
|
||||||
| `src/core/option_types.h/.cpp` | Internal mode enums, name lookup and parsing. |
|
|
||||||
|
|
||||||
Options are validated and converted at the API boundary. The translator renders
|
|
||||||
a concrete DGL program and binds media through `main` tensor inputs. All retained
|
|
||||||
inference entries use the same DGL compiler, execution context and model cache.
|
|
||||||
There is no separate native pipeline.
|
|
||||||
|
|
||||||
The option map alone records whether a key was supplied. Zero, false, empty
|
|
||||||
strings and explicit automatic choices remain entries until `unset` removes
|
|
||||||
them. Each conversion starts with a fresh `OptConfig`, then overlays supplied
|
|
||||||
values and validates combinations. Reusing the output configuration cannot
|
|
||||||
retain a previous request's overrides.
|
|
||||||
|
|
||||||
Fixed defaults live in the configuration constructors. Internal automatic
|
|
||||||
policies (such as model-selected sampler/scheduler and automatic eta/flow shift)
|
|
||||||
are resolved by the translator after refreshing the model metadata. Their internal
|
|
||||||
sentinel values describe an automatic policy, not the presence of an input key.
|
|
||||||
Do not infer presence by comparing a typed value against its default.
|
|
||||||
|
|
||||||
CLI/server inference inputs use `std::optional`; their option builders emit
|
|
||||||
only engaged fields. Recipe defaults fill missing startup inputs; request
|
|
||||||
fields then override the configured recipe/startup values. Explicit empty
|
|
||||||
numeric arrays replace inherited arrays, and JSON `null` clears an optional
|
|
||||||
input. Frontend-only settings such as output formats and listen ports keep
|
|
||||||
local defaults. Frontend checks cover request syntax, file inputs and server
|
|
||||||
resource policy. Parameter ranges are checked by the public setters used by the
|
|
||||||
option builders; combinations and model applicability are checked when executing.
|
|
||||||
Examples include only public library headers and do not query library defaults.
|
|
||||||
Capability defaults describe configured overrides; null means that the library
|
|
||||||
selects the value, and the executed DGL records the effective values.
|
|
||||||
|
|
||||||
Result storage owns tensors and metadata. Tensor handles contain a dtype-specific
|
|
||||||
`sd::Tensor<T>` and an atomic reference count; options retain handles rather than
|
|
||||||
copying tensor payloads. DGL outputs are adapted at the result boundary.
|
|
||||||
Internal producers with an `sd::Tensor<T>` can
|
|
||||||
move it directly into a handle. Video results keep per-frame tensors and assemble
|
|
||||||
a contiguous video tensor only when requested. Cached assembly is synchronized.
|
|
||||||
Preview tensors are independent snapshots and may be retained by callbacks.
|
|
||||||
Results retain the exact compiled DGL source. WebUI conversion and media metadata
|
|
||||||
embedding are separate from inference and never rebuild the execution program.
|
|
||||||
`src/api/generation_metadata.cpp` parses the source once to produce image
|
|
||||||
parameters and WebUI infotext together. Examples obtain this JSON through
|
|
||||||
`sd_get_generation_metadata()` without compiling or calling the DGL parser.
|
|
||||||
Container reading and metadata chunk generation also use the public C API.
|
|
||||||
Examples have no private `src` include path and retain generated DGL source
|
|
||||||
without legacy JSON conversion or LoRA path rewriting.
|
|
||||||
The translator uses an explicit `llm_path` as the text encoder's main `path`, falling back to
|
|
||||||
the checkpoint and other configured encoder paths when it is absent.
|
|
||||||
|
|
||||||
Context creation snapshots options without loading weights. Family probing is
|
|
||||||
lazy and tracks actual file dependencies. The complete request stays busy during
|
|
||||||
probing, compilation, batch gaps and execution. File permissions are checked
|
|
||||||
before probing and on every DGL resource access, including cache hits.
|
|
||||||
Generation templates load their required components as part of execution.
|
|
||||||
Capability queries read the detected family under the context lock and probe it
|
|
||||||
on demand. They leave the generation cancellation state untouched.
|
|
||||||
|
|
||||||
C++ validates inputs, resolves model defaults, prepares geometry and binds host
|
|
||||||
tensors. Templates describe complete execution flows and optional stages;
|
|
||||||
operations and models retain computation algorithms. Split templates when the
|
|
||||||
flow changes substantially, and use conditions for smaller variations. Do not
|
|
||||||
search and patch rendered source to change execution. See the
|
|
||||||
[template guide](../../src/api/templates/README.md).
|
|
||||||
|
|
||||||
These headers are private implementation details and are not installed as part
|
|
||||||
of the public C API.
|
|
||||||
|
|
@ -1,69 +0,0 @@
|
||||||
# DGL architecture
|
|
||||||
|
|
||||||
A DGL program describes a workflow in terms of model and tensor operations.
|
|
||||||
The CLI can run a handwritten script. The generation C API renders a script
|
|
||||||
from request parameters and binds input tensors to its entry point. Both paths
|
|
||||||
use the same compiler and executor. The C API keeps the rendered source in
|
|
||||||
`generation_info`. See the [language guide](../dgl.md) and
|
|
||||||
[C API internals](c_api.md).
|
|
||||||
|
|
||||||
## From source to execution
|
|
||||||
|
|
||||||
1. **Compile the script.** The compiler parses the source, resolves calls and
|
|
||||||
arguments against the built-in registry or user functions, and checks their
|
|
||||||
types. It records which values each statement needs and when operations
|
|
||||||
use model weights. For a configuration-dependent `if`, it checks both
|
|
||||||
branches and records resource uses from the selected branch. This is enough
|
|
||||||
for `--check` to validate a program without loading model weights.
|
|
||||||
2. **Plan the run.** With auto-fit enabled, the runtime combines the graph's
|
|
||||||
weight-use phases with model parameter sizes, weights already resident in
|
|
||||||
the context, and current RAM and device budgets. It chooses where to keep
|
|
||||||
weights and respects explicit backend and split settings. Models first
|
|
||||||
encountered inside an iteration join the plan when their loader executes.
|
|
||||||
3. **Execute the graph.** The executor evaluates the bound calls in source
|
|
||||||
order and releases intermediate values after their last use. As execution
|
|
||||||
advances, the model manager uses the plan's next-use information to reclaim
|
|
||||||
idle weight buffers under memory pressure. The value returned by `main`
|
|
||||||
becomes the program result.
|
|
||||||
|
|
||||||
## Built-ins, operations and models
|
|
||||||
|
|
||||||
The registry describes a built-in's script name, parameters, defaults and
|
|
||||||
return type. The compiler uses that contract to check calls. At execution,
|
|
||||||
the binding converts script values to typed C++ arguments, calls an operation
|
|
||||||
or model loader, and wraps its result for the script. The same registry supplies
|
|
||||||
the [built-in function catalog](../dgl-builtins.md).
|
|
||||||
|
|
||||||
Operations implement work such as sampling, tensor slicing and media decoding.
|
|
||||||
They take concrete tensors, model objects, options and event interfaces. Models
|
|
||||||
own their runners, weight registrations and model-specific inference. Operations
|
|
||||||
can call models. Both use shared tensor, backend and runtime primitives. Script
|
|
||||||
values, syntax, registry entries and executor state stay on the language side
|
|
||||||
of the binding. Model code is independent of operations and bindings.
|
|
||||||
|
|
||||||
For example, a sampling run can use a classifier-free guidance (CFG) predictor.
|
|
||||||
|
|
||||||
```dgl
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
guided = cfg(pos, predictor(model, negative), scale = 7)
|
|
||||||
latent = sample(start, sigmas, predict = guided, rng = rng)
|
|
||||||
```
|
|
||||||
|
|
||||||
The first two statements describe which model and conditions to evaluate and how
|
|
||||||
to combine the predictions. They keep the model reachable. The sampling
|
|
||||||
operation drives the solver and evaluates that predictor at each required
|
|
||||||
step. The resource plan therefore accounts for diffusion weights during
|
|
||||||
`sample`. Each sampling call owns its own prediction history and progress state.
|
|
||||||
|
|
||||||
## What the context retains
|
|
||||||
|
|
||||||
A context owns backend settings, memory budgets and the model cache. A
|
|
||||||
persistent context can reuse a loaded component across scripts when its
|
|
||||||
normalized loader settings and source dependencies still match. A run-once
|
|
||||||
context can release it after its last use. Releasing a script binding and
|
|
||||||
evicting cached weights are therefore separate lifetime decisions.
|
|
||||||
|
|
||||||
One context runs one program at a time. Each run gets a fresh placement plan
|
|
||||||
and its own progress, preview and cancellation state. Two runs of the same
|
|
||||||
source can choose different weight placement as cached resources or available
|
|
||||||
memory change. See [context execution settings](../dgl.md#context-execution-settings).
|
|
||||||
|
|
@ -1,558 +0,0 @@
|
||||||
# ggml operator extensions
|
|
||||||
|
|
||||||
The patched ggml exposes `ggml-ext.h` for application-owned operators, kernel
|
|
||||||
overrides, and graph fusion rules. Registrations are in-process and scoped to a
|
|
||||||
backend device. Register them before capability queries or graph allocation;
|
|
||||||
callback code and user data must remain alive until all dependent graphs and
|
|
||||||
backends have been destroyed. Registration names are unique, and duplicate
|
|
||||||
registrations fail rather than replacing live implementations.
|
|
||||||
|
|
||||||
## Operator definitions
|
|
||||||
|
|
||||||
`ggml_ext_register_op` registers a versioned name, attribute size, and an output
|
|
||||||
metadata inference callback. `ggml_ext_op_create` creates an ordinary ggml tensor
|
|
||||||
with explicit input dependencies. The initial interface supports one contiguous,
|
|
||||||
out-of-place output with an existing `ggml_type`.
|
|
||||||
|
|
||||||
Attributes are copied into the unused portion of `op_params`. They are small,
|
|
||||||
plain values; use `memcpy` when reading attributes that need stricter alignment.
|
|
||||||
Auxiliary tensors must appear in `src`, not in an attribute pointer or user data.
|
|
||||||
Registered operators use `GGML_OP_CUSTOM` internally, with an identifiable
|
|
||||||
callback marker. Unsupported devices do not mistake them for CPU callbacks.
|
|
||||||
These process-local descriptors are not a graph serialization format.
|
|
||||||
|
|
||||||
## Kernel selection
|
|
||||||
|
|
||||||
`ggml_ext_register_kernel(device, &desc)` associates a kernel with a built-in
|
|
||||||
`ggml_op`, or with a registered custom operator. `supports` describes correctness
|
|
||||||
constraints; `preferred` optionally decides whether to override an available
|
|
||||||
native implementation. Higher priorities are considered first. When native
|
|
||||||
execution is unsupported, a supported extension can run regardless of its
|
|
||||||
preference callback.
|
|
||||||
|
|
||||||
Capability queries include registered single-node implementations, so the
|
|
||||||
scheduler can select a device even when its native implementation rejects the
|
|
||||||
operator. Callbacks inspect metadata only and must not recursively call the
|
|
||||||
public capability query for the same device and operator. A fusion-only
|
|
||||||
registration does not claim single-node support.
|
|
||||||
|
|
||||||
`ggml_ext_dev_supports_native_op` queries the original device implementation
|
|
||||||
without extension dispatch. Fusion policies can use it to select a supported
|
|
||||||
extension even when their performance preference normally favors native kernels.
|
|
||||||
|
|
||||||
`prepare` creates optional host-side plan state and reports workspace bytes.
|
|
||||||
It can run during memory measurement, before tensor addresses are assigned, and
|
|
||||||
must not launch work or allocate device buffers. Workspace is allocated by ggml
|
|
||||||
before execution and included in scheduler memory estimates and buffer-size
|
|
||||||
reports. `execute` receives the backend, workspace buffer, and current tensor
|
|
||||||
addresses. `destroy` releases prepared state. A preparation or execution error
|
|
||||||
is propagated; execution never retries a native implementation after launch.
|
|
||||||
|
|
||||||
Workspace is scratch storage shared by sequential extension steps in a plan;
|
|
||||||
its capacity is the maximum request, not the sum across nodes. Contents are not
|
|
||||||
preserved between calls. Queue work in backend execution order, and finish any
|
|
||||||
private-stream use before subsequent backend work can access the workspace.
|
|
||||||
Persistent state belongs in `prepare`/`destroy` state or explicit tensor inputs.
|
|
||||||
|
|
||||||
Overriding a built-in operator preserves its numerical and aliasing contract,
|
|
||||||
including allocator reuse of input storage. Explicit views/in-place nodes are
|
|
||||||
not intercepted by this first interface. Rebuild the scheduler allocation after
|
|
||||||
changing graph metadata, selection policy, or registrations.
|
|
||||||
|
|
||||||
## Fusion
|
|
||||||
|
|
||||||
A `match` callback returns the number of consecutive nodes it can replace.
|
|
||||||
The scheduler freezes this selection before allocating tensors. ggml checks
|
|
||||||
compute flags, external uses, output flags, and views; the initial implementation
|
|
||||||
accepts a conservative set of pure operators with only the final node exposed
|
|
||||||
as the fused output. The rule remains responsible for mathematical equivalence,
|
|
||||||
dtype, shape, layout, and hardware constraints. Internal views are accepted when
|
|
||||||
their storage belongs to the fused subgraph. In-place intermediates are accepted
|
|
||||||
only when their storage owner is an earlier node in the same match. External
|
|
||||||
consumers and output flags still prevent eliminating those results. The final
|
|
||||||
output must own storage, use a terminal `CPY`, or write back to an earlier owning
|
|
||||||
node within the match. Internal writeback must cover exactly the owner's full
|
|
||||||
shape, type, strides and storage offset, without external consumers of that
|
|
||||||
owner. Output flags propagated to that owner are retained. Terminal `CPY` keeps
|
|
||||||
its original destination and write semantics. The extension must handle input/output storage overlap, including
|
|
||||||
allocator reuse, with scratch space when necessary. Other in-place writes are
|
|
||||||
not eligible for extension fusion when they target storage outside the match.
|
|
||||||
|
|
||||||
An optional `optimize` callback runs before matching and allocation. Use
|
|
||||||
`ggml_ext_graph_delay` to move a producer range after independent nodes. The
|
|
||||||
helper rejects dependencies, unknown side effects, and writes that alias moved
|
|
||||||
inputs or outputs. It can cross independent copies and known in-place operators
|
|
||||||
when their storage does not alias the moved inputs or outputs. Owning dtype
|
|
||||||
conversions can also be moved or crossed.
|
|
||||||
Reordering must preserve edges and tensor metadata. Fusion legality is checked
|
|
||||||
again after reordering.
|
|
||||||
|
|
||||||
External inputs stay allocated through the final node. Native graph optimization
|
|
||||||
and execution operate on the remaining contiguous ranges, so native fusion cannot
|
|
||||||
consume nodes selected by an extension. Fused intermediates are excluded from
|
|
||||||
allocation through the backend's `skip_alloc` callback and
|
|
||||||
`ggml_gallocr_set_skipped_tensors`. Their metadata and graph edges remain available,
|
|
||||||
but execution must not access their data or buffers. Storage backing the final
|
|
||||||
output is retained, including an internal owner used by an in-place final write.
|
|
||||||
The skipped set is replaced for each allocation graph; changing which tensors are skipped
|
|
||||||
invalidates cached allocation assignments even when tensor shapes are unchanged.
|
|
||||||
|
|
||||||
Automatic extension fusion is enabled in scheduler execution with one pipeline
|
|
||||||
copy and without evaluation callbacks. Multiple pipeline copies and evaluation
|
|
||||||
callbacks retain individual operations. Direct backend graph computation supports
|
|
||||||
single-node extensions; it does not fuse an already allocated graph. Direct calls
|
|
||||||
use temporary plans and synchronize before releasing them; scheduler plans and
|
|
||||||
workspaces are reused across executions.
|
|
||||||
|
|
||||||
Use the backend graph APIs or the scheduler. The legacy CPU `ggml_graph_compute`
|
|
||||||
and backend `graph_plan_*` interfaces do not dispatch these extensions.
|
|
||||||
|
|
||||||
## Backend services
|
|
||||||
|
|
||||||
ComfyUI W4A4 linear layers use `sd.linear_w4_convrot.v1`. W4A8 uses the same
|
|
||||||
`sd.linear_i8.v1` node as W8A8 with packed weights, a codebook, and FP8 relative
|
|
||||||
scales. The backend decodes that projection's weights into scheduler workspace
|
|
||||||
before running the shared INT8 GEMM with its channel scales. Both formats consume the explicit output of
|
|
||||||
`sd.quantize_i8_convrot.v1`. Logical output dimensions are stored in the linear
|
|
||||||
operator attributes so backend copies of the packed activation can be used
|
|
||||||
directly.
|
|
||||||
|
|
||||||
Services are discovered through `ggml_backend_reg_get_proc_address`:
|
|
||||||
|
|
||||||
| Service | Purpose |
|
|
||||||
| --- | --- |
|
|
||||||
| `ggml_ext_cpu_parallel_v1` | Run an application callback on the CPU backend's configured thread pool, with its abort callback. |
|
|
||||||
| `ggml_ext_cuda_context_v1` | Borrow the current CUDA device and stream, ordered with native work. |
|
|
||||||
| `ggml_ext_cuda_device_v1` | Get the physical CUDA ordinal for capability checks before backend creation, including virtual ggml devices. |
|
|
||||||
| `ggml_ext_cuda_blas_v1` | Borrow the current stream's cuBLAS handle during execution, with host scalar pointers. |
|
|
||||||
| `ggml_ext_gpu_device_v1` | Query CUDA/HIP/MUSA runtime kind, physical ordinal, shared-memory limit, warp size, and INT8 BLAS capability. |
|
|
||||||
| `ggml_ext_gpu_context_v1` | Borrow the matching runtime's device and execution stream. |
|
|
||||||
| `ggml_ext_gpu_blas_v1` | Borrow the matching cuBLAS, hipBLAS, or muBLAS handle on that stream. |
|
|
||||||
| `ggml_ext_metal_device_v1` | Borrow the Metal device for application pipeline compilation. |
|
|
||||||
| `ggml_ext_metal_buffer_v1` | Resolve a backend buffer range to its Metal buffer and offset, including private storage and split allocations. |
|
|
||||||
| `ggml_ext_metal_submit_v1` | Encode application commands on a backend-owned command buffer, ordered with native Metal work and tracked by backend synchronization. |
|
|
||||||
|
|
||||||
The borrowed cuBLAS handle remains owned by the backend. Extensions must not retain
|
|
||||||
or destroy it, or change its stream, pointer mode, math mode, or workspace. This
|
|
||||||
CUDA-specific BLAS service is retained for existing callers; the runtime-aware
|
|
||||||
services support CUDA, HIP, and MUSA with the same ownership rules. Extensions
|
|
||||||
call vendor runtime and BLAS APIs directly. These services do not execute GEMM,
|
|
||||||
quantization, or model fusion on the application's behalf.
|
|
||||||
|
|
||||||
Workspace is a backend buffer. Its base is a CUDA device pointer on CUDA; callers
|
|
||||||
must use the representation appropriate to their backend. Vulkan extensions use
|
|
||||||
the command recording services described below.
|
|
||||||
|
|
||||||
CUDA INT8 Linear, RoPE, ConvRot, RMS affine and INT8 gated residual kernels omit output
|
|
||||||
scratch when allocation guarantees that a fresh owning output cannot overlap
|
|
||||||
live inputs. Existing outputs and views retain overlap protection. Internal
|
|
||||||
GEMM and quantization workspace is still reserved when required; kernels also
|
|
||||||
handle a null workspace when the entire step needs no scratch.
|
|
||||||
|
|
||||||
Compute workspace measurement preserves the storage identities and offsets of
|
|
||||||
external tensors, including views. Separate allocations must not share a synthetic
|
|
||||||
buffer identity: that can invent overlap, overestimate scratch, and repeatedly
|
|
||||||
rebuild a workspace whose actual allocation is smaller than the estimate.
|
|
||||||
|
|
||||||
## sd.cpp integration
|
|
||||||
|
|
||||||
`src/core/ggml_extensions.cpp` and `.h` contain the shared operator schemas,
|
|
||||||
validation, and backend registration entry point. Graph construction helpers live
|
|
||||||
in `src/core/ggml_extend.cpp` and `.h`; they take `GGMLRunnerContext*` so backend
|
|
||||||
selection, compatibility workarounds, and shared ConvRot nodes use the same
|
|
||||||
context as the calling model. Per-call precision, scaling, attention, and padding
|
|
||||||
options remain explicit. Model blocks retain weight loading and adapter
|
|
||||||
orchestration, while the shared helpers own FP8 fallback, embedding lookup,
|
|
||||||
full/partial RoPE, grouped convolution, and backend-dependent repeat handling.
|
|
||||||
LoRA/LoKr construction, n-mode products, and Kronecker products stay in
|
|
||||||
`src/model/adapter/lora_ops.cpp` and `.h`, with the same runner-context interface.
|
|
||||||
CPU kernels and fusion rules live in `src/core/cpu/`, with registration collected
|
|
||||||
in `cpu/registration.cpp`. CUDA-style and Vulkan implementations live in their
|
|
||||||
respective backend directories.
|
|
||||||
|
|
||||||
`sd.i8_lora_merge.v1` takes an INT8 weight, its F32 scale tensor, and an F32 LoRA
|
|
||||||
delta. It rotates the delta when the checkpoint uses convrot, adds it in the
|
|
||||||
stored weight's basis, and packs a status word, the new scales, and the INT8
|
|
||||||
weight into one tensor. Graph copy nodes use integer views to write both
|
|
||||||
ranges into the cached weight buffers and retain only the status word for
|
|
||||||
finalization. The views use I32 for aligned ranges and I8 for byte copies.
|
|
||||||
Layouts without native copy support write back during graph finalization.
|
|
||||||
|
|
||||||
`src/core/metal/int8.mm` registers Metal INT8 linear and ConvRot kernels. Their
|
|
||||||
Metal source is embedded at build time and compiled for the selected device
|
|
||||||
during registration. The public `ggml-ext-metal.h` services expose borrowed
|
|
||||||
objects without private backend headers. The submit callback only encodes work;
|
|
||||||
GGML owns submission, cancellation checks, command-buffer lifetime, and
|
|
||||||
asynchronous error tracking. Rotation scratch and any overlapping output use
|
|
||||||
the scheduler workspace. No full floating-point weight copy is allocated.
|
|
||||||
When runtime compilation supports Metal 4 TensorOps, INT8 multiplication uses
|
|
||||||
`matmul2d` with INT32 cooperative results and fused scale/bias restoration.
|
|
||||||
The SIMD-group implementation remains the fallback for older systems and
|
|
||||||
devices where the TensorOps pipeline is unavailable.
|
|
||||||
TensorOps multiplies at most 1024 pairs per partial result and combines those
|
|
||||||
results with wrapping integer addition. This preserves exact INT32 semantics
|
|
||||||
even when TensorOps uses floating-point arithmetic internally.
|
|
||||||
|
|
||||||
`ggml_ext_modulate(ctx, x, shift, scale)` emits `sd.modulate.v1` for F32 inputs
|
|
||||||
when the runner context uses CPU, CUDA/HIP/MUSA, or Vulkan.
|
|
||||||
Its explicit inputs are `x`, `scale`, and optional `shift`; it computes
|
|
||||||
`(x + x * scale) + shift` with separate FP32 multiply/add rounding. The output
|
|
||||||
is contiguous and out of place. Inputs may be strided and use ggml's
|
|
||||||
dimension-wise repetition rules. Callers prepare token, batch, or frame layouts
|
|
||||||
before constructing the operation; normalization and residual gates remain
|
|
||||||
separate operations. CPU, CUDA/HIP/MUSA, and Vulkan have standalone kernels.
|
|
||||||
Other backends (including Metal, SYCL, and OpenCL), upstream ggml builds, and
|
|
||||||
other input types retain the original MUL/ADD graph.
|
|
||||||
|
|
||||||
ConvRot fusion matches the Modulate node directly, including scale-only
|
|
||||||
modulation, instead of recognizing its former MUL/ADD/ADD decomposition.
|
|
||||||
CUDA accepts contiguous per-channel parameters for `Modulate -> ConvRot` and
|
|
||||||
`RMSNorm -> Mul(weight) -> Modulate -> ConvRot`. Vulkan limits the first fusion
|
|
||||||
to widths 4096/6144/5376 and the RMSNorm fusion to width 5376.
|
|
||||||
Other layouts execute the standalone operation followed by ConvRot. The
|
|
||||||
gated-residual MUL/ADD fusion remains available for residual branches.
|
|
||||||
|
|
||||||
`src/core/cpu/rope.cpp` registers the CPU implementation of
|
|
||||||
`sd.rope_apply.v1` and a
|
|
||||||
`RMSNorm -> Mul -> RoPE` fusion. The fusion accepts a one-dimensional weight
|
|
||||||
vector. Both interleaved and split-half RoPE, partial rotation, and strided input
|
|
||||||
rows are supported. Model construction uses the custom operator on CPU, CUDA,
|
|
||||||
HIP, MUSA, and Vulkan. Other backends can use the scheduler's CPU fallback.
|
|
||||||
The former `ggml_rope_apply` API, builtin opcode, and CPU implementation have
|
|
||||||
been removed from ggml.
|
|
||||||
|
|
||||||
`src/core/cuda/rope.cu` supplies standalone CUDA RoPE,
|
|
||||||
`RMSNorm -> RoPE` fusion for non-affine normalization, and
|
|
||||||
`RMSNorm -> Mul -> RoPE [-> Scale -> FP16 Copy]` fusion. CuTe attention shares
|
|
||||||
its RMSNorm/RoPE kernel. Partial rotation and arbitrary float-aligned input and
|
|
||||||
position-encoding strides are supported by the standalone kernel; RMSNorm fusion
|
|
||||||
requires contiguous position encoding and, when present, weights. The non-affine
|
|
||||||
fusion uses 64-channel F32 inputs and split-half RoPE. Copy fusion uses workspace
|
|
||||||
when the destination overlaps an input. These registrations do not require
|
|
||||||
CUTLASS. The old CUDA/HIP/MUSA RoPE dispatch is removed.
|
|
||||||
|
|
||||||
Shared CUDA-style kernels live in `src/core/cuda/` and are compiled separately
|
|
||||||
for each enabled runtime. `SD_CUDA_NAMESPACE` expands to `sd_cuda`, `sd_hip`, or
|
|
||||||
`sd_musa`, so implementations can coexist. `runtime.h` handles the small runtime
|
|
||||||
differences, including logical 32-lane shuffles on HIP. The application defines
|
|
||||||
and launches its kernels directly; it includes only public ggml headers.
|
|
||||||
CMake generates the registration table from enabled backend options. The shared
|
|
||||||
entry point uses one `SD_BACKEND_EXTENSIONS` macro; backend registrars verify the
|
|
||||||
device kind, and disabled backends add no symbol references.
|
|
||||||
|
|
||||||
`SD_USE_UPSTREAM_GGML` excludes these registrations. The stable-diffusion public C
|
|
||||||
API is unchanged. INT8 ConvRot retains its existing packed activation layout and
|
|
||||||
separate weight scale tensor.
|
|
||||||
|
|
||||||
`src/core/cuda/cute_attention.cu` supplies CuTe Flash Attention on CUDA when
|
|
||||||
CUTLASS headers are configured. It registers an override of `FLASH_ATTN_EXT`,
|
|
||||||
with the existing sequence-length preference and native fallback. It also
|
|
||||||
registers Q preparation (`RMSNorm -> Mul -> RoPE`), output scaling, and packed
|
|
||||||
ConvRot output fusion. These kernels use only the public extension API, borrowed
|
|
||||||
CUDA stream, and scheduler-owned workspace; they do not use ggml's CUDA pool or
|
|
||||||
private conversion helpers. The existing CUDA fusion and CuTe disable environment
|
|
||||||
variables are honored.
|
|
||||||
Aligned contiguous FP16 K/V inputs are read directly without reserving conversion
|
|
||||||
buffers. Fresh F32 outputs are written by the attention epilogue, retaining the
|
|
||||||
original FP16 rounding before output scaling. Packed ConvRot and preallocated or
|
|
||||||
view outputs retain the intermediate half buffer.
|
|
||||||
|
|
||||||
`src/core/cuda/i8_projection.cu` supplies the INT8 GEMM projection epilogues:
|
|
||||||
`GEMM -> Reshape -> RMSNorm -> Mul -> RoPE`, optional scaling and FP16 copy,
|
|
||||||
and K/V prefix concatenation with FP16 output. CuTe can consume a directly
|
|
||||||
produced FP16 Q without materializing the FP32 GEMM or RoPE intermediates.
|
|
||||||
Independent affine operands, including broadcasted constants, are computed before
|
|
||||||
their normalization/projection
|
|
||||||
chain when graph dependencies allow it. The attention optimizer can then move
|
|
||||||
the complete five-node projection when safe.
|
|
||||||
These rules accept custom RoPE nodes. They preserve the original
|
|
||||||
large-matrix selection thresholds, full interleaved head dimension 128, packed
|
|
||||||
activation layout, and separate weight scales. External consumers prevent fusion;
|
|
||||||
aliasing terminal copies use scheduler workspace. The CUDA projection kernels
|
|
||||||
and matchers now live in sd.cpp. `GGML_CUDA_FORCE_CUBLAS` disables these epilogues.
|
|
||||||
|
|
||||||
`src/core/ggml_extensions.cpp` defines `sd.linear_i8.v1` and
|
|
||||||
`sd.quantize_i8_convrot.v1`. `src/core/cpu/int8.cpp` supplies their CPU
|
|
||||||
implementations. The CPU kernels use the
|
|
||||||
configured thread pool and scheduler workspace; the old CPU INT8 GEMM and ConvRot
|
|
||||||
implementations have been removed from ggml.
|
|
||||||
Model code keeps calling `ggml_ext_linear_i8_tensorwise`,
|
|
||||||
`ggml_ext_mul_mat_i8_tensorwise`, and `ggml_ext_quantize_i8_convrot`. The latter two
|
|
||||||
constructors are declared and implemented in sd.cpp and create custom nodes.
|
|
||||||
Their former ggml declarations, implementations, ConvRot opcode, and native
|
|
||||||
backend paths have been removed. CPU, CUDA/HIP/MUSA, and Vulkan register kernels
|
|
||||||
and fusion rules through the extension interfaces.
|
|
||||||
|
|
||||||
For already quantized activations, `ggml_ext_mul_mat_i8_tensorwise` accepts ordinary
|
|
||||||
I8 weight and activation tensors. Its optional `input_scale` parameter is a
|
|
||||||
separate F32 tensor with one value per activation row. Weight scales have one
|
|
||||||
value per output channel; weight scales and bias can be null. Existing calls
|
|
||||||
omit `input_scale` and retain their original argument order. It computes `float(int32_dot(W, X)) * X_scale * W_scale + bias`, in that
|
|
||||||
order. All scales are explicit graph dependencies; there is no quantized-tensor
|
|
||||||
wrapper. Shapes use ggml's low-to-high dimension order. Call
|
|
||||||
`sd_ggml_register_extensions` before scheduling these custom nodes.
|
|
||||||
|
|
||||||
`ggml_ext_mul_mat_i8_tensorwise` also accepts F32 activations (quantized into temporary
|
|
||||||
workspace) or the output of `ggml_ext_quantize_i8_convrot`. ConvRot keeps the existing
|
|
||||||
packed I8 activation rows, padded to a multiple of four rows, followed by F32 row
|
|
||||||
scales. Weight scales remain separate. CPU ConvRot groups are 1, 4, 16, 64, or 256.
|
|
||||||
Unsupported layouts and malformed scale shapes are rejected. Separate CPU quantize
|
|
||||||
and GEMM phases propagate cancellation, and overlapping outputs use workspace.
|
|
||||||
|
|
||||||
`src/core/cuda/int8.cu` implements the same custom schemas on CUDA. It uses the
|
|
||||||
borrowed cuBLAS handle for I8-by-I8-to-I32 GEMM and application-owned quantization,
|
|
||||||
ConvRot, and rescaling kernels. F32 inputs are quantized into workspace; ordinary
|
|
||||||
I8 inputs retain separate scale tensors and use a padded temporary only when
|
|
||||||
needed by cuBLAS. Packed ConvRot inputs are consumed directly. Large ConvRot rows
|
|
||||||
use multiple kernels when they exceed shared memory. Aliasing outputs use scratch.
|
|
||||||
CUDA GEMM requires Turing or newer, contiguous tensors, K/N divisible by four,
|
|
||||||
float-aligned inputs, and row counts that fit a padded signed 32-bit dimension;
|
|
||||||
CUDA ConvRot uses groups of 256.
|
|
||||||
Unsupported custom nodes can fall back to CPU through the scheduler.
|
|
||||||
|
|
||||||
When CUTLASS is configured, `src/core/cuda/i8_gemm.cu` supplies dense and SwiGLU
|
|
||||||
INT8 GEMM kernels on Ampere or newer. It preserves the native tile selection,
|
|
||||||
small-row policy, Stream-K scheduling, Ada column bands, and separate scaling
|
|
||||||
order. The same extension matches `GEMM -> SwiGLU [-> ConvRot]` and row
|
|
||||||
concatenation for custom GEMM nodes. Weight scales remain explicit
|
|
||||||
inputs, including the gate/up scale permutation recorded on every SwiGLU launch.
|
|
||||||
Two independent INT8 GEMMs sharing a quantized input can also fuse with split
|
|
||||||
SwiGLU. A paired-column iterator reads the separate gate/up weight allocations,
|
|
||||||
and the GEMM epilogue writes only the activated output. Both intermediate
|
|
||||||
activations are omitted through the generic fusion allocation interface; weights
|
|
||||||
are neither copied nor concatenated. This path requires bias-free branches,
|
|
||||||
compatible layouts and alignments, and no external intermediate consumers.
|
|
||||||
Only interleaved weight scales and any Stream-K workspace remain temporary.
|
|
||||||
Plans reserve bounded Stream-K workspace, cache occupancy on first execution,
|
|
||||||
and initialize barriers on every launch, so CUDA Graph replay observes updated
|
|
||||||
inputs and scales. External consumers retain ordinary execution; overlapping
|
|
||||||
outputs use workspace. For fresh outputs, the CUTLASS SwiGLU epilogue writes
|
|
||||||
an allocator-managed tensor that the subsequent ConvRot launch consumes. This
|
|
||||||
keeps the same GPU launches while allowing its storage to be reused by other
|
|
||||||
operations. The combined SwiGLU/ConvRot path retains its workspace intermediate
|
|
||||||
for other cases. Shapes or alignments unsuitable for CUTLASS use cuBLAS.
|
|
||||||
Custom I8 nodes also retain cuBLAS when the reduction could overflow I32, to
|
|
||||||
preserve their previous accumulation behavior. Fusion disable and force-cuBLAS
|
|
||||||
settings are honored. No CUTLASS headers are needed for the cuBLAS path.
|
|
||||||
|
|
||||||
The native CUDA/HIP INT8 GEMM, standalone ConvRot, and associated fusion paths
|
|
||||||
have been removed from ggml. The shared application implementation calls cuBLAS
|
|
||||||
or hipBLAS directly. HIP retains the existing architecture eligibility policy;
|
|
||||||
MUSA does not advertise INT8 BLAS support and uses scheduler fallback for GEMM.
|
|
||||||
Standalone ConvRot kernels are compiled for all three runtimes. CUTLASS
|
|
||||||
implementations remain CUDA-specific.
|
|
||||||
|
|
||||||
`src/core/cuda/i8_gated_residual.cu` implements
|
|
||||||
`INT8 GEMM -> [Scale] -> Mul(gate) -> Add(residual) -> [Concat]` as a registered
|
|
||||||
CUDA fusion, for packed ConvRot inputs and ordinary I8 nodes with separate activation
|
|
||||||
scales. The corresponding native CUDA fusion rules and CUTLASS residual epilogue
|
|
||||||
have been removed from ggml. Its optimizer moves independent gate producers ahead
|
|
||||||
of GEMM and optional scaling through `ggml_ext_graph_delay`, before fusion matching.
|
|
||||||
The former native INT8 affine reorder rule has also moved into this extension.
|
|
||||||
It preserves the original tile selection, small-row
|
|
||||||
threshold, Stream-K scheduling, Ada column bands, and separate FP32 rounding of
|
|
||||||
gate multiplication and residual addition. The plan bounds Stream-K workspace
|
|
||||||
over possible occupancy values using host metadata; execution verifies the
|
|
||||||
actual requirement against that bound. Device occupancy is cached on first
|
|
||||||
execution; each launch rebuilds parameters for the current tensor addresses and
|
|
||||||
initializes its Stream-K barriers. Overlapping outputs use scratch, except
|
|
||||||
for an exact in-place residual without concatenation. External consumers and
|
|
||||||
unsupported layouts retain ordinary operator execution. Fusion and force-cuBLAS
|
|
||||||
disable settings are honored.
|
|
||||||
|
|
||||||
`src/core/cuda/convrot.cu` registers CUDA fusion for `Scale -> ConvRot`,
|
|
||||||
`Norm -> Mul -> ConvRot`, `Modulate -> ConvRot`,
|
|
||||||
`RMSNorm -> Mul(weight) -> Modulate -> ConvRot`, `SwiGLU -> ConvRot`, and
|
|
||||||
`SiLU/Sigmoid -> Mul -> ConvRot`.
|
|
||||||
ConvRot outputs are custom nodes. SwiGLU accepts packed,
|
|
||||||
swapped, or separate gate/up inputs. Independent modulation and up-branch
|
|
||||||
producers are moved ahead of their consumers through the safe graph-delay API.
|
|
||||||
Reordering keeps an owning producer together with in-place consumers, such as
|
|
||||||
Krea2's RMSNorm weight multiplication, so the alias checks can preserve their
|
|
||||||
storage relationship.
|
|
||||||
The application kernel preserves the original reduction order, thread selection,
|
|
||||||
ConvRot row padding, and separate scale tail. Prepared plans cache operation
|
|
||||||
metadata, use the borrowed CUDA stream, and reserve scheduler workspace for
|
|
||||||
overlapping outputs. Long rows or external intermediate consumers retain
|
|
||||||
ordinary execution. These fusions do not require CUTLASS and honor
|
|
||||||
`GGML_CUDA_DISABLE_FUSION`.
|
|
||||||
|
|
||||||
The corresponding scale, normalization, and unary-activation fusion rules have
|
|
||||||
been removed from ggml for CUDA and HIP. GEMM/SwiGLU/ConvRot chains are selected by the
|
|
||||||
application INT8 extension before the standalone activation fusion.
|
|
||||||
|
|
||||||
`src/core/cuda/affine.cu` registers FP32 `Mul(gate) -> Add(residual)`,
|
|
||||||
`Concat -> [Permute] -> FP16 Copy`, and `Contiguous -> Scale -> Permute -> FP16
|
|
||||||
Copy` fusions. Gate multiplication and residual addition retain separate FP32
|
|
||||||
rounding. Copy layouts and alignment requirements match the original CUDA
|
|
||||||
kernels; unsupported layouts, external intermediate consumers, self-residual
|
|
||||||
Add inputs, and fusion disabling retain ordinary operators. Internal in-place
|
|
||||||
Add outputs are accepted when they overwrite the complete fused Mul allocation. Exact in-place residual
|
|
||||||
or input addresses are safe for the pointwise kernel; partial overlap, broadcast
|
|
||||||
gate overlap, and FP16 copy overlap use scheduler workspace. These registrations
|
|
||||||
require no CUTLASS, compile for CUDA/HIP/MUSA, and support reusable CUDA Graph
|
|
||||||
replay. Their former native fusion implementations have been removed from ggml.
|
|
||||||
|
|
||||||
CUDA kernels can opt into device replay with `ggml_ext_register_kernel_ex` and
|
|
||||||
`GGML_EXT_KERNEL_CAPTURE_SAFE`. The original registration function retains its
|
|
||||||
per-execution callback behavior, and the descriptor ABI is unchanged. Opting in
|
|
||||||
means the callback enqueues replayable device work: it has no required
|
|
||||||
per-execution host side effects or decisions based on tensor contents, and any
|
|
||||||
private streams rejoin the borrowed stream. Lazy setup must complete during the
|
|
||||||
first ordinary execution. Tensor metadata, attributes, and host plan parameters
|
|
||||||
remain frozen until scheduler reallocation; tensor contents may change normally.
|
|
||||||
|
|
||||||
When every selected extension opts in, the CUDA backend can capture the whole
|
|
||||||
scheduled plan, including its native fragments, into one CUDA Graph. The first
|
|
||||||
execution warms up kernels and library state while retaining native fragment
|
|
||||||
caches. The next stable execution captures
|
|
||||||
and launches the graph; later calls replay it. Changing a tensor address or the
|
|
||||||
execution stream invalidates the capture and repeats warmup, even when the graph
|
|
||||||
UID is unchanged. Capture failures propagate without retrying partially executed
|
|
||||||
work. An enclosing stream capture records the plan directly instead of starting
|
|
||||||
a nested capture.
|
|
||||||
|
|
||||||
`GGML_EXT_KERNEL_REPLAY_REUSABLE` additionally permits reuse across scheduler
|
|
||||||
plan rebuilds and requires `CAPTURE_SAFE`. Recorded work must depend only on
|
|
||||||
complete tensor metadata, addresses, the device and immutable registration data.
|
|
||||||
Captured resources must belong to the backend or the supplied workspace, never
|
|
||||||
per-plan host state. Workspace contents must be initialized by recorded device
|
|
||||||
work on each execution. Prepare/destroy still run for every rebuilt host plan.
|
|
||||||
The backend cache retains only the executor and workspace; it compares graph
|
|
||||||
structure, tensor metadata/addresses, selected kernels and workspace requirements
|
|
||||||
exactly, without dereferencing old graph objects. A new metadata arena can reuse
|
|
||||||
an equivalent capture. Each backend retains at most 16 retired plans and 256 MiB
|
|
||||||
of their workspaces, evicting the oldest entries first. Larger workspaces retain
|
|
||||||
plan-local capture only. Backend destruction synchronizes and releases the cache.
|
|
||||||
This allows sd.cpp's per-step scheduler rebuilds to retain device replay.
|
|
||||||
|
|
||||||
Mixed plans containing an extension without the flag retain ordinary dispatch.
|
|
||||||
Evaluation callbacks, multiple pipeline copies, and direct backend graph calls
|
|
||||||
also retain their previous behavior. `GGML_CUDA_DISABLE_GRAPHS` disables whole-plan
|
|
||||||
capture as well as native CUDA Graph caching. Native operations that cannot be
|
|
||||||
captured retain the existing fragment execution path. Whole-plan replay requires
|
|
||||||
CUDA VMM so native scratch addresses remain valid for the backend lifetime;
|
|
||||||
legacy scratch pools retain the existing fragment path. HIP and MUSA do not yet
|
|
||||||
provide this plan executor. sd.cpp's CUDA registrations opt in to reusable replay.
|
|
||||||
|
|
||||||
## Vulkan execution services
|
|
||||||
|
|
||||||
`ggml-ext-vulkan.h` exposes `ggml_ext_vulkan_v1` through the Vulkan backend
|
|
||||||
registry. The versioned function table reports device limits and subgroup
|
|
||||||
capabilities, resolves tensor/workspace byte ranges, dispatches application
|
|
||||||
SPIR-V, and copies nonoverlapping buffer ranges. Extensions do not include
|
|
||||||
private ggml Vulkan headers or own backend command buffers and descriptors.
|
|
||||||
|
|
||||||
Shaders use the `main` entry point, consecutive storage-buffer bindings starting
|
|
||||||
at zero, and consecutive 32-bit specialization constants. Dispatch accepts actual
|
|
||||||
workgroup counts. The backend validates ranges and dispatch limits, caches the
|
|
||||||
complete shader/configuration per device, and releases pipelines with that
|
|
||||||
device. Push constants and specialization values are copied; the backend does
|
|
||||||
not retain application execution state. Pipeline creation occurs on execution,
|
|
||||||
never during host-only plan preparation.
|
|
||||||
|
|
||||||
Bindings identify either a tensor or a backend buffer, with a byte offset and
|
|
||||||
optional byte count. `buffer_info` returns an opaque storage identity and byte
|
|
||||||
range for alias checks. Vulkan descriptor offsets are rounded down to the
|
|
||||||
device's required alignment; shaders must add the returned `shader_offset`.
|
|
||||||
Workspace bindings follow the same rules. Invalid or foreign-device ranges are
|
|
||||||
rejected before recording commands. Kernel bounds and shader capability
|
|
||||||
requirements remain the extension's responsibility.
|
|
||||||
|
|
||||||
Dispatch and copy use the backend's existing compute command context, descriptor
|
|
||||||
pool, transfer waits, and memory barriers. They preserve ordering with native
|
|
||||||
fragments and invalidate cached converted operands after writes. Normal backend
|
|
||||||
synchronization completes queued work before host access or resource release.
|
|
||||||
Vulkan copy ranges must be equal in size, nonoverlapping, and aligned to four
|
|
||||||
bytes. There is no per-dispatch host wait or extension-owned queue.
|
|
||||||
|
|
||||||
Scheduled Vulkan plans share submission counters and FLOP thresholds across
|
|
||||||
native fragments and extension callbacks. Native scratch is initialized once
|
|
||||||
per plan invocation, with its offsets retained across fragments. Fragment
|
|
||||||
boundaries do not force a
|
|
||||||
queue submission, and the final pending commands are submitted when the plan
|
|
||||||
returns. Extension dispatches and copies count toward the device's node limit.
|
|
||||||
Every callback still executes on every invocation; this batching neither
|
|
||||||
captures device replay nor retains plan state across scheduler rebuilds.
|
|
||||||
Callback errors propagate without retry. Evaluation callbacks, direct backend
|
|
||||||
calls, synchronous devices, serialized diagnostics, and timestamp profiling
|
|
||||||
retain fragment execution.
|
|
||||||
|
|
||||||
`src/core/vulkan/rope.cpp` registers the custom RoPE implementation,
|
|
||||||
plus `RMSNorm -> Mul -> RoPE` and `RMSNorm -> Mul -> RoPE -> Scale -> FP16 Copy`
|
|
||||||
fusion. These kernels retain the original strides, partial-rotation behavior,
|
|
||||||
128-channel subgroup reduction, and separate arithmetic rounding. Their SPIR-V
|
|
||||||
is generated from application shaders with the native RoPE compilation policy;
|
|
||||||
SPIR-V optimization is disabled because it changes the reduction results.
|
|
||||||
Safe graph-delay rules bring independent producers ahead of fusion candidates.
|
|
||||||
External intermediate consumers retain ordinary operators, and overlapping
|
|
||||||
outputs use plan workspace. `GGML_VK_DISABLE_FUSION` is honored.
|
|
||||||
|
|
||||||
The corresponding Vulkan shader sources and native fusion rules have been
|
|
||||||
removed from ggml. Unsupported custom nodes retain scheduler fallback to
|
|
||||||
another supported backend.
|
|
||||||
|
|
||||||
RoPE Apply, INT8/ConvRot, CuTe attention, SageAttention, and Sol-Attn use
|
|
||||||
application-owned implementations. This interface does not add dynamic dtypes.
|
|
||||||
|
|
||||||
`src/core/vulkan/int8.cpp` owns Vulkan INT8 GEMM, ConvRot, and their fusion rules.
|
|
||||||
The Vulkan compute metadata service exposes shared-memory limits, subgroup
|
|
||||||
arithmetic, and cooperative-matrix properties; shape selection stays in sd.cpp.
|
|
||||||
Shader variants preserve the former tiling and compilation policy, including
|
|
||||||
SwiGLU, residual, row-concatenation, and modulation paths. Kernels use public
|
|
||||||
Vulkan dispatch, buffer, copy, and workspace services without private backend
|
|
||||||
headers. Vulkan currently handles packed group-256 activations with separate
|
|
||||||
weight scales; unsupported custom nodes fall back to CPU.
|
|
||||||
|
|
||||||
## SageAttention
|
|
||||||
|
|
||||||
The `ggml_ext_sage_attn` entry point is declared and implemented in sd.cpp's
|
|
||||||
graph construction helpers. It constructs `sd.sage_attn.v1` with explicit Q/K/V inputs
|
|
||||||
and scale/mode attributes. ggml has no Sage-specific opcode, allocation rule, or
|
|
||||||
backend dispatch branch.
|
|
||||||
|
|
||||||
`src/core/cuda/sage_attention.cu` and its `sageattention/` device headers own the
|
|
||||||
CUDA implementation. Quantization and temporary attention output use scheduler
|
|
||||||
workspace, rather than an oversized output tensor. The implementation obtains
|
|
||||||
the backend stream through the public GPU service and converts the final FP16
|
|
||||||
output with a local CUDA kernel. It retains the SM80 compatibility path and the
|
|
||||||
SageAttention2/2++ toolkit and architecture requirements. Capability checks use
|
|
||||||
the application's compiled CUDA target as well as the physical device.
|
|
||||||
|
|
||||||
CPU, HIP, MUSA, and Vulkan do not implement this NVIDIA-specific kernel. Existing
|
|
||||||
model-level capability checks retain flash/default attention for unsupported
|
|
||||||
layers; a custom Sage node itself does not silently change algorithms.
|
|
||||||
|
|
||||||
## Sol-Attn
|
|
||||||
|
|
||||||
The `ggml_ext_sol_attn` entry point lives in the common sd.cpp graph construction
|
|
||||||
files and constructs `sd.sol_attn.v1`. It accepts contiguous F32 Q/K/V tensors
|
|
||||||
with shape `[128, tokens, heads, batch]`, a positive finite scale, and finite tau.
|
|
||||||
The output remains F32 `[128, heads, tokens, batch]`. No current sd.cpp model or
|
|
||||||
CLI path calls this entry point; the migration preserves its low-level behavior.
|
|
||||||
|
|
||||||
`src/core/cuda/sol_attention.cu` owns packing, block summaries, threshold
|
|
||||||
selection, and the BF16 tensor-core kernel. Temporary storage is separate
|
|
||||||
scheduler workspace, so the output allocation contains only the output tensor.
|
|
||||||
The kernel uses the public backend stream service and direct CUDA/PTX operations.
|
|
||||||
Registration requires CUDA 12 or newer, an SM80-or-newer device, and an application
|
|
||||||
kernel compiled for SM80 or newer. CPU, HIP, MUSA, and Vulkan do not advertise
|
|
||||||
support. ggml no longer contains a Sol-Attn opcode, constructor, allocation rule,
|
|
||||||
or backend kernel.
|
|
||||||
|
|
||||||
## Public graph access
|
|
||||||
|
|
||||||
`ggml-graph.h` exposes leaf enumeration, append-only leaf construction, recorded
|
|
||||||
use counts, mapped inference-graph copying, use-count copying for segments, and
|
|
||||||
backend execution of a node range. Mapped copies retain node order and consumer
|
|
||||||
counts from the original graph, including consumers outside a graph view. The
|
|
||||||
caller owns tensor copies and remaps their storage and edges; invalid mappings
|
|
||||||
leave the destination graph unchanged. Range execution uses already allocated
|
|
||||||
tensors and retains the original graph's consumer counts.
|
|
||||||
|
|
||||||
Workspace measurement, graph cuts, and evaluation callbacks use these APIs.
|
|
||||||
Normal sd.cpp builds require only ggml's public headers. Compatibility with an
|
|
||||||
upstream ggml lacking this header is isolated in `src/core/ggml_compat.cpp`; that
|
|
||||||
optional build still requires matching upstream private headers. The compatibility
|
|
||||||
layer also retains the workaround for old Metal backends wrapping failed host
|
|
||||||
mappings. The patched Metal backend returns null directly when mapping fails.
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
# PuLID implementation and validation
|
|
||||||
|
|
||||||
For model files, identity preparation, and generation commands, see the
|
|
||||||
[PuLID usage guide](../models/pulid.md).
|
|
||||||
|
|
||||||
## Architecture summary
|
|
||||||
|
|
||||||
The PuLID-Flux contribution to the Flux denoise loop is a stack of 20
|
|
||||||
small cross-attention modules (`PerceiverAttentionCA`) inserted between
|
|
||||||
the Flux transformer blocks:
|
|
||||||
|
|
||||||
- After every 2nd of the 19 double-stream blocks (10 hook points)
|
|
||||||
- After every 4th of the 38 single-stream blocks (10 hook points)
|
|
||||||
|
|
||||||
Each cross-attention layer takes the current image tokens as query, the
|
|
||||||
32-token / 2048-dim identity embedding as key+value, and adds its output
|
|
||||||
(scaled by `id_weight`, typically 1.0) back to the image tokens.
|
|
||||||
|
|
||||||
## Format (gguf)
|
|
||||||
|
|
||||||
The embedding is a standard **gguf** container holding a single tensor:
|
|
||||||
|
|
||||||
```
|
|
||||||
tensor name : "pulid_id"
|
|
||||||
shape : [token_dim, num_tokens] (ggml order; typically [2048, 32])
|
|
||||||
type : F16 (also accepts F32 / BF16)
|
|
||||||
metadata : general.architecture = "pulid", pulid.version = 1
|
|
||||||
```
|
|
||||||
|
|
||||||
stable-diffusion.cpp loads it with the normal gguf reader
|
|
||||||
(`gguf_init_from_file`) and converts to fp32 at load time -- no bespoke
|
|
||||||
parser. Total file size for the typical (32, 2048, fp16) case is ~131 KB.
|
|
||||||
|
|
||||||
## Verification
|
|
||||||
|
|
||||||
A three-way SHA-256 check is the recommended sanity test when bringing up
|
|
||||||
a new combination of model + backend + hardware:
|
|
||||||
|
|
||||||
| Run | Expected hash relation |
|
|
||||||
|----------------------------------------------|------------------------------------|
|
|
||||||
| A: DGL condition without `pulid::apply` | baseline |
|
|
||||||
| B: same script with `pulid::apply(..., strength = 0)` | **byte-identical to A** |
|
|
||||||
| C: same script with `pulid::apply(..., strength = 1)` | **different from A,B**, preserves source identity |
|
|
||||||
|
|
||||||
If A and C differ but A and B differ too, the injection is allocating
|
|
||||||
or computing something even at zero weight -- likely a bug.
|
|
||||||
|
|
@ -1,32 +0,0 @@
|
||||||
# Qwen Image 2.1 prefix cache
|
|
||||||
|
|
||||||
For cache options and memory estimates, see the
|
|
||||||
[Qwen Image 2.1 usage guide](../models/qwen_image_2.1.md#prefix-cache).
|
|
||||||
|
|
||||||
## Cache behavior
|
|
||||||
|
|
||||||
By default, the first denoising call for each fixed condition saves the text and reference-image keys and values from every transformer layer. Later calls only compute the target-image tokens. Positive and negative conditions use separate caches, which are released when sampling ends.
|
|
||||||
|
|
||||||
Set `qwen_image_2_1_prefix_cache_type` in `--model-args` to `auto` or a type name using the same parser and case-sensitive names as `--type`:
|
|
||||||
|
|
||||||
- `auto` (default): use FP16 only when Flash Attention is enabled, Sage Attention is disabled, the attention scale is unchanged, and every attention operation in the cache-writing or cache-reading graph selects Flash Attention after backend support checks. If an operation falls back, rebuild the prefix in FP32 before executing and keep FP32 for the rest of that sampling run.
|
|
||||||
- `f32`: always store FP32 keys and values.
|
|
||||||
- `f16`: always store FP16 keys and values, including with ordinary attention or custom attention scaling. This saves cache memory but can introduce additional rounding error.
|
|
||||||
- Other types, such as `bf16`, `q4_1`, `q5_0`, `q5_1`, `q8_0`, `q4_K`, `q6_K`, `iq4_nl`, and `iq4_xs`: use the requested storage type if the ggml build provides runtime conversion to and from FP32. Quantization is lossy and must be selected explicitly; `auto` never selects a quantized type.
|
|
||||||
|
|
||||||
Cache data is packed into contiguous rows of `hidden_size` elements before conversion, so 256-element quantization blocks work with the model's 128-element attention heads without padding. The type's block size must divide `hidden_size`. Unknown types, types lacking runtime conversion (for example `q8_1` and several IQ formats), and incompatible block sizes are ignored with a warning, leaving the previous setting or the default `auto` unchanged.
|
|
||||||
|
|
||||||
For example, use `--model-args qwen_image_2_1_prefix_cache_type=q8_0` to enable 8-bit cache storage. Cached keys and values are converted back to the attention input type before concatenating with the current target tokens. This reduces persistent cache memory; attention working buffers still use floating-point values, and conversion adds work on each step. Backends without the required conversion operations use the existing CPU fallback.
|
|
||||||
|
|
||||||
For the default 32-layer model, a prefix of 4096 tokens takes approximately the following memory per condition, excluding weights, working buffers, and allocation overhead:
|
|
||||||
|
|
||||||
| Cache type | Memory |
|
|
||||||
| --- | ---: |
|
|
||||||
| `f32` | 4 GiB |
|
|
||||||
| `f16` | 2 GiB |
|
|
||||||
| `q8_0` | 1.0625 GiB |
|
|
||||||
| `q4_0` | 0.5625 GiB |
|
|
||||||
|
|
||||||
The runner accounts for the cache when checking the memory budget. If a cached execution runs out of memory, it releases the prefix caches, disables caching for the rest of that sampling run, and retries the full sequence once. Per-step conditioning extensions currently use the full-sequence path.
|
|
||||||
|
|
||||||
Disable this optimization with `--model-args qwen_image_2_1_prefix_cache=false`. It reuses step-independent activations; numerical results can still differ slightly because the matrix sizes change.
|
|
||||||
|
|
@ -1,215 +0,0 @@
|
||||||
<!-- Generated by sd-cli -M dgl. Update with the dgl-update-builtins CMake target. -->
|
|
||||||
# Built-in DGL functions
|
|
||||||
|
|
||||||
Optional parameters are marked with `?`. Default values follow `=`. See [DGL syntax](dgl.md#dgl-syntax) for `fn`, `map` and `fold`.
|
|
||||||
|
|
||||||
| Function | Parameters | Returns |
|
|
||||||
|---|---|---|
|
|
||||||
| `add_noise` | `predict: predictor`, `base: tensor`, `noise: tensor`, `sigma: number` | `tensor` |
|
|
||||||
| `animatediff::apply` | `model: denoiser`, `motion: animatediff` | `denoiser` |
|
|
||||||
| `animatediff::load` (resource) | `path: string`, `family?: string = "auto"`, `wtype?: string = "auto"`, `conv_scale?: number = 0`, `linear_scale?: number = 0`, `attn_scale?: number = 0`, `backend?: string = ""`, `params_backend?: string = ""`, `split_mode?: string = ""`, `model_args?: string = ""`, `tensor_type_rules?: string = ""`, `flash_attn_mode?: string = "auto"`, `conv_direct_mode?: string = "auto"`, `sage_attn?: bool = false` | `animatediff` |
|
|
||||||
| `apg` | `positive: predictor`, `negative: predictor`, `scale: number`, `image_only?: predictor`, `image_scale?: number = 1`, `schedule?: list<number>`, `eta?: number = 1`, `momentum?: number = 0`, `norm_threshold?: number = 0`, `norm_threshold_smoothing?: number = 0` | `predictor` |
|
|
||||||
| `apply_lora` | `model: model`, `lora: lora`, `weight?: number = 1.0`, `mode?: string` | same type as `model` |
|
|
||||||
| `audio::load` | `path: string` | `dict`<br>`sample_rate: int`<br>`samples: tensor` |
|
|
||||||
| `audio::save` | `path: string`, `audio: dict`, `format?: string = "f32"` | `void` |
|
|
||||||
| `audio_latent_shape` | `vae: audio_vae`, `frames: int`, `fps: int` | `tensor` |
|
|
||||||
| `audio_vae_decode` | `vae: audio_vae`, `latent: tensor` | `dict`<br>`sample_rate: int`<br>`samples: tensor` |
|
|
||||||
| `audio_vae_encode` | `vae: audio_vae`, `samples: tensor`, `sample_rate: int` | `tensor` |
|
|
||||||
| `cache` | `mode?: string = "disabled"`, `reuse_threshold?: number`, `start_percent?: number`, `end_percent?: number`, `error_decay_rate?: number`, `use_relative_threshold?: bool`, `reset_error_on_compute?: bool`, `residual_diff_threshold?: number`, `max_warmup_steps?: int`, `max_cached_steps?: int`, `max_continuous_cached_steps?: int`, `taylorseer_n_derivatives?: int`, `taylorseer_skip_interval?: int`, `scm_mask?: string`, `spectrum_w?: number`, `spectrum_m?: int`, `spectrum_lam?: number`, `spectrum_window_size?: int`, `spectrum_flex_window?: number`, `spectrum_warmup_steps?: int`, `spectrum_stop_percent?: number` | `dict`<br>`end_percent: number`<br>`error_decay_rate: number`<br>`max_cached_steps: int`<br>`max_continuous_cached_steps: int`<br>`max_warmup_steps: int`<br>`mode: string`<br>`reset_error_on_compute: bool`<br>`residual_diff_threshold: number`<br>`reuse_threshold: number`<br>`scm_mask: string`<br>`spectrum_flex_window: number`<br>`spectrum_lam: number`<br>`spectrum_m: int`<br>`spectrum_stop_percent: number`<br>`spectrum_w: number`<br>`spectrum_warmup_steps: int`<br>`spectrum_window_size: int`<br>`start_percent: number`<br>`taylorseer_n_derivatives: int`<br>`taylorseer_skip_interval: int`<br>`use_relative_threshold: bool` |
|
|
||||||
| `cfg` | `positive: predictor`, `negative: predictor`, `scale: number`, `image_only?: predictor`, `image_scale?: number = 1`, `schedule?: list<number>` | `predictor` |
|
|
||||||
| `controlnet::apply` | `condition: dict`, `model: control_net`, `hint: tensor`, `strength?: number = 1`, `start_sigma?: number`, `end_sigma?: number`, `type?: string = "none"` | same type as `condition`<br>`controls: control_bindings` |
|
|
||||||
| `controlnet::load` (resource) | `path: string`, `family?: string = "auto"`, `wtype?: string = "auto"`, `conv_scale?: number = 0`, `linear_scale?: number = 0`, `attn_scale?: number = 0`, `backend?: string = ""`, `params_backend?: string = ""`, `split_mode?: string = ""`, `model_args?: string = ""`, `tensor_type_rules?: string = ""`, `flash_attn_mode?: string = "auto"`, `conv_direct_mode?: string = "auto"`, `sage_attn?: bool = false` | `control_net` |
|
|
||||||
| `denoiser_scalings` | `predict: predictor`, `sigma: number` | `dict`<br>`input_scale: number`<br>`output_scale: number`<br>`skip_scale: number` |
|
|
||||||
| `detections::box_masks` | `image: tensor`, `detections: dict` | `list<tensor>` |
|
|
||||||
| `detections::detect` | `detector: detector`, `image: tensor`, `input_size?: int = 640`, `confidence?: number = 0.3`, `nms?: number = 0.45`, `max_detections?: int = 100` | `dict`<br>`class_ids: tensor`<br>`scores: tensor`<br>`xyxy: tensor` |
|
|
||||||
| `detections::filter` | `image: tensor`, `detections: dict`, `top_k?: int = 0`, `top_k_by?: string = "area"`, `min_area_ratio?: number = 0`, `max_area_ratio?: number = 1`, `sort_by?: string = "none"` | `dict`<br>`class_ids: tensor`<br>`scores: tensor`<br>`xyxy: tensor` |
|
|
||||||
| `detections::to_regions` | `image: tensor`, `detections: dict` | `dict`<br>`boxes: tensor`<br>`height: int`<br>`width: int` |
|
|
||||||
| `dit_to_vae_latents` | `vae: vae`, `latent: tensor` | `tensor` |
|
|
||||||
| `encode_audio` | `encoder: audio_encoder`, `samples: tensor`, `sample_rate: int` | `tensor` |
|
|
||||||
| `encode_prompt` | `encoder: text_encoder`, `text: string`, `width?: int = 512`, `height?: int = 512`, `clip_skip?: int = -1`, `system?: string`, `media?: list<any>`, `image_bindings?: dict`, `raw?: bool = false` | `dict`<br>`concat: tensor`<br>`crossattn: tensor`<br>`extra_crossattn: list<tensor>`<br>`image_embed_indices: list<tensor>`<br>`image_embeds: list<tensor>`<br>`input_ids: tensor`<br>`position_ids: tensor`<br>`ref_audios: list<tensor>`<br>`ref_images: list<tensor>`<br>`reference_blocks: list<dict>`<br>`reference_blocks.audio: int`<br>`reference_blocks.kind: string`<br>`reference_blocks.video: int`<br>`t5_ids: tensor`<br>`t5_weights: tensor`<br>`token_types: tensor`<br>`vector: tensor`<br>`vinput_mask: tensor` |
|
|
||||||
| `encode_vision` | `encoder: vision_encoder`, `image: tensor`, `pooled?: bool = false`, `clip_skip?: int = -2`, `zero?: bool = false`, `zero_input?: bool = false` | `tensor` |
|
|
||||||
| `image::canny` | `image: tensor`, `high_threshold?: number = 0.08`, `low_threshold?: number = 0.04`, `weak?: number = 0.5`, `strong?: number = 1`, `invert?: bool = false` | `tensor` |
|
|
||||||
| `image::encode` | `image: tensor`, `format?: string = "png"` | `dict`<br>`data: bytes`<br>`mime_type: string` |
|
|
||||||
| `image::load` | `path: string` | `tensor` |
|
|
||||||
| `image::load_dir` | `path: string`, `max_images?: int = 0` | `list<tensor>` |
|
|
||||||
| `image::save` | `path: string`, `image: tensor` | `void` |
|
|
||||||
| `image::to_f32` | `image: tensor`, `channels?: int = 0` | `tensor` |
|
|
||||||
| `image::to_u8` | `pixels: tensor` | `tensor` |
|
|
||||||
| `ip_adapter::apply` | `condition: dict`, `adapter: ip_adapter`, `tokens: tensor`, `strength?: number = 1`, `start_sigma?: number`, `end_sigma?: number` | same type as `condition`<br>`ip_adapters: ip_adapter_bindings` |
|
|
||||||
| `ip_adapter::load` (resource) | `path: string`, `family?: string = "auto"`, `wtype?: string = "auto"`, `conv_scale?: number = 0`, `linear_scale?: number = 0`, `attn_scale?: number = 0`, `backend?: string = ""`, `params_backend?: string = ""`, `split_mode?: string = ""`, `model_args?: string = ""`, `tensor_type_rules?: string = ""`, `flash_attn_mode?: string = "auto"`, `conv_direct_mode?: string = "auto"`, `sage_attn?: bool = false` | `ip_adapter` |
|
|
||||||
| `ip_adapter::project` | `adapter: ip_adapter`, `embedding: tensor` | `tensor` |
|
|
||||||
| `latent_shape` | `vae: vae`, `width: int`, `height: int`, `batch?: int = 1`, `frames?: int` | `tensor` |
|
|
||||||
| `list::replace` | `items: list<any>`, `index: int`, `value: any` | `list<any>` |
|
|
||||||
| `load_audio_encoder` (resource) | `path: string`, `family?: string = "auto"`, `wtype?: string = "auto"`, `conv_scale?: number = 0`, `linear_scale?: number = 0`, `attn_scale?: number = 0`, `backend?: string = ""`, `params_backend?: string = ""`, `split_mode?: string = ""`, `model_args?: string = ""`, `tensor_type_rules?: string = ""`, `flash_attn_mode?: string = "auto"`, `conv_direct_mode?: string = "auto"`, `sage_attn?: bool = false` | `audio_encoder` |
|
|
||||||
| `load_audio_vae` (resource) | `path: string`, `family?: string = "auto"`, `wtype?: string = "auto"`, `conv_scale?: number = 0`, `linear_scale?: number = 0`, `attn_scale?: number = 0`, `backend?: string = ""`, `params_backend?: string = ""`, `split_mode?: string = ""`, `model_args?: string = ""`, `tensor_type_rules?: string = ""`, `flash_attn_mode?: string = "auto"`, `conv_direct_mode?: string = "auto"`, `sage_attn?: bool = false`, `family_from?: string = ""` | `audio_vae` |
|
|
||||||
| `load_detector` (resource) | `path: string`, `backend?: string = ""`, `params_backend?: string = ""` | `detector` |
|
|
||||||
| `load_dit` (resource) | `path: string`, `family?: string = "auto"`, `wtype?: string = "auto"`, `conv_scale?: number = 0`, `linear_scale?: number = 0`, `attn_scale?: number = 0`, `backend?: string = ""`, `params_backend?: string = ""`, `split_mode?: string = ""`, `model_args?: string = ""`, `tensor_type_rules?: string = ""`, `flash_attn_mode?: string = "auto"`, `conv_direct_mode?: string = "auto"`, `sage_attn?: bool = false` | `denoiser` |
|
|
||||||
| `load_latent_upscaler` (resource) | `path: string`, `family?: string = "auto"`, `wtype?: string = "auto"`, `conv_scale?: number = 0`, `linear_scale?: number = 0`, `attn_scale?: number = 0`, `backend?: string = ""`, `params_backend?: string = ""`, `split_mode?: string = ""`, `model_args?: string = ""`, `tensor_type_rules?: string = ""`, `flash_attn_mode?: string = "auto"`, `conv_direct_mode?: string = "auto"`, `sage_attn?: bool = false` | `latent_upscaler` |
|
|
||||||
| `load_lora` (resource) | `path: string` | `lora` |
|
|
||||||
| `load_tae` (resource) | `path: string`, `family?: string = "auto"`, `wtype?: string = "auto"`, `conv_scale?: number = 0`, `linear_scale?: number = 0`, `attn_scale?: number = 0`, `backend?: string = ""`, `params_backend?: string = ""`, `split_mode?: string = ""`, `model_args?: string = ""`, `tensor_type_rules?: string = ""`, `flash_attn_mode?: string = "auto"`, `conv_direct_mode?: string = "auto"`, `sage_attn?: bool = false`, `family_from?: string = ""`, `decode_only?: bool = false` | `vae` |
|
|
||||||
| `load_text_encoder` (resource) | `path: string`, `family?: string = "auto"`, `wtype?: string = "auto"`, `conv_scale?: number = 0`, `linear_scale?: number = 0`, `attn_scale?: number = 0`, `backend?: string = ""`, `params_backend?: string = ""`, `split_mode?: string = ""`, `model_args?: string = ""`, `tensor_type_rules?: string = ""`, `flash_attn_mode?: string = "auto"`, `conv_direct_mode?: string = "auto"`, `sage_attn?: bool = false`, `family_from?: string = ""`, `tokenizer?: string = ""`, `vision_path?: string = ""`, `projection_path?: string = ""`, `connectors_path?: string = ""`, `t5_path?: string = ""`, `clip_l_path?: string = ""`, `clip_g_path?: string = ""` | `text_encoder` |
|
|
||||||
| `load_unet` (resource) (alias of `load_dit`) | `path: string`, `family?: string = "auto"`, `wtype?: string = "auto"`, `conv_scale?: number = 0`, `linear_scale?: number = 0`, `attn_scale?: number = 0`, `backend?: string = ""`, `params_backend?: string = ""`, `split_mode?: string = ""`, `model_args?: string = ""`, `tensor_type_rules?: string = ""`, `flash_attn_mode?: string = "auto"`, `conv_direct_mode?: string = "auto"`, `sage_attn?: bool = false` | `denoiser` |
|
|
||||||
| `load_upscaler` (resource) | `path: string`, `tile_size?: int = 128`, `backend?: string = ""`, `params_backend?: string = ""`, `direct?: bool = false` | `upscaler` |
|
|
||||||
| `load_vae` (resource) | `path: string`, `family?: string = "auto"`, `wtype?: string = "auto"`, `conv_scale?: number = 0`, `linear_scale?: number = 0`, `attn_scale?: number = 0`, `backend?: string = ""`, `params_backend?: string = ""`, `split_mode?: string = ""`, `model_args?: string = ""`, `tensor_type_rules?: string = ""`, `flash_attn_mode?: string = "auto"`, `conv_direct_mode?: string = "auto"`, `sage_attn?: bool = false`, `family_from?: string = ""`, `vae_format?: string = "auto"` | `vae` |
|
|
||||||
| `load_vision_encoder` (resource) | `path: string`, `family?: string = "auto"`, `wtype?: string = "auto"`, `conv_scale?: number = 0`, `linear_scale?: number = 0`, `attn_scale?: number = 0`, `backend?: string = ""`, `params_backend?: string = ""`, `split_mode?: string = ""`, `model_args?: string = ""`, `tensor_type_rules?: string = ""`, `flash_attn_mode?: string = "auto"`, `conv_direct_mode?: string = "auto"`, `sage_attn?: bool = false` | `vision_encoder` |
|
|
||||||
| `ltx::video_positions` | `like: tensor`, `keyframe_latent_frames: int`, `keyframe_frame_index: int`, `keyframe_pixel_frames: int`, `fps?: int = 24`, `spatial_scale?: int = 32`, `temporal_scale?: int = 8`, `causal?: bool = true` | `tensor` |
|
|
||||||
| `make_rng` | `algorithm?: string = "cuda"`, `seed?: int = 0` | `rng` |
|
|
||||||
| `make_sigmas` | `predict: predictor`, `latent: tensor`, `scheduler?: string = "discrete"`, `steps: int`, `flow_shift?: number = 0`, `sequence_length?: int`, `extra_args?: string = ""` | `tensor` |
|
|
||||||
| `math::add` | `a: number`, `b: number` | `number` |
|
|
||||||
| `math::ceil` | `value: number` | `int` |
|
|
||||||
| `math::ceil_div` | `numerator: int`, `denominator: int` | `int` |
|
|
||||||
| `math::div` | `a: number`, `b: number` | `number` |
|
|
||||||
| `math::floor` | `value: number` | `int` |
|
|
||||||
| `math::min` | `a: int`, `b: int` | `int` |
|
|
||||||
| `math::mul` | `a: number`, `b: number` | `number` |
|
|
||||||
| `math::product` | `items: i64 tensor or list<int>` | `int` |
|
|
||||||
| `math::round` | `value: number` | `int` |
|
|
||||||
| `math::sub` | `a: number`, `b: number` | `number` |
|
|
||||||
| `media::save` | `path: string`, `media: dict` | `void` |
|
|
||||||
| `photomaker::apply` | `condition: dict`, `photomaker: photomaker`, `tokens: tensor`, `mask: tensor` | same type as `condition`<br>`crossattn: tensor` |
|
|
||||||
| `photomaker::encode_images` | `photomaker: photomaker`, `images: list<tensor>`, `id_embedding?: tensor` | `tensor` |
|
|
||||||
| `photomaker::encode_prompt` | `encoder: text_encoder`, `text: string`, `tokens: tensor`, `width?: int = 1024`, `height?: int = 1024`, `clip_skip?: int = -1` | `dict`<br>`condition: dict`<br>`condition.concat: tensor`<br>`condition.crossattn: tensor`<br>`condition.extra_crossattn: list<tensor>`<br>`condition.image_embed_indices: list<tensor>`<br>`condition.image_embeds: list<tensor>`<br>`condition.input_ids: tensor`<br>`condition.position_ids: tensor`<br>`condition.ref_audios: list<tensor>`<br>`condition.ref_images: list<tensor>`<br>`condition.reference_blocks: list<dict>`<br>`condition.reference_blocks.audio: int`<br>`condition.reference_blocks.kind: string`<br>`condition.reference_blocks.video: int`<br>`condition.t5_ids: tensor`<br>`condition.t5_weights: tensor`<br>`condition.token_types: tensor`<br>`condition.vector: tensor`<br>`condition.vinput_mask: tensor`<br>`mask: tensor`<br>`plain: dict`<br>`plain.concat: tensor`<br>`plain.crossattn: tensor`<br>`plain.extra_crossattn: list<tensor>`<br>`plain.image_embed_indices: list<tensor>`<br>`plain.image_embeds: list<tensor>`<br>`plain.input_ids: tensor`<br>`plain.position_ids: tensor`<br>`plain.ref_audios: list<tensor>`<br>`plain.ref_images: list<tensor>`<br>`plain.reference_blocks: list<dict>`<br>`plain.reference_blocks.audio: int`<br>`plain.reference_blocks.kind: string`<br>`plain.reference_blocks.video: int`<br>`plain.t5_ids: tensor`<br>`plain.t5_weights: tensor`<br>`plain.token_types: tensor`<br>`plain.vector: tensor`<br>`plain.vinput_mask: tensor` |
|
|
||||||
| `photomaker::load` (resource) | `path: string`, `family?: string = "auto"`, `wtype?: string = "auto"`, `conv_scale?: number = 0`, `linear_scale?: number = 0`, `attn_scale?: number = 0`, `backend?: string = ""`, `params_backend?: string = ""`, `split_mode?: string = ""`, `model_args?: string = ""`, `tensor_type_rules?: string = ""`, `flash_attn_mode?: string = "auto"`, `conv_direct_mode?: string = "auto"`, `sage_attn?: bool = false` | `photomaker` |
|
|
||||||
| `predictor` | `model: denoiser`, `condition: dict`, `prediction?: string = "auto"`, `concat?: tensor`, `ref_latents?: list<tensor>`, `ref_audios?: list<tensor>`, `reference_blocks?: list<dict>`, `keyframe_indices?: list<int>`, `ref_index_mode?: string = "fixed"`, `force_ref_timestep_zero?: bool = false`, `ref_rope_anchor?: string = "default"`, `guidance?: number = 3.5`, `skip_layers?: list<int>`, `vace_context?: tensor`, `vace_strength?: number = 1`, `audio_embedding?: tensor`, `video_positions?: tensor`, `audio_length?: int = 0`, `fps?: number = 24`, `video_sigma_shift?: number = 12`, `audio_sigma_shift?: number = 3`, `circular_x?: bool = false`, `circular_y?: bool = false`, `transform?: fn`, `transform_args?: dict` | `predictor` |
|
|
||||||
| `preview` | `decoder?: vae`, `circular_x?: bool = false`, `circular_y?: bool = false` | `sampling_observer` |
|
|
||||||
| `pulid::apply` | `condition: dict`, `pulid: pulid`, `embedding: tensor`, `strength?: number = 1`, `start_sigma?: number`, `end_sigma?: number` | same type as `condition`<br>`pulid: pulid_bindings` |
|
|
||||||
| `pulid::load` (resource) | `path: string`, `family?: string = "auto"`, `wtype?: string = "auto"`, `conv_scale?: number = 0`, `linear_scale?: number = 0`, `attn_scale?: number = 0`, `backend?: string = ""`, `params_backend?: string = ""`, `split_mode?: string = ""`, `model_args?: string = ""`, `tensor_type_rules?: string = ""`, `flash_attn_mode?: string = "auto"`, `conv_direct_mode?: string = "auto"`, `sage_attn?: bool = false` | `pulid` |
|
|
||||||
| `pulid::load_embedding` | `path: string` | `tensor` |
|
|
||||||
| `regions::crop` | `image: tensor`, `regions: dict` | `list<tensor>` |
|
|
||||||
| `regions::from_boxes` | `width: int`, `height: int`, `boxes: any` | `dict`<br>`boxes: tensor`<br>`height: int`<br>`width: int` |
|
|
||||||
| `regions::paste` | `background: tensor`, `foregrounds: list<tensor>`, `regions: dict` | `tensor` |
|
|
||||||
| `regions::plan_mask_crops` | `masks: list<tensor>`, `aspect?: i64 tensor or list<int> = [1, 1]`, `padding?: int = 32`, `only_masked?: bool = true` | `list<dict>`<br>`box: tensor`<br>`index: int`<br>`mask: tensor` |
|
|
||||||
| `relayvsr::decode` | `flash: vae`, `latent: tensor`, `frames: tensor`, `keyframe_indices: tensor`, `detail?: number = 1` | `tensor` |
|
|
||||||
| `relayvsr::latent_shape` | `dit: denoiser`, `keyframes: tensor` | `tensor` |
|
|
||||||
| `relayvsr::positive_embedding` | `dit: denoiser` | `tensor` |
|
|
||||||
| `sample` | `start: tensor`, `sigmas: tensor`, `predict: predictor`, `rng: rng`, `method?: string = "euler"`, `eta?: number = 1`, `base?: tensor`, `denoise_mask?: tensor`, `mask_input?: bool = false`, `extra_args?: string = ""`, `finish?: bool`, `cache?: dict`, `observer?: sampling_observer` | `tensor` |
|
|
||||||
| `seedvr2::positive_embedding` | `dit: denoiser` | `tensor` |
|
|
||||||
| `sefi::make_sigmas` | `steps: int`, `alpha?: number = 1`, `delta?: number = 0.1` | `dict`<br>`semantic_sigmas: tensor`<br>`sigmas: tensor` |
|
|
||||||
| `sefi::sample` | `start: tensor`, `sigmas: tensor`, `semantic_sigmas: tensor`, `predict: predictor`, `rng: rng`, `method?: string = "euler"`, `eta?: number = 1`, `base?: tensor`, `denoise_mask?: tensor`, `mask_input?: bool = false`, `extra_args?: string = ""`, `finish?: bool`, `cache?: dict`, `observer?: sampling_observer` | `tensor` |
|
|
||||||
| `slg` | `base: predictor`, `positive: predictor`, `skipped: predictor`, `scale: number`, `start_sigma?: number`, `end_sigma?: number`, `start_step_fraction?: number`, `stop_step_fraction?: number` | `predictor` |
|
|
||||||
| `switch_predictor` | `before: predictor`, `after: predictor`, `after_steps: int` | `predictor` |
|
|
||||||
| `t_to_sigma` | `predict: predictor`, `t: number`, `flow_shift?: number = 0`, `latent?: tensor`, `sequence_length?: int` | `number` |
|
|
||||||
| `tensor::add` | `a: any`, `b: any` | `tensor` |
|
|
||||||
| `tensor::affine` | `input: tensor`, `scale?: number = 1`, `offset?: number = 0` | `tensor` |
|
|
||||||
| `tensor::arange` | `start: int`, `end: int`, `step?: int = 1` | `tensor` |
|
|
||||||
| `tensor::broadcast_to` | `input: tensor`, `shape: i64 tensor or list<int>` | `tensor` |
|
|
||||||
| `tensor::cast` | `input: tensor`, `dtype: string` | `tensor` |
|
|
||||||
| `tensor::clamp` | `input: tensor`, `min: number`, `max: number` | `tensor` |
|
|
||||||
| `tensor::concat` | `items: list<tensor>`, `axis: int` | `tensor` |
|
|
||||||
| `tensor::count_nonzero` | `input: tensor` | `int` |
|
|
||||||
| `tensor::crop` | `input: tensor`, `axes: i64 tensor or list<int>`, `start: i64 tensor or list<int>`, `size: i64 tensor or list<int>` | `tensor` |
|
|
||||||
| `tensor::div` | `a: any`, `b: any` | `tensor` |
|
|
||||||
| `tensor::full` | `shape: i64 tensor or list<int>`, `value: number`, `dtype?: string = "f32"` | `tensor` |
|
|
||||||
| `tensor::gaussian_blur` | `input: tensor`, `sigma: number`, `radius: int`, `axes?: i64 tensor or list<int>`, `precision?: string = "auto"` | `tensor` |
|
|
||||||
| `tensor::grayscale` | `input: tensor`, `axis?: int = 0` | `tensor` |
|
|
||||||
| `tensor::index` | `input: tensor`, `indices: list<dict>` | `any` |
|
|
||||||
| `tensor::index_fill` | `input: tensor`, `axis: int`, `indices: i64 tensor or list<int>`, `value: number` | `tensor` |
|
|
||||||
| `tensor::index_select` | `input: tensor`, `axis: int`, `indices: i64 tensor or list<int>` | `tensor` |
|
|
||||||
| `tensor::interpolate` | `input: tensor`, `size: i64 tensor or list<int>`, `axes?: i64 tensor or list<int>`, `mode?: string = "bilinear"`, `antialias?: bool = false` | `tensor` |
|
|
||||||
| `tensor::lerp` | `a: any`, `b: any`, `weight: any` | `tensor` |
|
|
||||||
| `tensor::literal` | `dtype: string`, `shape: i64 tensor or list<int>`, `data: string` | `tensor` |
|
|
||||||
| `tensor::load` | `path: string` | `tensor` |
|
|
||||||
| `tensor::max_pool2d` | `input: tensor`, `kernel: i64 tensor or list<int>`, `axes?: i64 tensor or list<int>`, `stride?: i64 tensor or list<int>`, `padding_before?: i64 tensor or list<int>`, `padding_after?: i64 tensor or list<int>`, `pad_value?: number` | `tensor` |
|
|
||||||
| `tensor::maximum` | `a: tensor`, `b: tensor` | `tensor` |
|
|
||||||
| `tensor::min_pool2d` | `input: tensor`, `kernel: i64 tensor or list<int>`, `axes?: i64 tensor or list<int>`, `stride?: i64 tensor or list<int>`, `padding_before?: i64 tensor or list<int>`, `padding_after?: i64 tensor or list<int>`, `pad_value?: number` | `tensor` |
|
|
||||||
| `tensor::mul` | `a: any`, `b: any` | `tensor` |
|
|
||||||
| `tensor::numel` | `input: tensor` | `int` |
|
|
||||||
| `tensor::pad` | `input: tensor`, `pad: i64 tensor or list<int>`, `mode?: string = "constant"`, `value?: number = 0` | `tensor` |
|
|
||||||
| `tensor::permute` | `input: tensor`, `axes: i64 tensor or list<int>` | `tensor` |
|
|
||||||
| `tensor::randn_like` | `like: tensor`, `rng: rng` | `tensor` |
|
|
||||||
| `tensor::replace_slice` | `input: tensor`, `value: tensor`, `axis: int`, `start: int` | `tensor` |
|
|
||||||
| `tensor::reshape` | `input: tensor`, `shape: i64 tensor or list<int>` | `tensor` |
|
|
||||||
| `tensor::save` | `path: string`, `tensor: tensor` | `void` |
|
|
||||||
| `tensor::shape` | `input: tensor` | `tensor` |
|
|
||||||
| `tensor::threshold` | `input: tensor`, `threshold: number`, `low?: number = 0`, `high?: number = 1` | `tensor` |
|
|
||||||
| `tensor::to_list` | `input: tensor`, `element?: string = "auto"` | `list<any>` |
|
|
||||||
| `tensor::translate` | `input: tensor`, `axes: i64 tensor or list<int>`, `offset: i64 tensor or list<int>`, `value?: number = 0` | `tensor` |
|
|
||||||
| `tensor::unsqueeze` | `input: tensor`, `axis: int` | `tensor` |
|
|
||||||
| `tensor::vector` | `values: list<number>`, `dtype?: string = "f32"` | `tensor` |
|
|
||||||
| `tensor::zeros` | `shape: i64 tensor or list<int>`, `dtype?: string = "f32"` | `tensor` |
|
|
||||||
| `tensor::zeros_like` | `like: tensor` | `tensor` |
|
|
||||||
| `tiling` | `enabled?: bool = true`, `temporal_tiling?: bool = false`, `tile_size_w?: int = 0`, `tile_size_h?: int = 0`, `target_overlap?: number = 0.5`, `rel_size_w?: number = 0`, `rel_size_h?: number = 0`, `extra_args?: string = ""` | `dict`<br>`enabled: bool`<br>`extra_args: string`<br>`rel_size_h: number`<br>`rel_size_w: number`<br>`target_overlap: number`<br>`temporal_tiling: bool`<br>`tile_size_h: int`<br>`tile_size_w: int` |
|
|
||||||
| `unet_to_vae_latents` (alias of `dit_to_vae_latents`) | `vae: vae`, `latent: tensor` | `tensor` |
|
|
||||||
| `upscale` | `upscaler: upscaler`, `image: tensor`, `factor?: int` | `tensor` |
|
|
||||||
| `upscale_latent` | `upscaler: latent_upscaler`, `latent: tensor`, `width?: int`, `height?: int` | `tensor` |
|
|
||||||
| `vae_decode` | `vae: vae`, `latent: tensor`, `tiling?: dict`, `circular_x?: bool = false`, `circular_y?: bool = false`, `dtype?: string = "u8"` | `tensor` |
|
|
||||||
| `vae_encode` | `vae: vae`, `pixels: tensor`, `rng: rng`, `tiling?: dict`, `circular_x?: bool = false`, `circular_y?: bool = false`, `posterior?: string = "sample"` | `tensor` |
|
|
||||||
| `vae_to_dit_latents` | `vae: vae`, `latent: tensor` | `tensor` |
|
|
||||||
| `vae_to_unet_latents` (alias of `vae_to_dit_latents`) | `vae: vae`, `latent: tensor` | `tensor` |
|
|
||||||
| `video::encode` | `video: dict`, `audio?: dict`, `format?: string = "webm"` | `dict`<br>`data: bytes`<br>`mime_type: string` |
|
|
||||||
| `video::join_windows` | `windows: list<tensor>`, `overlap?: int = 0` | `tensor` |
|
|
||||||
| `video::load` | `path: string`, `max_frames?: int = 0`, `fps_num?: int = 0`, `fps_den?: int = 1`, `audio?: bool = true` | `dict`<br>`audio: dict`<br>`audio.sample_rate: int`<br>`audio.samples: tensor`<br>`video: dict`<br>`video.fps_den: int`<br>`video.fps_num: int`<br>`video.frames: tensor` |
|
|
||||||
| `video::save` | `path: string`, `video: dict`, `audio?: dict`, `trim_audio?: bool = false`, `codec?: string = "auto"`, `quality?: int = 90`, `audio_format?: string = "f32"` | `void` |
|
|
||||||
| `video::split_windows` | `frames: tensor`, `size: int`, `overlap?: int = 0` | `list<tensor>` |
|
|
||||||
| `wan::s2v_audio_window` | `embedding: tensor`, `latent_frames: int` | `tensor` |
|
|
||||||
| `zero_out` | `condition: dict`, `fields?: list<string>` | same type as `condition` |
|
|
||||||
|
|
||||||
## Model family IDs
|
|
||||||
|
|
||||||
Pass the ID as the component loader's `family` argument. The default is `"auto"`.
|
|
||||||
|
|
||||||
| ID | Model family |
|
|
||||||
|---|---|
|
|
||||||
| `sd1` | SD 1.x |
|
|
||||||
| `sd1_inpaint` | SD 1.x Inpaint |
|
|
||||||
| `sd1_pix2pix` | Instruct-Pix2Pix |
|
|
||||||
| `sd1_tiny_unet` | SD 1.x Tiny UNet |
|
|
||||||
| `sd2` | SD 2.x |
|
|
||||||
| `sd2_inpaint` | SD 2.x Inpaint |
|
|
||||||
| `sd2_tiny_unet` | SD 2.x Tiny UNet |
|
|
||||||
| `sdxs_512_ds` | SDXS (512-DS) |
|
|
||||||
| `sdxs_09` | SDXS (09) |
|
|
||||||
| `sdxl` | SDXL |
|
|
||||||
| `sdxl_inpaint` | SDXL Inpaint |
|
|
||||||
| `sdxl_pix2pix` | SDXL Instruct-Pix2Pix |
|
|
||||||
| `sdxl_vega` | SDXL (Vega) |
|
|
||||||
| `sdxl_ssd1b` | SDXL (SSD1B) |
|
|
||||||
| `svd` | SVD |
|
|
||||||
| `sd3` | SD3.x |
|
|
||||||
| `flux` | Flux |
|
|
||||||
| `flux_fill` | Flux Fill |
|
|
||||||
| `flux_control` | Flux Control |
|
|
||||||
| `flex2` | Flex.2 |
|
|
||||||
| `chroma_radiance` | Chroma Radiance |
|
|
||||||
| `wan2` | Wan 2.x |
|
|
||||||
| `wan2_2_i2v` | Wan 2.2 I2V |
|
|
||||||
| `wan2_2_ti2v` | Wan 2.2 TI2V |
|
|
||||||
| `wan2_2_s2v` | Wan 2.2 S2V |
|
|
||||||
| `lingbot_video` | LingBot Video |
|
|
||||||
| `qwen_image` | Qwen Image |
|
|
||||||
| `qwen_image_layered` | Qwen Image Layered |
|
|
||||||
| `qwen_image_2_1` | Qwen Image 2.1 |
|
|
||||||
| `hunyuan_video` | Hunyuan Video |
|
|
||||||
| `anima` | Anima |
|
|
||||||
| `flux2` | Flux.2 |
|
|
||||||
| `flux2_klein` | Flux.2 klein |
|
|
||||||
| `ltxav` | LTXAV |
|
|
||||||
| `minimax_h3` | MiniMax-H3 |
|
|
||||||
| `hidream_o1` | HiDream O1 |
|
|
||||||
| `z_image` | Z-Image |
|
|
||||||
| `boogu_image` | Boogu Image |
|
|
||||||
| `ovis_image` | Ovis Image |
|
|
||||||
| `ernie_image` | Ernie Image |
|
|
||||||
| `lens` | Lens |
|
|
||||||
| `minit2i` | MiniT2I |
|
|
||||||
| `longcat_image` | Longcat-Image |
|
|
||||||
| `pid` | PiD |
|
|
||||||
| `ideogram4` | Ideogram 4 |
|
|
||||||
| `sefi_image` | SeFi-Image |
|
|
||||||
| `krea2` | Krea2 |
|
|
||||||
| `mage_flow` | Mage Flow |
|
|
||||||
| `sensenova_u1_5` | SenseNova U1.5 |
|
|
||||||
| `llada_image` | LLaDA-Image |
|
|
||||||
| `esrgan` | ESRGAN |
|
|
||||||
| `pixart` | PixArt |
|
|
||||||
| `ming_image` | Ming-Image |
|
|
||||||
| `z_image_l2p` | Z-Image L2P |
|
|
||||||
| `iris_3b` | Iris-3B |
|
|
||||||
| `flux3_klein` | Flux.3 Image Klein |
|
|
||||||
| `moss_image` | MOSS-Image |
|
|
||||||
| `fibo2` | Fibo-2.0 |
|
|
||||||
| `chroma` | Chroma |
|
|
||||||
| `p_h3_image` | P-H3-Image |
|
|
||||||
| `minimax_h3_image` | MiniMax-H3-Image |
|
|
||||||
| `relayvsr` | RelayVSR |
|
|
||||||
| `seedvr2` | SeedVR2 |
|
|
||||||
1948
docs/dgl.md
1948
docs/dgl.md
File diff suppressed because it is too large
Load diff
|
|
@ -1,116 +0,0 @@
|
||||||
# DGL examples
|
|
||||||
|
|
||||||
Choose a runnable script for [image generation and editing](#image-generation-and-editing),
|
|
||||||
[video and audio generation](#video-and-audio-generation), or
|
|
||||||
[adapters, refinement and upscaling](#adapters-refinement-and-upscaling).
|
|
||||||
Each model name links to its guide for weights and setup.
|
|
||||||
|
|
||||||
## Run an example
|
|
||||||
|
|
||||||
Open the script's `var` block and set the model paths, input files, prompt and
|
|
||||||
output path. Run the following commands from the CMake build directory. Relative
|
|
||||||
paths in the script resolve from that directory.
|
|
||||||
|
|
||||||
**Windows (PowerShell, Visual Studio Release)**
|
|
||||||
|
|
||||||
```powershell
|
|
||||||
.\bin\Release\sd-cli.exe -M dgl --script ..\docs\dgl\sd\sd1-5-txt2img.dgl --check
|
|
||||||
.\bin\Release\sd-cli.exe -M dgl --script ..\docs\dgl\sd\sd1-5-txt2img.dgl
|
|
||||||
```
|
|
||||||
|
|
||||||
**Linux/macOS**
|
|
||||||
|
|
||||||
```sh
|
|
||||||
./bin/sd-cli -M dgl --script ../docs/dgl/sd/sd1-5-txt2img.dgl --check
|
|
||||||
./bin/sd-cli -M dgl --script ../docs/dgl/sd/sd1-5-txt2img.dgl
|
|
||||||
```
|
|
||||||
|
|
||||||
The first command checks the script without loading weights. The second runs it
|
|
||||||
and writes to the output path in the script. Set context options such as
|
|
||||||
`--max-vram` and `--auto-fit` on the command line. In the server's DGL editor,
|
|
||||||
choose model paths under a configured model directory and save results under
|
|
||||||
`output/`. See the [server guide](../../examples/server/README.md#dgl-editor).
|
|
||||||
|
|
||||||
For a large video input, set `max_frames` on `video::load` to limit how many
|
|
||||||
frames it decodes. See [video input formats and limits](../dgl.md#reading-video)
|
|
||||||
and [NumPy tensor files](../dgl.md#tensor-files).
|
|
||||||
|
|
||||||
## Model examples
|
|
||||||
|
|
||||||
### Image generation and editing
|
|
||||||
|
|
||||||
| Model guide | Scripts |
|
|
||||||
| --- | --- |
|
|
||||||
| [Anima](../models/anima.md) | [Anima Preview text to image](anima/anima-preview-txt2img.dgl) |
|
|
||||||
| [Boogu Image](../models/boogu_image.md) | [Text to image](boogu_image/boogu-image-base-txt2img.dgl) · [Image editing](boogu_image/boogu-image-edit.dgl) |
|
|
||||||
| [Chroma](../models/chroma.md) | [Unlocked v40 text to image](chroma/chroma-unlocked-v40-txt2img.dgl) |
|
|
||||||
| [Chroma1-Radiance](../models/chroma_radiance.md) | [Text to image](chroma_radiance/chroma1-radiance-v0-4-txt2img.dgl) |
|
|
||||||
| [Distilled Stable Diffusion models](../models/distilled_sd.md) | [SSD1B](distilled_sd/ssd1b-txt2img.dgl) · [SDXS-512-DreamShaper](distilled_sd/sdxs-512-dreamshaper-txt2img.dgl) |
|
|
||||||
| [ERNIE-Image](../models/ernie_image.md) | [ERNIE-Image Turbo](ernie_image/ernie-image-turbo-txt2img.dgl) · [ERNIE-Image](ernie_image/ernie-image-txt2img.dgl) |
|
|
||||||
| [Fibo 2.0](../models/fibo2.md) | [Dev: text to image](fibo2/fibo2-dev-txt2img.dgl) · [Dev: image editing](fibo2/fibo2-dev-edit.dgl) · [Edit Turbo](fibo2/fibo2-edit-turbo.dgl) |
|
|
||||||
| [FLUX.1](../models/flux.md) | [FLUX.1 dev](flux/flux1-dev-txt2img.dgl) · [FLUX.1 schnell](flux/flux1-schnell-txt2img.dgl) · [FLUX.1 dev with LoRA](flux/flux1-dev-lora.dgl) |
|
|
||||||
| [FLUX.2 dev](../models/flux2.md) | [Image editing](flux2/flux2-dev-edit.dgl) |
|
|
||||||
| [FLUX.2 Klein 4B](../models/flux2.md) | [Text to image](flux2/flux2-klein-4b-txt2img.dgl) · [Image editing](flux2/flux2-klein-4b-edit.dgl) · [Base text to image](flux2/flux2-klein-base-4b-txt2img.dgl) |
|
|
||||||
| [FLUX.2 Klein 9B](../models/flux2.md) | [Text to image](flux2/flux2-klein-9b-txt2img.dgl) · [Image editing](flux2/flux2-klein-9b-edit.dgl) · [Base text to image](flux2/flux2-klein-base-9b-txt2img.dgl) |
|
|
||||||
| [FLUX.3 Image](../models/flux3.md) | [Klein: text to image](flux3/flux3-image-klein-txt2img.dgl) · [Klein: image editing](flux3/flux3-image-klein-edit.dgl) · [Klein Base: text to image](flux3/flux3-image-klein-base-txt2img.dgl) |
|
|
||||||
| [HiDream-O1-Image](../models/hidream_o1_image.md) | [Text to image](hidream_o1_image/hidream-o1-image-dev-txt2img.dgl) |
|
|
||||||
| [Ideogram4](../models/ideogram4.md) | [Text to image](ideogram4/ideogram4-txt2img.dgl) |
|
|
||||||
| [Iris-3B](../models/iris.md) | [Text to image](iris/iris-3b-txt2img.dgl) |
|
|
||||||
| [FLUX.1 Kontext](../models/kontext.md) | [Edit with FLUX.1 Kontext dev](kontext/flux1-kontext-dev-edit.dgl) |
|
|
||||||
| [Krea2](../models/krea2.md) | [Raw text to image](krea2/krea2-raw-txt2img.dgl) |
|
|
||||||
| [Lens](../models/lens.md) | [Lens](lens/lens-txt2img.dgl) · [Lens Turbo](lens/lens-turbo-txt2img.dgl) |
|
|
||||||
| [LLaDA-Image](../models/llada_image.md) | [Text to image](llada_image/llada-image-turbo-txt2img.dgl) · [Image editing](llada_image/llada-image-turbo-edit.dgl) |
|
|
||||||
| [LongCat Image](../models/longcat_image.md) | [Text to image](longcat_image/longcat-image-txt2img.dgl) |
|
|
||||||
| [Mage-Flow](../models/mage_flow.md) | [Text to image](mage_flow/mage-flow-turbo-txt2img.dgl) · [Image editing](mage_flow/mage-flow-edit.dgl) |
|
|
||||||
| [Ming-Image](../models/ming_image.md) | [0.1 Design text to image](ming_image/ming-image-0-1-design-txt2img.dgl) |
|
|
||||||
| [MiniMax-H3-Image](../models/minimax_h3_image.md) | [Text to image](minimax_h3_image/minimax-h3-image-txt2img.dgl) · [Image editing](minimax_h3_image/minimax-h3-image-edit.dgl) |
|
|
||||||
| [MiniT2I](../models/minit2i.md) | [CUDA](minit2i/minit2i-cuda-txt2img.dgl) · [Metal](minit2i/minit2i-metal-txt2img.dgl) (`--threads 8`) |
|
|
||||||
| [MOSS-Image](../models/moss_image.md) | [Base: text to image](moss_image/moss-image-base-txt2img.dgl) · [SFT: text to image](moss_image/moss-image-sft-txt2img.dgl) · [Inline images](moss_image/moss-image-sft-inline-images.dgl) · [Image editing (HQ)](moss_image/moss-image-edit.dgl) · [Image editing (chinoll)](moss_image/moss-image-edit-chinoll.dgl) |
|
|
||||||
| [Ovis-Image](../models/ovis_image.md) | [Text to image](ovis_image/ovis-image-txt2img.dgl) |
|
|
||||||
| [P-H3-Image](../models/p_h3_image.md) | [Text to image](p_h3_image/p-h3-image-txt2img.dgl) · [Image editing](p_h3_image/p-h3-image-edit.dgl) |
|
|
||||||
| [PiD](../models/pid.md) | [512 to 2048 pixels](pid/pid-flux1-512-to-2048-txt2img.dgl) |
|
|
||||||
| [PixArt](../models/pixart.md) | [Sigma XL2 at 1024 pixels](pixart/pixart-sigma-xl2-1024-ms-txt2img.dgl) |
|
|
||||||
| [Qwen Image](../models/qwen_image.md) | [Text to image](qwen_image/qwen-image-txt2img.dgl) |
|
|
||||||
| [Qwen Image 2.1](../models/qwen_image_2.1.md) | [Text to image](qwen_image_2.1/qwen-image-2-1-txt2img.dgl) · [Image editing](qwen_image_2.1/qwen-image-2-1-edit.dgl) |
|
|
||||||
| [Qwen Image Edit](../models/qwen_image_edit.md) | [Qwen Image Edit](qwen_image_edit/qwen-image-edit.dgl) · [Qwen Image Edit 2509](qwen_image_edit/qwen-image-edit-2509.dgl) · [Qwen Image Edit 2511](qwen_image_edit/qwen-image-edit-2511.dgl) |
|
|
||||||
| [Stable Diffusion – generation](../models/sd.md) | [SD 1.4](sd/sd1-4-txt2img.dgl) · [SD 1.5](sd/sd1-5-txt2img.dgl) · [SDXL](sd/sdxl-txt2img.dgl) · [NitroFusion](sd/nitrosd-realism-nitrofusion.dgl) |
|
|
||||||
| [Stable Diffusion – image conditioning](../models/sd.md) | [SD 1.4 image to image](sd/sd1-4-img2img.dgl) · [SD 1.5 ControlNet](sd/sd1-5-controlnet.dgl) · [SD 1.5 inpainting](sd/sd1-5-inpainting.dgl) |
|
|
||||||
| [Stable Diffusion 3](../models/sd3.md) | [SD 3.5 Large text to image](sd3/sd3-5-large-txt2img.dgl) |
|
|
||||||
| [SeFi-Image](../models/sefi_image.md) | [1B Turbo](sefi_image/sefi-1b-turbo-txt2img.dgl) · [1B Base](sefi_image/sefi-1b-base-txt2img.dgl) · [5B Turbo](sefi_image/sefi-5b-turbo-txt2img.dgl) (`--max-vram 8`) · [5B RL](sefi_image/sefi-image-5b-rl.dgl) |
|
|
||||||
| [SenseNova U1.5](../models/sensenova_u1.md) | [Text to image on CUDA](sensenova_u1/sensenova-u1-cuda-txt2img.dgl) |
|
|
||||||
| [Z-Image](../models/z_image.md) | [Turbo: text to image](z_image/z-image-turbo-txt2img.dgl) · [Base: text to image](z_image/z-image-base-txt2img.dgl) · [Turbo with ControlNet](z_image/z-image-turbo-controlnet.dgl) |
|
|
||||||
| [Z-Image L2P](../models/z_image_l2p.md) | [Text to image](z_image_l2p/z-image-l2p-txt2img.dgl) |
|
|
||||||
|
|
||||||
### Video and audio generation
|
|
||||||
|
|
||||||
| Model guide | Scripts |
|
|
||||||
| --- | --- |
|
|
||||||
| [AnimateDiff – text to video](../models/animatediff.md) | [Text to video with CPU offload](animatediff/animatediff-realisticvision-v6-txt2video-cpu-offload.dgl) · [Text to video, 16 frames](animatediff/animatediff-realisticvision-v6-txt2video-16-frames.dgl) · [Text to video with a VRAM budget](animatediff/animatediff-realisticvision-v6-txt2video-vram-budget.dgl) (`--max-vram 2.0`) · [Domain Adapter LoRA](animatediff/animatediff-realisticvision-v6-domain-lora.dgl) |
|
|
||||||
| [AnimateDiff – image to video](../models/animatediff.md) | [Generate the initial image](animatediff/realisticvision-v6-txt2img.dgl) · [Image to video](animatediff/animatediff-realisticvision-v6-img2video.dgl) |
|
|
||||||
| [HunyuanVideo 1.5](../models/hunyuan_video.md) | [720p text to video](hunyuan_video/hunyuanvideo1-5-720p-txt2video.dgl) |
|
|
||||||
| [LingBot-Video](../models/lingbot_video.md) | [Dens 1.3B text to video](lingbot_video/lingbot-video-dens-1-3b-txt2video.dgl) |
|
|
||||||
| [LTX-2.3](../models/ltx2.md) | [2.3 text to video](ltx2/ltx-2-3-dev-txt2video.dgl) · [2.3 image to video](ltx2/ltx-2-3-dev-img2video.dgl) · [2.3 first/last frames](ltx2/ltx-2-3-dev-first-last-frame.dgl) · [2.3 spatial latent upscale](ltx2/ltx-2-3-spatial-upscale.dgl) |
|
|
||||||
| [LTX-2.5](../models/ltx2.md) | [2.5 text to video](ltx2/ltx-2-5-dev-txt2video.dgl) · [2.5 image to video](ltx2/ltx-2-5-dev-img2video.dgl) · [2.5 spatial latent upscale](ltx2/ltx-2-5-spatial-upscale.dgl) |
|
|
||||||
| [MiniMax-H3](../models/minimax_h3.md) | [Text to audio/video](minimax_h3/minimax-h3-text-to-av.dgl) · [First/last-frame conditioning](minimax_h3/minimax-h3-first-last-frame.dgl) · [Reference to audio/video](minimax_h3/minimax-h3-reference-to-av.dgl) · [Interpolated latent hires](minimax_h3/minimax-h3-latent-hires.dgl) · [Learned latent hires](minimax_h3/minimax-h3-learned-hires.dgl) |
|
|
||||||
| [Wan 2.1](../models/wan.md) | [Text to video, 1.3B](wan/wan2-1-t2v-1-3b.dgl) · [Text to video, 14B](wan/wan2-1-t2v-14b.dgl) · [Image to video, 14B](wan/wan2-1-i2v-14b.dgl) · [First/last frames, 14B](wan/wan2-1-first-last-frame-14b.dgl) |
|
|
||||||
| [Wan 2.1 VACE 1.3B](../models/wan.md) | [Text to video](wan/wan2-1-vace-1-3b-txt2video.dgl) · [Reference to video](wan/wan2-1-vace-1-3b-ref2video.dgl) · [Video to video](wan/wan2-1-vace-1-3b-video2video.dgl) |
|
|
||||||
| [Wan 2.1 VACE 14B](../models/wan.md) | [Text to video](wan/wan2-1-vace-14b-txt2video.dgl) · [Reference to video](wan/wan2-1-vace-14b-ref2video.dgl) · [Video to video](wan/wan2-1-vace-14b-video2video.dgl) |
|
|
||||||
| [Wan 2.2 A14B](../models/wan.md) | [Text to video](wan/wan2-2-t2v-a14b.dgl) · [Image to video](wan/wan2-2-i2v-a14b.dgl) · [Single image](wan/wan2-2-t2v-a14b-image.dgl) · [Text to video with LoRA](wan/wan2-2-t2v-a14b-lora.dgl) · [First/last frames](wan/wan2-2-first-last-frame-a14b.dgl) |
|
|
||||||
| [Wan 2.2 TI2V 5B](../models/wan.md) | [Text to video](wan/wan2-2-ti2v-5b-txt2video.dgl) · [Image to video](wan/wan2-2-ti2v-5b-img2video.dgl) |
|
|
||||||
| [Wan 2.2 S2V](../models/wan.md) | [Speech to video, 14B](wan/wan2-2-s2v-14b.dgl) |
|
|
||||||
| [Wan 2.2 VACE Fun A14B](../models/wan.md) | [Reference to video](wan/wan2-2-vace-fun-a14b-ref2video.dgl) |
|
|
||||||
|
|
||||||
### Adapters, refinement and upscaling
|
|
||||||
|
|
||||||
| Model guide | Scripts |
|
|
||||||
| --- | --- |
|
|
||||||
| [ADetailer](../models/adetailer.md) | [Refine an existing image](adetailer/adetailer-existing-image.dgl) · [Generate and refine](adetailer/adetailer-generated-image.dgl) |
|
|
||||||
| [ESRGAN and MoSR](../models/esrgan.md) | [Generate and upscale](esrgan/sd1-5-txt2img-esrgan.dgl) · [Upscale an image](esrgan/realesrgan-x4plus-anime-6b-upscale.dgl) |
|
|
||||||
| [IP-Adapter](../models/ip_adapter.md) | [SD 1.5 Classic](ip_adapter/ip-adapter-sd1-5.dgl) · [SDXL Classic](ip_adapter/ip-adapter-sdxl.dgl) · [SD 1.5 Plus](ip_adapter/ip-adapter-plus-sd1-5.dgl) · [SDXL with ControlNet](ip_adapter/ip-adapter-sdxl-controlnet.dgl) |
|
|
||||||
| [LCM and LCM-LoRA](../models/lcm.md) | [LCM-LoRA with SD 1.5](lcm/lcm-lora-sd1-5.dgl) |
|
|
||||||
| [LoRA](../models/lora.md) | [SD 1.5 UNet and text encoder](lora/sd1-5-lora.dgl) |
|
|
||||||
| [PhotoMaker](../models/photo_maker.md) | [PhotoMaker v1](photo_maker/photomaker-v1-sdxl.dgl) · [PhotoMaker v2](photo_maker/photomaker-v2-sdxl.dgl) |
|
|
||||||
| [PuLID-Flux](../models/pulid.md) | [Identity-guided generation](pulid/pulid-flux1-schnell.dgl) |
|
|
||||||
| [RelayVSR](../models/relay_vsr.md) | [Upscale a video](relay_vsr/relayvsr-x2-video-upscale.dgl) · [Upscale an image](relay_vsr/relayvsr-x2-image-upscale.dgl) |
|
|
||||||
| [SeedVR2](../models/seedvr2.md) | [Upscale an image](seedvr2/seedvr2-3b-image-upscale.dgl) · [Upscale a video](seedvr2/seedvr2-3b-video-upscale.dgl) |
|
|
||||||
| [TAESD](../models/taesd.md) | [SD 1.5 decoding with TAESD](taesd/sd1-5-taesd-preview.dgl). The CLI writes the final PNG. Intermediate previews require a [host preview callback](../dgl.md#progress-preview-and-cancellation) in `tae` mode. |
|
|
||||||
|
|
@ -1,107 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/adetailer.md — Repair an existing image
|
|
||||||
|
|
||||||
var {
|
|
||||||
weights = "../models/checkpoints/model.safetensors"
|
|
||||||
model_path = "../models/detectors/face_yolov8n.safetensors"
|
|
||||||
|
|
||||||
input_path = "input.png"
|
|
||||||
output_path = "repaired.png"
|
|
||||||
|
|
||||||
detail_prompt = "detailed portrait photo"
|
|
||||||
negative_prompt = "deformed face"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
|
|
||||||
settings = {
|
|
||||||
size = [512, 512],
|
|
||||||
steps = 24,
|
|
||||||
strength = 0.4,
|
|
||||||
cfg_scale = 6.0,
|
|
||||||
method = "dpm++2m",
|
|
||||||
scheduler = "karras",
|
|
||||||
mask_blur = 4
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn latent_mask(mask, like) {
|
|
||||||
shape = tensor::shape(like)
|
|
||||||
w = shape[0]
|
|
||||||
h = shape[1]
|
|
||||||
batch = shape[3]
|
|
||||||
resized = tensor::interpolate(image::to_f32(mask), size = [w, h], mode = "nearest")
|
|
||||||
return tensor::broadcast_to(resized, [w, h, 1, batch])
|
|
||||||
}
|
|
||||||
|
|
||||||
fn slice_sigmas_by_strength(sigmas, strength) {
|
|
||||||
steps = tensor::numel(sigmas) - 1
|
|
||||||
retained = math::floor(steps * strength)
|
|
||||||
return sigmas[steps - retained:]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn dilate(mask) {
|
|
||||||
return tensor::max_pool2d(mask, kernel = [4, 4], axes = [1, 2], padding_before = [2, 2], padding_after = [1, 1], pad_value = 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn inpaint_patch(image, mask, unet, text, vae, prompt, negative_prompt, seed, settings) {
|
|
||||||
pixels = image::to_f32(image)
|
|
||||||
encode_rng = make_rng("cuda", seed = seed)
|
|
||||||
base = vae_to_unet_latents(vae, vae_encode(vae, pixels, rng = encode_rng))
|
|
||||||
latent_region = latent_mask(mask, like = base)
|
|
||||||
rng = make_rng("cuda", seed = seed)
|
|
||||||
pos = predictor(unet, encode_prompt(text, prompt), prediction = "eps")
|
|
||||||
neg = predictor(unet, encode_prompt(text, negative_prompt), prediction = "eps")
|
|
||||||
guided = cfg(pos, neg, scale = settings.cfg_scale)
|
|
||||||
sigmas = slice_sigmas_by_strength(make_sigmas(guided, latent = base, scheduler = settings.scheduler, steps = settings.steps), strength = settings.strength)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
denoise_mask = tensor::max_pool2d(latent_region, kernel = [3, 3], padding_before = [1, 1])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = settings.method, base = base, denoise_mask = denoise_mask, rng = rng)
|
|
||||||
return vae_decode(vae, unet_to_vae_latents(vae, latent))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn paste_region(canvas, patch, feather, origin, extent) {
|
|
||||||
background = tensor::crop(canvas, axes = [1, 2], start = origin, size = extent)
|
|
||||||
foreground = tensor::interpolate(patch, size = extent, axes = [1, 2], mode = "bilinear")
|
|
||||||
mask = tensor::crop(feather, axes = [1, 2], start = origin, size = extent)
|
|
||||||
weight = tensor::affine(tensor::cast(mask, "f32"), scale = 0.00392156862745098)
|
|
||||||
blended = tensor::lerp(background, foreground, weight)
|
|
||||||
y = origin[1]
|
|
||||||
rows = tensor::crop(canvas, axes = [2], start = [y], size = [extent[1]])
|
|
||||||
band = tensor::replace_slice(rows, blended, axis = 1, start = origin[0])
|
|
||||||
return tensor::replace_slice(canvas, band, axis = 2, start = y)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn refine_region(canvas, region, unet, text, vae, prompt, negative_prompt, seed, settings) {
|
|
||||||
origin = region.box[:2]
|
|
||||||
extent = region.box[2:4]
|
|
||||||
channels = tensor::shape(canvas)[0]
|
|
||||||
last = channels - 1
|
|
||||||
rgb = tensor::index_select(canvas, axis = 0, indices = [0, math::min(1, last), math::min(2, last)])
|
|
||||||
image_crop = tensor::crop(rgb, axes = [1, 2], start = origin, size = extent)
|
|
||||||
mask_crop = tensor::crop(region.mask, axes = [1, 2], start = origin, size = extent)
|
|
||||||
image = tensor::interpolate(image_crop, size = settings.size, axes = [1, 2], mode = "bilinear")
|
|
||||||
mask = tensor::interpolate(mask_crop, size = settings.size, axes = [1, 2], mode = "nearest_exact")
|
|
||||||
region_seed = seed + region.index
|
|
||||||
patch = inpaint_patch(image, mask, unet, text, vae, prompt, negative_prompt, region_seed, settings)
|
|
||||||
radius = math::ceil(settings.mask_blur * 2.5)
|
|
||||||
feather = tensor::gaussian_blur(region.mask, sigma = settings.mask_blur, radius = radius, axes = [1, 2])
|
|
||||||
refined = paste_region(rgb, patch, feather, origin, extent)
|
|
||||||
alpha = canvas[math::min(3, channels):]
|
|
||||||
return tensor::concat([refined, alpha], axis = 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
unet = load_unet(weights)
|
|
||||||
text = load_text_encoder(weights)
|
|
||||||
vae = load_vae(weights)
|
|
||||||
detector = load_detector(model_path)
|
|
||||||
image = image::load(input_path)
|
|
||||||
detections = detections::detect(detector, image, confidence = 0.3)
|
|
||||||
selected = detections::filter(image, detections, top_k = 4)
|
|
||||||
masks = map(detections::box_masks(image, selected), process = dilate)
|
|
||||||
regions = regions::plan_mask_crops(masks, aspect = settings.size, padding = 32)
|
|
||||||
refined = fold(regions, image, process = refine_region, unet = unet, text = text, vae = vae,
|
|
||||||
prompt = detail_prompt, negative_prompt = negative_prompt, seed = seed, settings = settings)
|
|
||||||
image::save(output_path, refined)
|
|
||||||
return { image = refined, detections = selected, regions = regions }
|
|
||||||
}
|
|
||||||
|
|
@ -1,128 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/adetailer.md — Repair generated images
|
|
||||||
|
|
||||||
var {
|
|
||||||
weights = "../models/checkpoints/model.safetensors"
|
|
||||||
model_path = "../models/detectors/face_yolov8n.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "portrait photo"
|
|
||||||
detail_prompt = "portrait photo, detailed face"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
|
|
||||||
settings = {
|
|
||||||
size = [512, 512],
|
|
||||||
steps = 20,
|
|
||||||
strength = 0.4,
|
|
||||||
cfg_scale = 7.0,
|
|
||||||
method = "euler_a",
|
|
||||||
scheduler = "karras",
|
|
||||||
mask_blur = 4
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn latent_mask(mask, like) {
|
|
||||||
shape = tensor::shape(like)
|
|
||||||
w = shape[0]
|
|
||||||
h = shape[1]
|
|
||||||
batch = shape[3]
|
|
||||||
resized = tensor::interpolate(image::to_f32(mask), size = [w, h], mode = "nearest")
|
|
||||||
return tensor::broadcast_to(resized, [w, h, 1, batch])
|
|
||||||
}
|
|
||||||
|
|
||||||
fn slice_sigmas_by_strength(sigmas, strength) {
|
|
||||||
steps = tensor::numel(sigmas) - 1
|
|
||||||
retained = math::floor(steps * strength)
|
|
||||||
return sigmas[steps - retained:]
|
|
||||||
}
|
|
||||||
|
|
||||||
fn dilate(mask) {
|
|
||||||
return tensor::max_pool2d(mask, kernel = [4, 4], axes = [1, 2], padding_before = [2, 2], padding_after = [1, 1], pad_value = 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn inpaint_patch(image, mask, unet, text, vae, prompt, negative_prompt, seed, settings) {
|
|
||||||
pixels = image::to_f32(image)
|
|
||||||
encode_rng = make_rng("cuda", seed = seed)
|
|
||||||
base = vae_to_unet_latents(vae, vae_encode(vae, pixels, rng = encode_rng))
|
|
||||||
latent_region = latent_mask(mask, like = base)
|
|
||||||
rng = make_rng("cuda", seed = seed)
|
|
||||||
pos = predictor(unet, encode_prompt(text, prompt), prediction = "eps")
|
|
||||||
neg = predictor(unet, encode_prompt(text, negative_prompt), prediction = "eps")
|
|
||||||
guided = cfg(pos, neg, scale = settings.cfg_scale)
|
|
||||||
sigmas = slice_sigmas_by_strength(make_sigmas(guided, latent = base, scheduler = settings.scheduler, steps = settings.steps), strength = settings.strength)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
denoise_mask = tensor::max_pool2d(latent_region, kernel = [3, 3], padding_before = [1, 1])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = settings.method, base = base, denoise_mask = denoise_mask, rng = rng)
|
|
||||||
return vae_decode(vae, unet_to_vae_latents(vae, latent))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn paste_region(canvas, patch, feather, origin, extent) {
|
|
||||||
background = tensor::crop(canvas, axes = [1, 2], start = origin, size = extent)
|
|
||||||
foreground = tensor::interpolate(patch, size = extent, axes = [1, 2], mode = "bilinear")
|
|
||||||
mask = tensor::crop(feather, axes = [1, 2], start = origin, size = extent)
|
|
||||||
weight = tensor::affine(tensor::cast(mask, "f32"), scale = 0.00392156862745098)
|
|
||||||
blended = tensor::lerp(background, foreground, weight)
|
|
||||||
y = origin[1]
|
|
||||||
rows = tensor::crop(canvas, axes = [2], start = [y], size = [extent[1]])
|
|
||||||
band = tensor::replace_slice(rows, blended, axis = 1, start = origin[0])
|
|
||||||
return tensor::replace_slice(canvas, band, axis = 2, start = y)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn refine_region(canvas, region, unet, text, vae, prompt, negative_prompt, seed, settings) {
|
|
||||||
origin = region.box[:2]
|
|
||||||
extent = region.box[2:4]
|
|
||||||
channels = tensor::shape(canvas)[0]
|
|
||||||
last = channels - 1
|
|
||||||
rgb = tensor::index_select(canvas, axis = 0, indices = [0, math::min(1, last), math::min(2, last)])
|
|
||||||
image_crop = tensor::crop(rgb, axes = [1, 2], start = origin, size = extent)
|
|
||||||
mask_crop = tensor::crop(region.mask, axes = [1, 2], start = origin, size = extent)
|
|
||||||
image = tensor::interpolate(image_crop, size = settings.size, axes = [1, 2], mode = "bilinear")
|
|
||||||
mask = tensor::interpolate(mask_crop, size = settings.size, axes = [1, 2], mode = "nearest_exact")
|
|
||||||
region_seed = seed + region.index
|
|
||||||
patch = inpaint_patch(image, mask, unet, text, vae, prompt, negative_prompt, region_seed, settings)
|
|
||||||
radius = math::ceil(settings.mask_blur * 2.5)
|
|
||||||
feather = tensor::gaussian_blur(region.mask, sigma = settings.mask_blur, radius = radius, axes = [1, 2])
|
|
||||||
refined = paste_region(rgb, patch, feather, origin, extent)
|
|
||||||
alpha = canvas[math::min(3, channels):]
|
|
||||||
return tensor::concat([refined, alpha], axis = 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn generate_canvas(unet, text, vae, prompt, negative_prompt, seed) {
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
scheduler = "discrete"
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 7
|
|
||||||
method = "euler_a"
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
rng = make_rng("cuda", seed = seed)
|
|
||||||
pos = encode_prompt(text, prompt)
|
|
||||||
neg = encode_prompt(text, negative_prompt)
|
|
||||||
positive_predictor = predictor(unet, pos, prediction = "eps")
|
|
||||||
negative_predictor = predictor(unet, neg, prediction = "eps")
|
|
||||||
guided = cfg(positive_predictor, negative_predictor, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, scheduler = scheduler, steps = steps)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
return vae_decode(vae, unet_to_vae_latents(vae, latent))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
unet = load_unet(weights)
|
|
||||||
text = load_text_encoder(weights)
|
|
||||||
vae = load_vae(weights)
|
|
||||||
detector = load_detector(model_path)
|
|
||||||
image = generate_canvas(unet, text, vae, prompt, negative_prompt, seed)
|
|
||||||
detections = detections::detect(detector, image, confidence = 0.3)
|
|
||||||
selected = detections::filter(image, detections, top_k = 4)
|
|
||||||
masks = map(detections::box_masks(image, selected), process = dilate)
|
|
||||||
regions = regions::plan_mask_crops(masks, aspect = settings.size, padding = 32)
|
|
||||||
refined = fold(regions, image, process = refine_region, unet = unet, text = text, vae = vae,
|
|
||||||
prompt = detail_prompt, negative_prompt = negative_prompt, seed = seed, settings = settings)
|
|
||||||
image::save(output_path, refined)
|
|
||||||
return { image = refined, detections = selected, regions = regions }
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/anima.md — CLI
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/anima-preview.safetensors"
|
|
||||||
text_path = "../models/text_encoders/qwen_3_06b_base.safetensors"
|
|
||||||
vae_path = "../models/vae/qwen_image_vae.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat holding a sign says 'anima.cpp'"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 6.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "anima", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "anima", params_backend = "cpu")
|
|
||||||
vae = load_vae(vae_path, family = "anima", params_backend = "cpu")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/animatediff.md — v3 + Domain Adapter LoRA
|
|
||||||
|
|
||||||
var {
|
|
||||||
weights = "../models/checkpoints/realisticVisionV60B1.safetensors"
|
|
||||||
model_path = "../models/motion_modules/mm_sd15_v3.safetensors"
|
|
||||||
lora_path = "./loras/v3_sd15_adapter.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.avi"
|
|
||||||
|
|
||||||
prompt = "close up photo of a rabbit"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
frames = 16
|
|
||||||
fps = 8
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 7.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
original_unet = load_unet(weights)
|
|
||||||
domain_adapter = load_lora(lora_path)
|
|
||||||
base_unet = apply_lora(original_unet, domain_adapter)
|
|
||||||
motion = animatediff::load(model_path)
|
|
||||||
unet = animatediff::apply(base_unet, motion)
|
|
||||||
text = load_text_encoder(weights)
|
|
||||||
vae = load_vae(weights)
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height, batch = frames))
|
|
||||||
rng = make_rng("cuda", seed = seed)
|
|
||||||
pos = predictor(unet, encode_prompt(text, prompt), prediction = "eps")
|
|
||||||
neg = predictor(unet, encode_prompt(text, negative_prompt), prediction = "eps")
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, scheduler = scheduler, steps = steps)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
video = vae_decode(vae, unet_to_vae_latents(vae, latent))
|
|
||||||
video::save(output_path, {frames = video, fps_num = fps, fps_den = 1})
|
|
||||||
return { video = video, latent = latent }
|
|
||||||
}
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/animatediff.md — img2video
|
|
||||||
|
|
||||||
var {
|
|
||||||
weights = "../models/checkpoints/realisticVisionV60B1.safetensors"
|
|
||||||
model_path = "../models/motion_modules/mm_sd15_v3.safetensors"
|
|
||||||
|
|
||||||
input_path = "init.png"
|
|
||||||
output_path = "out.avi"
|
|
||||||
|
|
||||||
prompt = "a lovely cat"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
frames = 8
|
|
||||||
fps = 8
|
|
||||||
|
|
||||||
steps = 25
|
|
||||||
cfg_scale = 7.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "karras"
|
|
||||||
strength = 0.75
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
base_unet = load_unet(weights)
|
|
||||||
motion = animatediff::load(model_path)
|
|
||||||
unet = animatediff::apply(base_unet, motion)
|
|
||||||
text = load_text_encoder(weights)
|
|
||||||
vae = load_vae(weights)
|
|
||||||
source = tensor::interpolate(image::load(input_path), size = [width, height], axes = [1, 2])
|
|
||||||
encode_rng = make_rng("cuda", seed = seed)
|
|
||||||
encoded = vae_to_unet_latents(vae, vae_encode(vae, image::to_f32(source), rng = encode_rng))
|
|
||||||
base = tensor::broadcast_to(encoded, latent_shape(vae, width = width, height = height, batch = frames))
|
|
||||||
rng = make_rng("cuda", seed = seed)
|
|
||||||
pos = predictor(unet, encode_prompt(text, prompt), prediction = "eps")
|
|
||||||
neg = predictor(unet, encode_prompt(text, negative_prompt), prediction = "eps")
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
full_sigmas = make_sigmas(guided, latent = base, scheduler = scheduler, steps = steps)
|
|
||||||
retained = math::min(math::floor(steps * strength) + 1, steps)
|
|
||||||
sigmas = full_sigmas[steps - retained:]
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
video = vae_decode(vae, unet_to_vae_latents(vae, latent))
|
|
||||||
video::save(output_path, {frames = video, fps_num = fps, fps_den = 1})
|
|
||||||
return { video = video, latent = latent }
|
|
||||||
}
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/animatediff.md — Text-to-video
|
|
||||||
|
|
||||||
var {
|
|
||||||
weights = "../models/checkpoints/realisticVisionV60B1.safetensors"
|
|
||||||
model_path = "../models/motion_modules/animatediff/mm_sd15_v3.safetensors"
|
|
||||||
|
|
||||||
output_path = "out.avi"
|
|
||||||
|
|
||||||
prompt = "photo of coastline, rocks, storm weather, wind, waves, lightning"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
width = 384
|
|
||||||
height = 384
|
|
||||||
frames = 16
|
|
||||||
fps = 8
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 8.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
base_unet = load_unet(weights, params_backend = "cpu")
|
|
||||||
motion = animatediff::load(model_path, params_backend = "cpu")
|
|
||||||
unet = animatediff::apply(base_unet, motion)
|
|
||||||
text = load_text_encoder(weights, params_backend = "cpu")
|
|
||||||
vae = load_vae(weights, params_backend = "cpu")
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height, batch = frames))
|
|
||||||
rng = make_rng("cuda", seed = seed)
|
|
||||||
pos = predictor(unet, encode_prompt(text, prompt), prediction = "eps")
|
|
||||||
neg = predictor(unet, encode_prompt(text, negative_prompt), prediction = "eps")
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, scheduler = scheduler, steps = steps)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
video = vae_decode(vae, unet_to_vae_latents(vae, latent))
|
|
||||||
video::save(output_path, {frames = video, fps_num = fps, fps_den = 1})
|
|
||||||
return { video = video, latent = latent }
|
|
||||||
}
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/animatediff.md — Text-to-video
|
|
||||||
|
|
||||||
var {
|
|
||||||
weights = "../models/checkpoints/realisticVisionV60B1.safetensors"
|
|
||||||
model_path = "../models/motion_modules/animatediff/mm_sd15_v3.safetensors"
|
|
||||||
|
|
||||||
output_path = "out.avi"
|
|
||||||
|
|
||||||
prompt = "a red apple on a wooden table"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
frames = 8
|
|
||||||
fps = 8
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 8.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
base_unet = load_unet(weights, params_backend = "cpu")
|
|
||||||
motion = animatediff::load(model_path, params_backend = "cpu")
|
|
||||||
unet = animatediff::apply(base_unet, motion)
|
|
||||||
text = load_text_encoder(weights, params_backend = "cpu")
|
|
||||||
vae = load_vae(weights, params_backend = "cpu")
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height, batch = frames))
|
|
||||||
rng = make_rng("cuda", seed = seed)
|
|
||||||
pos = predictor(unet, encode_prompt(text, prompt), prediction = "eps")
|
|
||||||
neg = predictor(unet, encode_prompt(text, negative_prompt), prediction = "eps")
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, scheduler = scheduler, steps = steps)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
video = vae_decode(vae, unet_to_vae_latents(vae, latent))
|
|
||||||
video::save(output_path, {frames = video, fps_num = fps, fps_den = 1})
|
|
||||||
return { video = video, latent = latent }
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# CLI/context: --max-vram 2.0
|
|
||||||
# docs/models/animatediff.md — Text-to-video
|
|
||||||
|
|
||||||
var {
|
|
||||||
weights = "../models/checkpoints/realisticVisionV60B1.safetensors"
|
|
||||||
model_path = "../models/motion_modules/animatediff/mm_sd15_v3.safetensors"
|
|
||||||
|
|
||||||
output_path = "out.avi"
|
|
||||||
|
|
||||||
prompt = "photo of coastline, rocks, storm weather, wind, waves, lightning"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
width = 384
|
|
||||||
height = 384
|
|
||||||
frames = 8
|
|
||||||
fps = 8
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 8.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
base_unet = load_unet(weights)
|
|
||||||
motion = animatediff::load(model_path)
|
|
||||||
unet = animatediff::apply(base_unet, motion)
|
|
||||||
text = load_text_encoder(weights)
|
|
||||||
vae = load_vae(weights)
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height, batch = frames))
|
|
||||||
rng = make_rng("cuda", seed = seed)
|
|
||||||
pos = predictor(unet, encode_prompt(text, prompt), prediction = "eps")
|
|
||||||
neg = predictor(unet, encode_prompt(text, negative_prompt), prediction = "eps")
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, scheduler = scheduler, steps = steps)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
video = vae_decode(vae, unet_to_vae_latents(vae, latent))
|
|
||||||
video::save(output_path, {frames = video, fps_num = fps, fps_den = 1})
|
|
||||||
return { video = video, latent = latent }
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/animatediff.md — img2video
|
|
||||||
|
|
||||||
var {
|
|
||||||
weights = "../models/checkpoints/realisticVisionV60B1.safetensors"
|
|
||||||
|
|
||||||
output_path = "init.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 7.0
|
|
||||||
method = "euler_a"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
text = load_text_encoder(weights)
|
|
||||||
vae = load_vae(weights)
|
|
||||||
unet = load_unet(weights)
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
rng = make_rng("cuda", seed = seed)
|
|
||||||
pos = encode_prompt(text, prompt)
|
|
||||||
neg = encode_prompt(text, negative_prompt)
|
|
||||||
positive_predictor = predictor(unet, pos, prediction = "eps")
|
|
||||||
negative_predictor = predictor(unet, neg, prediction = "eps")
|
|
||||||
guided = cfg(positive_predictor, negative_predictor, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, scheduler = scheduler, steps = steps)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, unet_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return { image = image, latent = latent, positive = pos, sigmas = sigmas }
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/boogu_image.md — Boogu Image Base
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/boogu_image_base_bf16.safetensors"
|
|
||||||
text_path = "../models/text_encoders/Qwen3VL-8B-Instruct-Q4_K_M.gguf"
|
|
||||||
vae_path = "../models/vae/ae.sft"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 7.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "boogu_image", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "boogu_image", params_backend = "cpu")
|
|
||||||
vae = load_vae(vae_path, family = "boogu_image", params_backend = "cpu")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,68 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/boogu_image.md — Boogu Image Edit
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/boogu_image_edit_bf16.safetensors"
|
|
||||||
text_path = "../models/text_encoders/Qwen3VL-8B-Instruct-Q4_K_M.gguf"
|
|
||||||
vision_path = "../models/text_encoders/mmproj-Qwen3VL-8B-Instruct-F16.gguf"
|
|
||||||
vae_path = "../models/vae/ae.sft"
|
|
||||||
|
|
||||||
reference_0_path = "../inputs/flux/flux1-dev-q8_0.png"
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "change 'flux.cpp' to 'boogu.cpp'"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 7.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sqrt_step(estimate, index, value) {
|
|
||||||
return (estimate + value / estimate) / 2
|
|
||||||
}
|
|
||||||
|
|
||||||
fn positive_sqrt(value) {
|
|
||||||
return fold(tensor::to_list(tensor::arange(0, 32)), value + 1.0, process = sqrt_step, value = value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fit_reference_area(input, area, factor, mode) {
|
|
||||||
shape = tensor::shape(input)
|
|
||||||
width = positive_sqrt(area * shape[0] / shape[1])
|
|
||||||
rounded = [math::round(width / factor) * factor, math::round(width * shape[1] / shape[0] / factor) * factor]
|
|
||||||
size = tensor::maximum(tensor::vector(rounded, dtype = "i64"), tensor::full([2], factor, dtype = "i64"))
|
|
||||||
return tensor::interpolate(input, size = size, mode = mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
reference_0 = image::load(reference_0_path)
|
|
||||||
width = tensor::shape(reference_0)[1]
|
|
||||||
height = tensor::shape(reference_0)[2]
|
|
||||||
|
|
||||||
model = load_dit(model_path, family = "boogu_image", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "boogu_image", params_backend = "cpu", vision_path = vision_path)
|
|
||||||
vae = load_vae(vae_path, family = "boogu_image", params_backend = "cpu")
|
|
||||||
|
|
||||||
encode_rng = make_rng(rng_type, seed = seed)
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
reference_0_original = image::to_f32(reference_0, channels = 3)
|
|
||||||
reference_0_pixels = fit_reference_area(reference_0_original, math::min(1048576, width * height), 16, mode = "bilinear")
|
|
||||||
reference_latent_0 = vae_to_dit_latents(vae, vae_encode(vae, reference_0_pixels, rng = encode_rng))
|
|
||||||
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height, media = [reference_0_original])
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height, media = [reference_0_original])
|
|
||||||
pos = predictor(model, positive, ref_latents = [reference_latent_0])
|
|
||||||
neg = predictor(model, negative, ref_latents = [reference_latent_0])
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/chroma.md — Example
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/chroma-unlocked-v40-q8_0.gguf"
|
|
||||||
text_path = "../models/text_encoders/t5xxl_fp16.safetensors"
|
|
||||||
vae_path = "../models/vae/ae.sft"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat holding a sign says 'chroma.cpp'"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 4.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "flux"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "chroma", model_args = "chroma_use_dit_mask=false")
|
|
||||||
text = load_text_encoder(text_path, backend = "cpu", family = "chroma", model_args = "chroma_use_dit_mask=false", t5_path = text_path)
|
|
||||||
vae = load_vae(vae_path, family = "chroma", model_args = "chroma_use_dit_mask=false")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/chroma_radiance.md — CLI
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/Chroma1-Radiance-v0.4-Q8_0.gguf"
|
|
||||||
text_path = "../models/text_encoders/clip/t5xxl_fp16.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat holding a sign says 'chroma radiance cpp'"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 4.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "flux"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "chroma_radiance")
|
|
||||||
text = load_text_encoder(text_path, family = "chroma_radiance", t5_path = text_path)
|
|
||||||
vae = load_vae(model_path, family = "chroma_radiance")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/distilled_sd.md — SDXS-512-DreamShaper
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/checkpoints/sdxs.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "portrait of a lovely cat"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 1
|
|
||||||
method = "euler_a"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_unet(model_path, family = "sdxs_512_ds")
|
|
||||||
text = load_text_encoder(model_path, family = "sdxs_512_ds")
|
|
||||||
vae = load_vae(model_path, family = "sdxs_512_ds")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
predict = predictor(model, condition)
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, unet_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,54 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/distilled_sd.md — SSD1B
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/checkpoints/SSD-1B-A1111.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat"
|
|
||||||
negative_prompt = ""
|
|
||||||
zero_negative = true
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 7.0
|
|
||||||
method = "euler_a"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sdxl_zero_text(cond) {
|
|
||||||
zeroed = zero_out(cond, fields = ["crossattn"])
|
|
||||||
pooled_zeros = tensor::zeros_like(cond.vector[:1280])
|
|
||||||
adm = tensor::replace_slice(cond.vector, pooled_zeros, axis = 0, start = 0)
|
|
||||||
return {crossattn = zeroed.crossattn, vector = adm}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_unet(model_path, family = "sdxl_ssd1b")
|
|
||||||
text = load_text_encoder(model_path, family = "sdxl_ssd1b")
|
|
||||||
vae = load_vae(model_path, family = "sdxl_ssd1b", conv_scale = 0.03125)
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative_text = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
negative = if zero_negative {
|
|
||||||
sdxl_zero_text(negative_text)
|
|
||||||
} else {
|
|
||||||
{crossattn = negative_text.crossattn, vector = negative_text.vector}
|
|
||||||
}
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, unet_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/ernie_image.md — ERNIE-Image-Turbo
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/ernie-image-turbo.safetensors"
|
|
||||||
text_path = "../models/text_encoders/ministral-3-3b.safetensors"
|
|
||||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 8
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "ernie_image", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "ernie_image", params_backend = "cpu")
|
|
||||||
vae = load_vae(vae_path, family = "ernie_image", params_backend = "cpu")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
predict = predictor(model, condition)
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/ernie_image.md — ERNIE-Image
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/ernie-image-UD-Q4_K_M.gguf"
|
|
||||||
text_path = "../models/text_encoders/ministral-3-3b.safetensors"
|
|
||||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 5.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "ernie_image", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "ernie_image", params_backend = "cpu")
|
|
||||||
vae = load_vae(vae_path, family = "ernie_image", params_backend = "cpu")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,17 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/esrgan.md — standalone image upscaling
|
|
||||||
|
|
||||||
var {
|
|
||||||
upscaler_path = "../models/upscale_models/RealESRGAN_x4plus_anime_6B.pth"
|
|
||||||
|
|
||||||
input_path = "input.png"
|
|
||||||
output_path = "upscaled.png"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
upscaler = load_upscaler(upscaler_path)
|
|
||||||
image = image::load(input_path)
|
|
||||||
output = upscale(upscaler, image)
|
|
||||||
image::save(output_path, output)
|
|
||||||
return output
|
|
||||||
}
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/esrgan.md — CLI
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/checkpoints/v1-5-pruned-emaonly.safetensors"
|
|
||||||
upscaler_path = "../models/upscale_models/RealESRGAN_x4plus_anime_6B.pth"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 7.0
|
|
||||||
method = "euler_a"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_unet(model_path, family = "sd1")
|
|
||||||
text = load_text_encoder(model_path, family = "sd1")
|
|
||||||
vae = load_vae(model_path, family = "sd1")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, unet_to_vae_latents(vae, latent))
|
|
||||||
upscaler = load_upscaler(upscaler_path)
|
|
||||||
enlarged = upscale(upscaler, image)
|
|
||||||
image::save(output_path, enlarged)
|
|
||||||
return {image = enlarged, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,61 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/fibo2.md — Fibo 2.0 Dev
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/fibo2_dev_int8_convrot.safetensors"
|
|
||||||
text_path = "../models/text_encoders/Qwen3-VL-4B-Instruct-Q4_K_M.gguf"
|
|
||||||
vision_path = "../models/text_encoders/Qwen3-VL-4B-Instruct-mmproj-BF16.gguf"
|
|
||||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
|
||||||
|
|
||||||
reference_0_path = "../inputs/flux/flux1-dev-q8_0.png"
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "change 'flux.cpp' to 'fibo2.cpp'"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 5.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "flux"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn center_crop_reference(input, width, height) {
|
|
||||||
shape = tensor::shape(input)
|
|
||||||
scale = tensor::maximum(tensor::vector([width / shape[0]]), tensor::vector([height / shape[1]]))[0]
|
|
||||||
resized_width = math::ceil(shape[0] * scale)
|
|
||||||
resized_height = math::ceil(shape[1] * scale)
|
|
||||||
resized = tensor::interpolate(input, size = [resized_width, resized_height], mode = "lanczos")
|
|
||||||
return tensor::crop(resized, axes = [0, 1], start = [math::floor((resized_width - width) / 2), math::floor((resized_height - height) / 2)], size = [width, height])
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
reference_0 = image::load(reference_0_path)
|
|
||||||
width = tensor::shape(reference_0)[1]
|
|
||||||
height = tensor::shape(reference_0)[2]
|
|
||||||
|
|
||||||
model = load_dit(model_path, family = "fibo2", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "fibo2", params_backend = "cpu", vision_path = vision_path)
|
|
||||||
vae = load_vae(vae_path, family = "fibo2", params_backend = "cpu")
|
|
||||||
|
|
||||||
encode_rng = make_rng(rng_type, seed = seed)
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
reference_0_original = image::to_f32(reference_0, channels = 3)
|
|
||||||
reference_0_pixels = center_crop_reference(reference_0_original, width, height)
|
|
||||||
reference_latent_0 = vae_to_dit_latents(vae, vae_encode(vae, reference_0_pixels, rng = encode_rng))
|
|
||||||
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height, media = [reference_0_pixels])
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive, ref_latents = [reference_latent_0], ref_index_mode = "increase")
|
|
||||||
neg = predictor(model, negative, ref_latents = [reference_latent_0], ref_index_mode = "increase")
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/fibo2.md — Fibo 2.0 Dev
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/fibo2_dev_int8_convrot.safetensors"
|
|
||||||
text_path = "../models/text_encoders/Qwen3-VL-4B-Instruct-Q4_K_M.gguf"
|
|
||||||
vision_path = "../models/text_encoders/Qwen3-VL-4B-Instruct-mmproj-BF16.gguf"
|
|
||||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat holding a sign says 'fibo2.cpp'"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 5.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "flux"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "fibo2", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "fibo2", params_backend = "cpu", vision_path = vision_path)
|
|
||||||
vae = load_vae(vae_path, family = "fibo2", params_backend = "cpu")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/fibo2.md — Fibo 2.0 Edit Turbo
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/fibo2_edit_turbo_int8_convrot.safetensors"
|
|
||||||
text_path = "../models/text_encoders/Qwen3-VL-4B-Instruct-Q4_K_M.gguf"
|
|
||||||
vision_path = "../models/text_encoders/Qwen3-VL-4B-Instruct-mmproj-BF16.gguf"
|
|
||||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
|
||||||
|
|
||||||
reference_0_path = "../inputs/flux/flux1-dev-q8_0.png"
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "change 'flux.cpp' to 'fibo2.cpp'"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
|
|
||||||
steps = 4
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "flux"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn center_crop_reference(input, width, height) {
|
|
||||||
shape = tensor::shape(input)
|
|
||||||
scale = tensor::maximum(tensor::vector([width / shape[0]]), tensor::vector([height / shape[1]]))[0]
|
|
||||||
resized_width = math::ceil(shape[0] * scale)
|
|
||||||
resized_height = math::ceil(shape[1] * scale)
|
|
||||||
resized = tensor::interpolate(input, size = [resized_width, resized_height], mode = "lanczos")
|
|
||||||
return tensor::crop(resized, axes = [0, 1], start = [math::floor((resized_width - width) / 2), math::floor((resized_height - height) / 2)], size = [width, height])
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
reference_0 = image::load(reference_0_path)
|
|
||||||
width = tensor::shape(reference_0)[1]
|
|
||||||
height = tensor::shape(reference_0)[2]
|
|
||||||
|
|
||||||
model = load_dit(model_path, family = "fibo2", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "fibo2", params_backend = "cpu", vision_path = vision_path)
|
|
||||||
vae = load_vae(vae_path, family = "fibo2", params_backend = "cpu")
|
|
||||||
|
|
||||||
encode_rng = make_rng(rng_type, seed = seed)
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
reference_0_original = image::to_f32(reference_0, channels = 3)
|
|
||||||
reference_0_pixels = center_crop_reference(reference_0_original, width, height)
|
|
||||||
reference_latent_0 = vae_to_dit_latents(vae, vae_encode(vae, reference_0_pixels, rng = encode_rng))
|
|
||||||
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height, media = [reference_0_pixels])
|
|
||||||
predict = predictor(model, condition, ref_latents = [reference_latent_0], ref_index_mode = "increase")
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/flux.md — Flux-dev q8_0 with LoRA
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/flux1-dev-q8_0.gguf"
|
|
||||||
clip_l_path = "../models/text_encoders/clip_l.safetensors"
|
|
||||||
t5_path = "../models/text_encoders/t5xxl_fp16.safetensors"
|
|
||||||
vae_path = "../models/vae/ae.sft"
|
|
||||||
lora_0_path = "../models/loras/realism_lora_comfy_converted.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat holding a sign says 'flux.cpp'"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "flux"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
base_model = load_dit(model_path, family = "flux")
|
|
||||||
text = load_text_encoder(clip_l_path, backend = "cpu", clip_l_path = clip_l_path, family = "flux", t5_path = t5_path)
|
|
||||||
vae = load_vae(vae_path, family = "flux")
|
|
||||||
|
|
||||||
lora_0 = load_lora(lora_0_path)
|
|
||||||
model = apply_lora(base_model, lora_0)
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
predict = predictor(model, condition)
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/flux.md — Flux-dev
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/flux1-dev-q8_0.gguf"
|
|
||||||
clip_l_path = "../models/text_encoders/clip_l.safetensors"
|
|
||||||
t5_path = "../models/text_encoders/t5xxl_fp16.safetensors"
|
|
||||||
vae_path = "../models/vae/ae.sft"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat holding a sign says 'flux.cpp'"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "flux"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "flux")
|
|
||||||
text = load_text_encoder(clip_l_path, backend = "cpu", clip_l_path = clip_l_path, family = "flux", t5_path = t5_path)
|
|
||||||
vae = load_vae(vae_path, family = "flux")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
predict = predictor(model, condition)
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/flux.md — Flux-schnell
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/flux1-schnell-q8_0.gguf"
|
|
||||||
clip_l_path = "../models/text_encoders/clip_l.safetensors"
|
|
||||||
t5_path = "../models/text_encoders/t5xxl_fp16.safetensors"
|
|
||||||
vae_path = "../models/vae/ae.sft"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat holding a sign says 'flux.cpp'"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 4
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "flux"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "flux")
|
|
||||||
text = load_text_encoder(clip_l_path, backend = "cpu", clip_l_path = clip_l_path, family = "flux", t5_path = t5_path)
|
|
||||||
vae = load_vae(vae_path, family = "flux")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
predict = predictor(model, condition)
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,62 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/flux2.md — Flux.2-dev
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/flux2-dev-Q4_K_S.gguf"
|
|
||||||
text_path = "../models/text_encoders/Mistral-Small-3.2-24B-Instruct-2506-Q4_K_M.gguf"
|
|
||||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
|
||||||
|
|
||||||
reference_0_path = "./kontext_input.png"
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "change 'flux.cpp' to 'flux2-dev.cpp'"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "flux2"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sqrt_step(estimate, index, value) {
|
|
||||||
return (estimate + value / estimate) / 2
|
|
||||||
}
|
|
||||||
|
|
||||||
fn positive_sqrt(value) {
|
|
||||||
return fold(tensor::to_list(tensor::arange(0, 32)), value + 1.0, process = sqrt_step, value = value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fit_reference_area(input, area, factor, mode) {
|
|
||||||
shape = tensor::shape(input)
|
|
||||||
width = positive_sqrt(area * shape[0] / shape[1])
|
|
||||||
rounded = [math::round(width / factor) * factor, math::round(width * shape[1] / shape[0] / factor) * factor]
|
|
||||||
size = tensor::maximum(tensor::vector(rounded, dtype = "i64"), tensor::full([2], factor, dtype = "i64"))
|
|
||||||
return tensor::interpolate(input, size = size, mode = mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
reference_0 = image::load(reference_0_path)
|
|
||||||
width = tensor::shape(reference_0)[1]
|
|
||||||
height = tensor::shape(reference_0)[2]
|
|
||||||
|
|
||||||
model = load_dit(model_path, family = "flux2", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "flux2", params_backend = "cpu")
|
|
||||||
vae = load_vae(vae_path, family = "flux2", params_backend = "cpu")
|
|
||||||
|
|
||||||
encode_rng = make_rng(rng_type, seed = seed)
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
reference_0_original = image::to_f32(reference_0, channels = 3)
|
|
||||||
reference_0_pixels = fit_reference_area(reference_0_original, math::min(1048576, width * height), 16, mode = "bilinear")
|
|
||||||
reference_latent_0 = vae_to_dit_latents(vae, vae_encode(vae, reference_0_pixels, rng = encode_rng))
|
|
||||||
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
predict = predictor(model, condition, ref_latents = [reference_latent_0], ref_index_mode = "increase")
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,62 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/flux2.md — Flux.2 klein 4B / Flux.2 klein base 4B
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/flux-2-klein-4b.safetensors"
|
|
||||||
text_path = "../models/text_encoders/qwen_3_4b.safetensors"
|
|
||||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
|
||||||
|
|
||||||
reference_0_path = "./kontext_input.png"
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "change 'flux.cpp' to 'klein.cpp'"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
|
|
||||||
steps = 4
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "flux2"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sqrt_step(estimate, index, value) {
|
|
||||||
return (estimate + value / estimate) / 2
|
|
||||||
}
|
|
||||||
|
|
||||||
fn positive_sqrt(value) {
|
|
||||||
return fold(tensor::to_list(tensor::arange(0, 32)), value + 1.0, process = sqrt_step, value = value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fit_reference_area(input, area, factor, mode) {
|
|
||||||
shape = tensor::shape(input)
|
|
||||||
width = positive_sqrt(area * shape[0] / shape[1])
|
|
||||||
rounded = [math::round(width / factor) * factor, math::round(width * shape[1] / shape[0] / factor) * factor]
|
|
||||||
size = tensor::maximum(tensor::vector(rounded, dtype = "i64"), tensor::full([2], factor, dtype = "i64"))
|
|
||||||
return tensor::interpolate(input, size = size, mode = mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
reference_0 = image::load(reference_0_path)
|
|
||||||
width = tensor::shape(reference_0)[1]
|
|
||||||
height = tensor::shape(reference_0)[2]
|
|
||||||
|
|
||||||
model = load_dit(model_path, family = "flux2_klein", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "flux2_klein", params_backend = "cpu")
|
|
||||||
vae = load_vae(vae_path, family = "flux2_klein", params_backend = "cpu")
|
|
||||||
|
|
||||||
encode_rng = make_rng(rng_type, seed = seed)
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
reference_0_original = image::to_f32(reference_0, channels = 3)
|
|
||||||
reference_0_pixels = fit_reference_area(reference_0_original, math::min(1048576, width * height), 16, mode = "bilinear")
|
|
||||||
reference_latent_0 = vae_to_dit_latents(vae, vae_encode(vae, reference_0_pixels, rng = encode_rng))
|
|
||||||
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
predict = predictor(model, condition, ref_latents = [reference_latent_0], ref_index_mode = "increase")
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/flux2.md — Flux.2 klein 4B / Flux.2 klein base 4B
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/flux-2-klein-4b.safetensors"
|
|
||||||
text_path = "../models/text_encoders/qwen_3_4b.safetensors"
|
|
||||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 4
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "flux2"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "flux2_klein", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "flux2_klein", params_backend = "cpu")
|
|
||||||
vae = load_vae(vae_path, family = "flux2_klein", params_backend = "cpu")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
predict = predictor(model, condition)
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,62 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/flux2.md — Flux.2 klein 9B / Flux.2 klein base 9B
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/flux-2-klein-9b.safetensors"
|
|
||||||
text_path = "../models/text_encoders/qwen_3_8b.safetensors"
|
|
||||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
|
||||||
|
|
||||||
reference_0_path = "./kontext_input.png"
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "change 'flux.cpp' to 'klein.cpp'"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
|
|
||||||
steps = 4
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "flux2"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sqrt_step(estimate, index, value) {
|
|
||||||
return (estimate + value / estimate) / 2
|
|
||||||
}
|
|
||||||
|
|
||||||
fn positive_sqrt(value) {
|
|
||||||
return fold(tensor::to_list(tensor::arange(0, 32)), value + 1.0, process = sqrt_step, value = value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fit_reference_area(input, area, factor, mode) {
|
|
||||||
shape = tensor::shape(input)
|
|
||||||
width = positive_sqrt(area * shape[0] / shape[1])
|
|
||||||
rounded = [math::round(width / factor) * factor, math::round(width * shape[1] / shape[0] / factor) * factor]
|
|
||||||
size = tensor::maximum(tensor::vector(rounded, dtype = "i64"), tensor::full([2], factor, dtype = "i64"))
|
|
||||||
return tensor::interpolate(input, size = size, mode = mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
reference_0 = image::load(reference_0_path)
|
|
||||||
width = tensor::shape(reference_0)[1]
|
|
||||||
height = tensor::shape(reference_0)[2]
|
|
||||||
|
|
||||||
model = load_dit(model_path, family = "flux2_klein", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "flux2_klein", params_backend = "cpu")
|
|
||||||
vae = load_vae(vae_path, family = "flux2_klein", params_backend = "cpu")
|
|
||||||
|
|
||||||
encode_rng = make_rng(rng_type, seed = seed)
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
reference_0_original = image::to_f32(reference_0, channels = 3)
|
|
||||||
reference_0_pixels = fit_reference_area(reference_0_original, math::min(1048576, width * height), 16, mode = "bilinear")
|
|
||||||
reference_latent_0 = vae_to_dit_latents(vae, vae_encode(vae, reference_0_pixels, rng = encode_rng))
|
|
||||||
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
predict = predictor(model, condition, ref_latents = [reference_latent_0], ref_index_mode = "increase")
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/flux2.md — Flux.2 klein 9B / Flux.2 klein base 9B
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/flux-2-klein-9b.safetensors"
|
|
||||||
text_path = "../models/text_encoders/qwen_3_8b.safetensors"
|
|
||||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 4
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "flux2"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "flux2_klein", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "flux2_klein", params_backend = "cpu")
|
|
||||||
vae = load_vae(vae_path, family = "flux2_klein", params_backend = "cpu")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
predict = predictor(model, condition)
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/flux2.md — Flux.2 klein 4B / Flux.2 klein base 4B
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/flux-2-klein-base-4b.safetensors"
|
|
||||||
text_path = "../models/text_encoders/qwen_3_4b.safetensors"
|
|
||||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 4.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "flux2"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "flux2_klein", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "flux2_klein", params_backend = "cpu")
|
|
||||||
vae = load_vae(vae_path, family = "flux2_klein", params_backend = "cpu")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/flux2.md — Flux.2 klein 9B / Flux.2 klein base 9B
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/flux-2-klein-base-9b.safetensors"
|
|
||||||
text_path = "../models/text_encoders/qwen_3_8b.safetensors"
|
|
||||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 4.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "flux2"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "flux2_klein", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "flux2_klein", params_backend = "cpu")
|
|
||||||
vae = load_vae(vae_path, family = "flux2_klein", params_backend = "cpu")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/flux3.md — FLUX.3 Image Klein Base
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/flux-3-image-klein-base.safetensors"
|
|
||||||
text_path = "../models/text_encoders/Qwen3-VL-4B-Instruct-Q4_K_M.gguf"
|
|
||||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat holding a sign says 'flux3.cpp'"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 3.5
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "flux3_klein", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "flux3_klein", params_backend = "cpu")
|
|
||||||
vae = load_vae(vae_path, family = "flux3_klein", params_backend = "cpu")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,62 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/flux3.md — FLUX.3 Image Klein
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/flux-3-image-klein.safetensors"
|
|
||||||
text_path = "../models/text_encoders/Qwen3-VL-4B-Instruct-Q4_K_M.gguf"
|
|
||||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
|
||||||
|
|
||||||
reference_0_path = "../assets/flux/flux1-dev-q8_0.png"
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "change 'flux.cpp' to 'flux3-image-klein.cpp'"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
|
|
||||||
steps = 16
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sqrt_step(estimate, index, value) {
|
|
||||||
return (estimate + value / estimate) / 2
|
|
||||||
}
|
|
||||||
|
|
||||||
fn positive_sqrt(value) {
|
|
||||||
return fold(tensor::to_list(tensor::arange(0, 32)), value + 1.0, process = sqrt_step, value = value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fit_reference_area(input, area, factor, mode) {
|
|
||||||
shape = tensor::shape(input)
|
|
||||||
width = positive_sqrt(area * shape[0] / shape[1])
|
|
||||||
rounded = [math::round(width / factor) * factor, math::round(width * shape[1] / shape[0] / factor) * factor]
|
|
||||||
size = tensor::maximum(tensor::vector(rounded, dtype = "i64"), tensor::full([2], factor, dtype = "i64"))
|
|
||||||
return tensor::interpolate(input, size = size, mode = mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
reference_0 = image::load(reference_0_path)
|
|
||||||
width = tensor::shape(reference_0)[1]
|
|
||||||
height = tensor::shape(reference_0)[2]
|
|
||||||
|
|
||||||
model = load_dit(model_path, family = "flux3_klein", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "flux3_klein", params_backend = "cpu")
|
|
||||||
vae = load_vae(vae_path, family = "flux3_klein", params_backend = "cpu")
|
|
||||||
|
|
||||||
encode_rng = make_rng(rng_type, seed = seed)
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
reference_0_original = image::to_f32(reference_0, channels = 3)
|
|
||||||
reference_0_pixels = fit_reference_area(reference_0_original, math::min(1048576, width * height), 16, mode = "bilinear")
|
|
||||||
reference_latent_0 = vae_to_dit_latents(vae, vae_encode(vae, reference_0_pixels, rng = encode_rng))
|
|
||||||
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
predict = predictor(model, condition, ref_latents = [reference_latent_0], ref_index_mode = "increase")
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/flux3.md — FLUX.3 Image Klein
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/flux-3-image-klein.safetensors"
|
|
||||||
text_path = "../models/text_encoders/Qwen3-VL-4B-Instruct-Q4_K_M.gguf"
|
|
||||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat holding a sign says 'flux3.cpp'"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 16
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "flux3_klein", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "flux3_klein", params_backend = "cpu")
|
|
||||||
vae = load_vae(vae_path, family = "flux3_klein", params_backend = "cpu")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
predict = predictor(model, condition)
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/hidream_o1_image.md — HiDream-O1-Image-Dev
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/checkpoints/hidream_o1_image_dev_bf16.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat holding a sign says 'hidream o1 cpp'"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 1024
|
|
||||||
height = 1024
|
|
||||||
|
|
||||||
steps = 28
|
|
||||||
method = "lcm"
|
|
||||||
scheduler = "lcm"
|
|
||||||
noise_scale = 8.0
|
|
||||||
extra_sample_args = "noise_scale_start=7.5,noise_scale_end=7.5,noise_clip_std=2.5"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "hidream_o1")
|
|
||||||
text = load_text_encoder(model_path, family = "hidream_o1")
|
|
||||||
vae = load_vae(model_path, family = "hidream_o1")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
predict = predictor(model, condition)
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
noise = tensor::affine(tensor::randn_like(base, rng = rng), scale = noise_scale)
|
|
||||||
start = add_noise(predict, base, noise, sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng, extra_args = extra_sample_args)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/hunyuan_video.md — Text-to-video example
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/hunyuanvideo1.5_720p_t2v_fp16.safetensors"
|
|
||||||
text_path = "../models/text_encoders/qwen_2.5_vl_7b.safetensors"
|
|
||||||
t5_path = "../models/text_encoders/byt5_small_glyphxl_fp16.safetensors"
|
|
||||||
vae_path = "../models/vae/hunyuanvideo15_vae_fp16.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.avi"
|
|
||||||
|
|
||||||
prompt = "a lovely cat"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 1280
|
|
||||||
height = 720
|
|
||||||
frames = 33
|
|
||||||
fps = 16
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 6.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "hunyuan_video", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "hunyuan_video", params_backend = "cpu", t5_path = t5_path)
|
|
||||||
vae = load_vae(vae_path, family = "hunyuan_video", params_backend = "cpu")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height, frames = frames))
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
output_frames = vae_decode(vae, dit_to_vae_latents(vae, latent), tiling = tiling())
|
|
||||||
video::save(output_path, {frames = output_frames, fps_num = fps, fps_den = 1}, audio = {})
|
|
||||||
return {video = {frames = output_frames, fps_num = fps, fps_den = 1}, latent = latent, audio = {}}
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/ideogram4.md — CLI
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/ideogram4-Q8_0.gguf"
|
|
||||||
negative_model_path = "../models/diffusion_models/ideogram4_uncond-Q8_0.gguf"
|
|
||||||
text_path = "../models/text_encoders/Qwen3VL-8B-Instruct-Q4_K_M.gguf"
|
|
||||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "{\"high_level_description\":\"A square 1024 x 1024 luxury fashion magazine cover featuring exactly one short chubby fluffy cat as the main model. The cat sits on a soft ivory studio floor, facing the viewer with a stylish calm expression, wearing tiny black sunglasses, a red silk scarf, and a small gold collar charm. In front of the cat on the floor is a wide horizontal luxury nameplate that clearly reads ideogram4.cpp. The whole design feels premium, fashionable, clean, and editorial.\",\"style_description\":{\"aesthetics\":\"luxury fashion magazine cover, high-end pet couture campaign, minimalist editorial design, elegant studio photography, soft paper texture, refined typography, fashionable and polished\",\"lighting\":\"Soft diffused studio lighting, gentle spotlight on the cat, subtle floor shadow, warm ivory highlights, clean separation between subject and background\",\"photo\":\"high-resolution fashion editorial photography look, front-facing cat portrait, crisp fur details, glossy sunglasses, clear readable nameplate text, shallow depth of field\",\"medium\":\"mixed media fashion photography and premium editorial graphic design\",\"color_palette\":[\"#F4EFE7\",\"#111111\",\"#D8B56D\",\"#B73A3A\",\"#FFFFFF\",\"#8A7A6A\"]},\"compositional_deconstruction\":{\"canvas\":\"Square 1024 x 1024 canvas with a normal upright orientation. Do not rotate the poster or any text. Use a clean fashion magazine cover layout.\",\"background\":\"Warm ivory studio backdrop with subtle paper grain, a soft spotlight gradient, faint floor shadow, and a few minimal gold editorial lines. The background is spacious, premium, and uncluttered.\",\"layout\":\"Top center has a small elegant headline. Center area features one cat as the main fashion model. Lower foreground has a wide horizontal luxury nameplate placed on the floor in front of the cat. Bottom center has a small footer. All text is horizontal, upright, and readable left to right.\",\"elements\":[{\"type\":\"text\",\"desc\":\"Top center headline reading LOOK WHAT I FOUND in a refined high-fashion serif font. The headline is horizontal, centered, elegant, and secondary to the nameplate text.\"},{\"type\":\"obj\",\"desc\":\"Exactly one short chubby fluffy cat sitting in the center like a luxury fashion model. The cat has a large round head, compact body, short legs, soft detailed fur, expressive eyes, and a calm confident pose. The cat is cute and rounded, not tall, not stretched, not duplicated.\"},{\"type\":\"obj\",\"desc\":\"Tiny glossy black sunglasses worn naturally by the cat, slightly oversized but still showing the cat face clearly. The sunglasses add a chic fashion-editorial attitude.\"},{\"type\":\"obj\",\"desc\":\"A red silk scarf tied neatly around the cat neck, with soft folds and a couture feeling. The scarf must not cover the cat face or the nameplate.\"},{\"type\":\"obj\",\"desc\":\"A small gold collar charm or fashion accessory under the scarf, subtle and premium, adding a luxury campaign detail.\"},{\"type\":\"obj\",\"desc\":\"In the lower foreground, place a wide horizontal luxury nameplate on the floor in front of the cat. The nameplate is low, flat, landscape-oriented, much wider than tall, like a fashion show seat card or premium display plaque. It is centered, front-facing, level, and fully visible. It must not become vertical, tall, standing, rotated, or side-facing.\"},{\"type\":\"text\",\"desc\":\"Print the exact text ideogram4.cpp only on the wide horizontal nameplate. Use clean bold black lettering, perfectly spelled, lowercase, with the number 4 and .cpp extension. The text must fit completely inside the nameplate, stay horizontal, and be readable from left to right.\"},{\"type\":\"obj\",\"desc\":\"Add sparse premium editorial accents around the edges: thin gold lines, small code brackets, tiny cursor marks, subtle dots, and minimal geometric details. No extra cats, no stickers, no animal faces, no busy decorations.\"},{\"type\":\"text\",\"desc\":\"Bottom center footer reading tiny paws, big compile energy in a small refined monospace or editorial font. The footer is horizontal, centered, understated, and much smaller than the nameplate text.\"}]}}"
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 1024
|
|
||||||
height = 1024
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 7.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "logit_normal"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "ideogram4", params_backend = "cpu")
|
|
||||||
negative_model = load_dit(negative_model_path, family = "ideogram4", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "ideogram4", params_backend = "cpu")
|
|
||||||
vae = load_vae(vae_path, family = "ideogram4", params_backend = "cpu")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = {vector = tensor::vector([1])}
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(negative_model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(pos, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/ip_adapter.md — Plus variants
|
|
||||||
|
|
||||||
var {
|
|
||||||
weights = "../models/checkpoints/sd_v1.5.safetensors"
|
|
||||||
vision_encoder_path = "../models/clip_vision/clip_vision_h.safetensors"
|
|
||||||
ip_adapter_path = "../models/ipadapter/ip-adapter-plus_sd15.safetensors"
|
|
||||||
|
|
||||||
input_path = "../inputs/reference.png"
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a woman, best quality"
|
|
||||||
negative_prompt = "lowres, bad anatomy"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 30
|
|
||||||
cfg_scale = 7.0
|
|
||||||
method = "dpm++2m"
|
|
||||||
scheduler = "karras"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
unet = load_unet(weights)
|
|
||||||
text = load_text_encoder(weights)
|
|
||||||
vae = load_vae(weights)
|
|
||||||
vision = load_vision_encoder(vision_encoder_path)
|
|
||||||
adapter = ip_adapter::load(ip_adapter_path, family = "sd1")
|
|
||||||
reference = image::load(input_path)
|
|
||||||
embedding = encode_vision(vision, reference)
|
|
||||||
positive_image = ip_adapter::project(adapter, embedding)
|
|
||||||
negative_embedding = encode_vision(vision, reference, zero_input = true)
|
|
||||||
negative_image = ip_adapter::project(adapter, negative_embedding)
|
|
||||||
positive = ip_adapter::apply(encode_prompt(text, prompt, width = width, height = height), adapter, positive_image, strength = 0.8)
|
|
||||||
negative = ip_adapter::apply(encode_prompt(text, negative_prompt, width = width, height = height), adapter, negative_image, strength = 0.8)
|
|
||||||
pos = predictor(unet, positive, prediction = "eps")
|
|
||||||
neg = predictor(unet, negative, prediction = "eps")
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, scheduler = scheduler, steps = steps)
|
|
||||||
rng = make_rng("cuda", seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, unet_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return { image = image, latent = latent, image_tokens = positive_image }
|
|
||||||
}
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/ip_adapter.md — Example (SD 1.5)
|
|
||||||
|
|
||||||
var {
|
|
||||||
weights = "../models/checkpoints/sd_v1.5.safetensors"
|
|
||||||
vision_encoder_path = "../models/clip_vision/clip_vision_h.safetensors"
|
|
||||||
ip_adapter_path = "../models/ipadapter/ip-adapter_sd15.safetensors"
|
|
||||||
|
|
||||||
input_path = "../inputs/reference.png"
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a woman, best quality"
|
|
||||||
negative_prompt = "lowres, bad anatomy"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 30
|
|
||||||
cfg_scale = 7.0
|
|
||||||
method = "dpm++2m"
|
|
||||||
scheduler = "karras"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
unet = load_unet(weights)
|
|
||||||
text = load_text_encoder(weights)
|
|
||||||
vae = load_vae(weights)
|
|
||||||
vision = load_vision_encoder(vision_encoder_path)
|
|
||||||
adapter = ip_adapter::load(ip_adapter_path, family = "sd1")
|
|
||||||
embedding = encode_vision(vision, image::load(input_path), pooled = true)
|
|
||||||
positive_image = ip_adapter::project(adapter, embedding)
|
|
||||||
negative_image = ip_adapter::project(adapter, tensor::zeros_like(embedding))
|
|
||||||
positive = ip_adapter::apply(encode_prompt(text, prompt, width = width, height = height), adapter, positive_image, strength = 0.8)
|
|
||||||
negative = ip_adapter::apply(encode_prompt(text, negative_prompt, width = width, height = height), adapter, negative_image, strength = 0.8)
|
|
||||||
pos = predictor(unet, positive, prediction = "eps")
|
|
||||||
neg = predictor(unet, negative, prediction = "eps")
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, scheduler = scheduler, steps = steps)
|
|
||||||
rng = make_rng("cuda", seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, unet_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return { image = image, latent = latent, image_tokens = positive_image }
|
|
||||||
}
|
|
||||||
|
|
@ -1,76 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/ip_adapter.md — Combining with Control Net
|
|
||||||
|
|
||||||
var {
|
|
||||||
weights = "../models/checkpoints/sdxl.safetensors"
|
|
||||||
vision_encoder_path = "../models/clip_vision/clip_vision_h.safetensors"
|
|
||||||
ip_adapter_path = "../models/ipadapter/ip-adapter_sdxl_vit-h.safetensors"
|
|
||||||
control_path = "../models/controlnet/OpenPoseXL2.safetensors"
|
|
||||||
|
|
||||||
input_path = "../inputs/character.png"
|
|
||||||
control_image_path = "../inputs/pose.png"
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a character, side view"
|
|
||||||
negative_prompt = ""
|
|
||||||
zero_negative = true
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
width = 1024
|
|
||||||
height = 1024
|
|
||||||
|
|
||||||
steps = 25
|
|
||||||
cfg_scale = 6.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fit_canvas(input, width, height, mode) {
|
|
||||||
shape = tensor::shape(input)
|
|
||||||
crop_width = math::min(shape[1], math::floor(shape[2] * width / height))
|
|
||||||
crop_height = math::min(shape[2], math::floor(shape[1] * height / width))
|
|
||||||
start = [math::floor((shape[1] - crop_width) / 2), math::floor((shape[2] - crop_height) / 2)]
|
|
||||||
cropped = tensor::crop(input, axes = [1, 2], start = start, size = [crop_width, crop_height])
|
|
||||||
return tensor::interpolate(cropped, size = [width, height], axes = [1, 2], mode = mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sdxl_zero_text(cond) {
|
|
||||||
zeroed = zero_out(cond, fields = ["crossattn"])
|
|
||||||
pooled_zeros = tensor::zeros_like(cond.vector[:1280])
|
|
||||||
adm = tensor::replace_slice(cond.vector, pooled_zeros, axis = 0, start = 0)
|
|
||||||
return {crossattn = zeroed.crossattn, vector = adm}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
unet = load_unet(weights)
|
|
||||||
text = load_text_encoder(weights)
|
|
||||||
vae = load_vae(weights, conv_scale = 0.03125)
|
|
||||||
vision = load_vision_encoder(vision_encoder_path)
|
|
||||||
adapter = ip_adapter::load(ip_adapter_path, family = "sdxl")
|
|
||||||
embedding = encode_vision(vision, image::load(input_path), pooled = true)
|
|
||||||
positive_image = ip_adapter::project(adapter, embedding)
|
|
||||||
negative_image = ip_adapter::project(adapter, tensor::zeros_like(embedding))
|
|
||||||
positive = ip_adapter::apply(encode_prompt(text, prompt, width = width, height = height), adapter, positive_image, strength = 0.9)
|
|
||||||
negative_text = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
negative_condition = if zero_negative {
|
|
||||||
sdxl_zero_text(negative_text)
|
|
||||||
} else {
|
|
||||||
{crossattn = negative_text.crossattn, vector = negative_text.vector}
|
|
||||||
}
|
|
||||||
negative = ip_adapter::apply(negative_condition, adapter, negative_image, strength = 0.9)
|
|
||||||
control = controlnet::load(control_path, family = "sdxl")
|
|
||||||
hint = fit_canvas(image::load(control_image_path), width, height, mode = "nearest")
|
|
||||||
controlled_positive = controlnet::apply(positive, control, hint, strength = 0.8)
|
|
||||||
controlled_negative = controlnet::apply(negative, control, hint, strength = 0.8)
|
|
||||||
pos = predictor(unet, controlled_positive, prediction = "eps")
|
|
||||||
neg = predictor(unet, controlled_negative, prediction = "eps")
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, scheduler = scheduler, steps = steps)
|
|
||||||
rng = make_rng("cuda", seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, unet_to_vae_latents(vae, latent), tiling = tiling())
|
|
||||||
image::save(output_path, image)
|
|
||||||
return { image = image, latent = latent, image_tokens = positive_image }
|
|
||||||
}
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/ip_adapter.md — Example (SDXL)
|
|
||||||
|
|
||||||
var {
|
|
||||||
weights = "../models/checkpoints/sdxl.safetensors"
|
|
||||||
vision_encoder_path = "../models/clip_vision/clip_vision_h.safetensors"
|
|
||||||
ip_adapter_path = "../models/ipadapter/ip-adapter_sdxl_vit-h.safetensors"
|
|
||||||
|
|
||||||
input_path = "../inputs/reference.png"
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a woman, best quality"
|
|
||||||
negative_prompt = "lowres, bad anatomy"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
width = 1024
|
|
||||||
height = 1024
|
|
||||||
|
|
||||||
steps = 25
|
|
||||||
cfg_scale = 6.0
|
|
||||||
method = "dpm++2m"
|
|
||||||
scheduler = "karras"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
unet = load_unet(weights)
|
|
||||||
text = load_text_encoder(weights)
|
|
||||||
vae = load_vae(weights, conv_scale = 0.03125)
|
|
||||||
vision = load_vision_encoder(vision_encoder_path)
|
|
||||||
adapter = ip_adapter::load(ip_adapter_path, family = "sdxl")
|
|
||||||
embedding = encode_vision(vision, image::load(input_path), pooled = true)
|
|
||||||
positive_image = ip_adapter::project(adapter, embedding)
|
|
||||||
negative_image = ip_adapter::project(adapter, tensor::zeros_like(embedding))
|
|
||||||
positive = ip_adapter::apply(encode_prompt(text, prompt, width = width, height = height), adapter, positive_image, strength = 0.8)
|
|
||||||
negative = ip_adapter::apply(encode_prompt(text, negative_prompt, width = width, height = height), adapter, negative_image, strength = 0.8)
|
|
||||||
pos = predictor(unet, positive, prediction = "eps")
|
|
||||||
neg = predictor(unet, negative, prediction = "eps")
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, scheduler = scheduler, steps = steps)
|
|
||||||
rng = make_rng("cuda", seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, unet_to_vae_latents(vae, latent), tiling = tiling())
|
|
||||||
image::save(output_path, image)
|
|
||||||
return { image = image, latent = latent, image_tokens = positive_image }
|
|
||||||
}
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/iris.md — CLI
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/iris-3b.safetensors"
|
|
||||||
text_path = "../models/text_encoders/Qwen3-VL-4B-Instruct-Q4_K_M.gguf"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 1024
|
|
||||||
height = 1024
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 3.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "iris_3b")
|
|
||||||
text = load_text_encoder(text_path, family = "iris_3b")
|
|
||||||
base = tensor::zeros([width, height, 3, 1])
|
|
||||||
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
pixels = tensor::clamp(tensor::affine(latent, scale = 0.5, offset = 0.5), 0, 1)
|
|
||||||
image = image::to_u8(pixels)
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,63 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/kontext.md — Example
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/flux1-kontext-dev-q8_0.gguf"
|
|
||||||
clip_l_path = "../models/text_encoders/clip_l.safetensors"
|
|
||||||
t5_path = "../models/text_encoders/t5xxl_fp16.safetensors"
|
|
||||||
vae_path = "../models/vae/ae.sft"
|
|
||||||
|
|
||||||
reference_0_path = "./flux1-dev-q8_0.png"
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "change 'flux.cpp' to 'kontext.cpp'"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "flux"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn sqrt_step(estimate, index, value) {
|
|
||||||
return (estimate + value / estimate) / 2
|
|
||||||
}
|
|
||||||
|
|
||||||
fn positive_sqrt(value) {
|
|
||||||
return fold(tensor::to_list(tensor::arange(0, 32)), value + 1.0, process = sqrt_step, value = value)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fit_reference_area(input, area, factor, mode) {
|
|
||||||
shape = tensor::shape(input)
|
|
||||||
width = positive_sqrt(area * shape[0] / shape[1])
|
|
||||||
rounded = [math::round(width / factor) * factor, math::round(width * shape[1] / shape[0] / factor) * factor]
|
|
||||||
size = tensor::maximum(tensor::vector(rounded, dtype = "i64"), tensor::full([2], factor, dtype = "i64"))
|
|
||||||
return tensor::interpolate(input, size = size, mode = mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
reference_0 = image::load(reference_0_path)
|
|
||||||
width = tensor::shape(reference_0)[1]
|
|
||||||
height = tensor::shape(reference_0)[2]
|
|
||||||
|
|
||||||
model = load_dit(model_path, family = "flux")
|
|
||||||
text = load_text_encoder(clip_l_path, backend = "cpu", clip_l_path = clip_l_path, family = "flux", t5_path = t5_path)
|
|
||||||
vae = load_vae(vae_path, family = "flux")
|
|
||||||
|
|
||||||
encode_rng = make_rng(rng_type, seed = seed)
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
reference_0_original = image::to_f32(reference_0, channels = 3)
|
|
||||||
reference_0_pixels = fit_reference_area(reference_0_original, math::min(1048576, width * height), 16, mode = "bilinear")
|
|
||||||
reference_latent_0 = vae_to_dit_latents(vae, vae_encode(vae, reference_0_pixels, rng = encode_rng))
|
|
||||||
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
predict = predictor(model, condition, ref_latents = [reference_latent_0])
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/krea2.md — Krea2
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/Krea-2-Raw-Q8_0.gguf"
|
|
||||||
text_path = "../models/text_encoders/Qwen3-VL-4B-Instruct-Q4_K_M.gguf"
|
|
||||||
vae_path = "../models/vae/wan_2.1_vae.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat holding a sign says 'krea2.cpp'"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 7.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "krea2", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "krea2", params_backend = "cpu")
|
|
||||||
vae = load_vae(vae_path, family = "krea2", params_backend = "cpu")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/lcm.md — LCM-LoRA with SD 1.5
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/checkpoints/v1-5-pruned-emaonly.safetensors"
|
|
||||||
lora_0_path = "../models/loras/lcm-lora-sdv1-5.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 4
|
|
||||||
method = "euler_a"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
base_model = load_unet(model_path, family = "sd1")
|
|
||||||
text = load_text_encoder(model_path, family = "sd1")
|
|
||||||
vae = load_vae(model_path, family = "sd1")
|
|
||||||
|
|
||||||
lora_0 = load_lora(lora_0_path)
|
|
||||||
model = apply_lora(base_model, lora_0)
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
predict = predictor(model, condition)
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, unet_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,39 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/lens.md — Lens Turbo
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/lens_turbo_bf16.safetensors"
|
|
||||||
text_path = "../models/text_encoders/gpt-oss-20b-UD-Q8_K_XL.gguf"
|
|
||||||
tokenizer_path = "../models/tokenizers/tokenizer_gpt_oss.json"
|
|
||||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "A crystal dragon soaring through an aurora borealis sky, its entire body made of transparent faceted crystal refracting the green and purple aurora light into rainbow spectra, ice particles trailing from its wings, high fantasy digital art"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 4
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "lens")
|
|
||||||
text = load_text_encoder(text_path, family = "lens", tokenizer = tokenizer_path)
|
|
||||||
vae = load_vae(vae_path, family = "lens")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
predict = predictor(model, condition)
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/lens.md — Lens
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/lens_bf16.safetensors"
|
|
||||||
text_path = "../models/text_encoders/gpt-oss-20b-UD-Q8_K_XL.gguf"
|
|
||||||
tokenizer_path = "../models/tokenizers/tokenizer_gpt_oss.json"
|
|
||||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "A crystal dragon soaring through an aurora borealis sky, its entire body made of transparent faceted crystal refracting the green and purple aurora light into rainbow spectra, ice particles trailing from its wings, high fantasy digital art"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 5.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "lens")
|
|
||||||
text = load_text_encoder(text_path, family = "lens", tokenizer = tokenizer_path)
|
|
||||||
vae = load_vae(vae_path, family = "lens")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/lingbot_video.md — LingBot-Video T2V
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/lingbot-video-dens-1.3b.safetensors"
|
|
||||||
text_path = "../models/text_encoders/Qwen3-VL-4B-Instruct-Q4_K_M.gguf"
|
|
||||||
vae_path = "../models/vae/wan_2.1_vae.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.avi"
|
|
||||||
|
|
||||||
negative_prompt = "{\"universal_negative\":{\"visual_quality\":[\"low quality\",\"worst quality\",\"blurry\",\"pixelated\",\"jpeg artifacts\",\"low resolution\",\"unstable color\",\"color flicker\",\"underexposed\",\"overexposed\",\"invisible subject\",\"subject hidden in darkness\"],\"artistic_style\":[\"painting\",\"illustration\",\"drawing\",\"cartoon\",\"3d render\",\"cgi\",\"sketch\",\"digital art\"],\"composition_and_content\":[\"text\",\"watermark\",\"signature\",\"logo\",\"subtitles\",\"pillarboxed\",\"side bars\",\"portrait image in landscape frame\"],\"temporal_and_motion_stability\":[\"flickering\",\"jittery\",\"motion blur\",\"temporal inconsistency\",\"warping\",\"morphing\",\"incoherent motion\",\"unnatural movement\",\"static object with sudden jump\",\"frame-to-frame inconsistency\"],\"material_and_structure\":[\"plastic-like glass\",\"unrealistic texture\",\"deformed bottle\",\"liquid freezing improperly\",\"distorted reflections\"]}}"
|
|
||||||
prompt = "{\"caption\":{\"comprehensive_description\":\"A lovely cat sits comfortably on a soft cushion near a sunlit window, looking calm, gentle, and adorable. The cat has soft fluffy fur, bright expressive eyes, small rounded ears, delicate whiskers, and a relaxed posture. Warm daylight falls across the cat from one side, creating soft highlights on the fur and a cozy glow around the scene. The background is softly blurred, showing hints of a peaceful indoor home environment with warm tones and gentle natural light. The overall atmosphere is cute, tender, serene, and photorealistic, emphasizing the cats charming appearance, soft texture, and affectionate presence.\",\"camera_info\":{\"color\":\"Warm\",\"frame_size\":\"Close Up\",\"shot_type_angle\":\"Eye level\",\"lens_size\":\"Medium Lens\",\"composition\":\"Centered balanced\",\"lighting\":\"Soft light\",\"lighting_type\":\"Daylight\"},\"world_knowledge\":[],\"prominent_elements\":[{\"name\":\"lovely cat\",\"description\":\"A cute and gentle domestic cat with soft fluffy fur, expressive eyes, and a calm relaxed presence.\",\"location\":\"center of the frame\",\"relative_size\":\"large\",\"shape_and_color\":\"Small animal body with rounded face, triangular ears, bright eyes, and soft fur in warm natural tones\",\"texture\":\"soft, fluffy, silky\",\"appearance_details\":\"The cat has clean well-groomed fur, delicate whiskers, small ears, a cute nose, and bright attentive eyes. Its expression appears calm, affectionate, and slightly curious.\",\"relationship\":\"Acts as the main subject and emotional focal point of the scene.\",\"orientation\":\"facing the camera\",\"pose\":\"sitting comfortably with a relaxed posture\",\"expression\":\"gentle, adorable, calm, slightly curious\",\"clothing\":\"\",\"gender\":\"\",\"skin_tone_and_texture\":\"\"},{\"name\":\"cat eyes\",\"description\":\"Bright expressive eyes that give the cat a sweet and affectionate appearance.\",\"location\":\"upper center of the cat face\",\"relative_size\":\"small\",\"shape_and_color\":\"Round almond-like eyes with glossy reflections\",\"texture\":\"clear, glossy, reflective\",\"appearance_details\":\"The eyes catch the soft daylight, creating small natural highlights that make the cat look vivid and alive.\",\"relationship\":\"Enhance the emotional charm and cuteness of the cat.\",\"orientation\":\"looking toward the camera\",\"pose\":\"\",\"expression\":\"soft and attentive\",\"clothing\":\"\",\"gender\":\"\",\"skin_tone_and_texture\":\"\"},{\"name\":\"soft cushion\",\"description\":\"A comfortable cushion or blanket where the cat is resting.\",\"location\":\"bottom portion of the frame\",\"relative_size\":\"medium\",\"shape_and_color\":\"Soft rounded fabric surface in light warm neutral tones\",\"texture\":\"plush, fabric, cozy\",\"appearance_details\":\"The cushion gently supports the cat and adds a comfortable home-like feeling to the scene.\",\"relationship\":\"Provides a cozy resting place for the cat.\",\"orientation\":\"horizontal\",\"pose\":\"\",\"expression\":\"\",\"clothing\":\"\",\"gender\":\"\",\"skin_tone_and_texture\":\"\"},{\"name\":\"sunlit indoor background\",\"description\":\"A softly blurred indoor background with warm daylight and peaceful home atmosphere.\",\"location\":\"behind the cat, filling the upper and side areas of the frame\",\"relative_size\":\"large\",\"shape_and_color\":\"Soft abstract shapes in warm beige, cream, and pale golden tones\",\"texture\":\"soft, blurry, bokeh-like\",\"appearance_details\":\"The background is intentionally out of focus, keeping attention on the cat while creating a cozy and serene mood.\",\"relationship\":\"Provides a warm and gentle environment that supports the cute domestic scene.\",\"orientation\":\"upright\",\"pose\":\"\",\"expression\":\"\",\"clothing\":\"\",\"gender\":\"\",\"skin_tone_and_texture\":\"\",\"is_cluster\":true,\"number_of_objects\":\"numerous\"}]}}"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
frames = 33
|
|
||||||
fps = 16
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 3.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "lingbot_video", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "lingbot_video", params_backend = "cpu")
|
|
||||||
vae = load_vae(vae_path, family = "lingbot_video", params_backend = "cpu")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height, frames = frames))
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
output_frames = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
video::save(output_path, {frames = output_frames, fps_num = fps, fps_den = 1}, audio = {})
|
|
||||||
return {video = {frames = output_frames, fps_num = fps, fps_den = 1}, latent = latent, audio = {}}
|
|
||||||
}
|
|
||||||
|
|
@ -1,48 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/llada_image.md — Image editing
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/llada-image-turbo-f16.gguf"
|
|
||||||
text_path = "../models/text_encoders/llada-image-turbo-text_encoder-q8_0.gguf"
|
|
||||||
connectors_path = "../models/text_encoders/llada-image-turbo-connectors-edit.safetensors"
|
|
||||||
tokenizer_path = "../models/tokenizers/tokenizer.json"
|
|
||||||
vae_path = "../models/vae/llada_vae.safetensors"
|
|
||||||
|
|
||||||
reference_0_path = "../inputs/input.png"
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "change the sign text to 'sd.cpp'"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 1024
|
|
||||||
height = 1024
|
|
||||||
|
|
||||||
steps = 4
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "llada_image"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
reference_0 = image::load(reference_0_path)
|
|
||||||
|
|
||||||
model = load_dit(model_path, family = "llada_image")
|
|
||||||
text = load_text_encoder(text_path, connectors_path = connectors_path, family = "llada_image", tokenizer = tokenizer_path)
|
|
||||||
vae = load_vae(vae_path, family = "llada_image")
|
|
||||||
|
|
||||||
encode_rng = make_rng(rng_type, seed = seed)
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
reference_0_original = image::to_f32(reference_0, channels = 3)
|
|
||||||
reference_0_pixels = tensor::interpolate(reference_0_original, size = [width, height], mode = "bilinear")
|
|
||||||
reference_latent_0 = vae_to_dit_latents(vae, vae_encode(vae, reference_0_pixels, rng = encode_rng))
|
|
||||||
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height, media = [reference_0_pixels])
|
|
||||||
predict = predictor(model, condition, ref_latents = [reference_latent_0], force_ref_timestep_zero = true)
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/llada_image.md — Text to image
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/llada-image-turbo-f16.gguf"
|
|
||||||
text_path = "../models/text_encoders/llada-image-turbo-text_encoder-q8_0.gguf"
|
|
||||||
connectors_path = "../models/text_encoders/llada-image-turbo-connectors.safetensors"
|
|
||||||
tokenizer_path = "../models/tokenizers/tokenizer.json"
|
|
||||||
vae_path = "../models/vae/llada_vae.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat holding a sign says 'llada.cpp'"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 1024
|
|
||||||
height = 1024
|
|
||||||
|
|
||||||
steps = 4
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "llada_image"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "llada_image")
|
|
||||||
text = load_text_encoder(text_path, connectors_path = connectors_path, family = "llada_image", tokenizer = tokenizer_path)
|
|
||||||
vae = load_vae(vae_path, family = "llada_image")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
predict = predictor(model, condition)
|
|
||||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = predict, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/longcat_image.md — LongCat Image
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/LongCat-Image-Q4_K_M.gguf"
|
|
||||||
text_path = "../models/text_encoders/Qwen2.5-VL-7B-Instruct-Q8_0.gguf"
|
|
||||||
vae_path = "../models/vae/ae.sft"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat holding a sign says 'longcat.cpp'"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 5.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "longcat_image", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "longcat_image", params_backend = "cpu")
|
|
||||||
vae = load_vae(vae_path, family = "longcat_image", params_backend = "cpu")
|
|
||||||
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler, flow_shift = 3.0)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,45 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/lora.md — CLI
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/checkpoints/v1-5-pruned-emaonly.safetensors"
|
|
||||||
lora_0_path = "../models/loras/marblesh.safetensors"
|
|
||||||
|
|
||||||
output_path = "output.png"
|
|
||||||
|
|
||||||
prompt = "a lovely cat"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 512
|
|
||||||
height = 512
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 7.0
|
|
||||||
method = "euler_a"
|
|
||||||
scheduler = "discrete"
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
base_model = load_unet(model_path, family = "sd1")
|
|
||||||
base_text = load_text_encoder(model_path, family = "sd1")
|
|
||||||
vae = load_vae(model_path, family = "sd1")
|
|
||||||
|
|
||||||
lora_0 = load_lora(lora_0_path)
|
|
||||||
model = apply_lora(base_model, lora_0)
|
|
||||||
text = apply_lora(base_text, lora_0)
|
|
||||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive)
|
|
||||||
neg = predictor(model, negative)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
image = vae_decode(vae, unet_to_vae_latents(vae, latent))
|
|
||||||
image::save(output_path, image)
|
|
||||||
return {image = image, latent = latent}
|
|
||||||
}
|
|
||||||
|
|
@ -1,100 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/ltx2.md — LTX-2.3 dev FLF2V
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/ltx-2.3-22b-dev-UD-Q4_K_M.gguf"
|
|
||||||
text_path = "../models/text_encoders/gemma-3-12b-it-qat-UD-Q4_K_XL.gguf"
|
|
||||||
connectors_path = "../models/text_encoders/ltx-2.3-22b-dev_embeddings_connectors.safetensors"
|
|
||||||
vae_path = "../models/vae/ltx-2.3-22b-dev_video_vae.safetensors"
|
|
||||||
audio_vae_path = "../models/vae/ltx-2.3-22b-dev_audio_vae.safetensors"
|
|
||||||
|
|
||||||
first_frame_path = "../inputs/start_image.png"
|
|
||||||
last_frame_path = "../inputs/end_image.png"
|
|
||||||
output_path = "flf2v.avi"
|
|
||||||
|
|
||||||
prompt = "glass flower blossom"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 1280
|
|
||||||
height = 736
|
|
||||||
frames = 33
|
|
||||||
fps = 16
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 6.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "ltx2"
|
|
||||||
strength = 0.75
|
|
||||||
audio_scale = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fit_canvas(input, width, height, mode) {
|
|
||||||
shape = tensor::shape(input)
|
|
||||||
crop_width = math::min(shape[1], math::floor(shape[2] * width / height))
|
|
||||||
crop_height = math::min(shape[2], math::floor(shape[1] * height / width))
|
|
||||||
start = [math::floor((shape[1] - crop_width) / 2), math::floor((shape[2] - crop_height) / 2)]
|
|
||||||
cropped = tensor::crop(input, axes = [1, 2], start = start, size = [crop_width, crop_height])
|
|
||||||
return tensor::interpolate(cropped, size = [width, height], axes = [1, 2], mode = mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pack_av(video, audio, audio_scale) {
|
|
||||||
shape = tensor::shape(video)
|
|
||||||
count = tensor::numel(audio)
|
|
||||||
tail_channels = math::ceil_div(count, shape[0] * shape[1] * shape[2])
|
|
||||||
tail_shape = [shape[0], shape[1], shape[2], tail_channels, 1]
|
|
||||||
flat = tensor::reshape(tensor::mul(audio, audio_scale), [count])
|
|
||||||
padded = tensor::pad(flat, [0, math::product(tail_shape) - count])
|
|
||||||
return tensor::concat([video, tensor::reshape(padded, tail_shape)], axis = 3)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn unpack_audio(packed, channels, audio_shape, audio_scale) {
|
|
||||||
tail = packed[:, :, :, channels:]
|
|
||||||
flat = tensor::reshape(tail, [tensor::numel(tail)])
|
|
||||||
return tensor::div(tensor::reshape(flat[:math::product(audio_shape)], audio_shape), audio_scale)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
first_frame = image::load(first_frame_path)
|
|
||||||
last_frame = image::load(last_frame_path)
|
|
||||||
|
|
||||||
model = load_dit(model_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, connectors_path = connectors_path, family = "ltxav", params_backend = "cpu", projection_path = model_path)
|
|
||||||
vae = load_vae(vae_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
video_base = tensor::zeros(latent_shape(vae, width = width, height = height, frames = frames))
|
|
||||||
first_frame_pixels = tensor::unsqueeze(image::to_f32(fit_canvas(first_frame, width, height, mode = "nearest"), channels = 3), axis = 2)
|
|
||||||
last_frame_pixels = tensor::unsqueeze(image::to_f32(fit_canvas(last_frame, width, height, mode = "nearest"), channels = 3), axis = 2)
|
|
||||||
video_shape = tensor::shape(video_base)
|
|
||||||
video_mask = tensor::full([video_shape[0], video_shape[1], video_shape[2], 1, 1], 1)
|
|
||||||
first_latent = vae_to_dit_latents(vae, vae_encode(vae, first_frame_pixels, rng = rng))
|
|
||||||
video_first = tensor::replace_slice(video_base, first_latent, axis = 2, start = 0)
|
|
||||||
mask_first = tensor::index_fill(video_mask, axis = 2, indices = [0], value = 1 - strength)
|
|
||||||
last_latent = vae_to_dit_latents(vae, vae_encode(vae, last_frame_pixels, rng = rng))
|
|
||||||
tail_mask = tensor::full([video_shape[0], video_shape[1], tensor::shape(last_latent)[2], 1, 1], 1 - strength)
|
|
||||||
video_conditioned = tensor::concat([video_first, last_latent], axis = 2)
|
|
||||||
mask_conditioned = tensor::concat([mask_first, tail_mask], axis = 2)
|
|
||||||
positions = ltx::video_positions(video_first, keyframe_latent_frames = tensor::shape(last_latent)[2], keyframe_frame_index = frames - 1, keyframe_pixel_frames = 1, fps = fps)
|
|
||||||
audio_vae = load_audio_vae(audio_vae_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
audio_shape = audio_latent_shape(audio_vae, frames = frames, fps = fps)
|
|
||||||
base = pack_av(video_conditioned, tensor::zeros(audio_shape), audio_scale = audio_scale)
|
|
||||||
packed_shape = tensor::shape(base)
|
|
||||||
full_video_mask = tensor::broadcast_to(mask_conditioned, tensor::shape(video_conditioned))
|
|
||||||
packed_mask = tensor::concat([full_video_mask, tensor::full([packed_shape[0], packed_shape[1], packed_shape[2], packed_shape[3] - video_shape[3], 1], 1)], axis = 3)
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive, audio_length = audio_shape[1], fps = fps, video_positions = positions)
|
|
||||||
neg = predictor(model, negative, audio_length = audio_shape[1], fps = fps, video_positions = positions)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng, base = base, denoise_mask = packed_mask, mask_input = true)
|
|
||||||
video_latent = latent[:, :, :tensor::shape(video_base)[2], :tensor::shape(video_base)[3]]
|
|
||||||
output_frames = vae_decode(vae, dit_to_vae_latents(vae, video_latent))
|
|
||||||
sound_latent = unpack_audio(latent, channels = tensor::shape(video_base)[3], audio_shape = audio_shape, audio_scale = audio_scale)
|
|
||||||
audio = audio_vae_decode(audio_vae, sound_latent)
|
|
||||||
video::save(output_path, {frames = output_frames, fps_num = fps, fps_den = 1}, audio = audio)
|
|
||||||
return {video = {frames = output_frames, fps_num = fps, fps_den = 1}, latent = latent, audio = audio}
|
|
||||||
}
|
|
||||||
|
|
@ -1,92 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/ltx2.md — LTX-2.3 dev I2V
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/ltx-2.3-22b-dev-UD-Q4_K_M.gguf"
|
|
||||||
text_path = "../models/text_encoders/gemma-3-12b-it-qat-UD-Q4_K_XL.gguf"
|
|
||||||
connectors_path = "../models/text_encoders/ltx-2.3-22b-dev_embeddings_connectors.safetensors"
|
|
||||||
vae_path = "../models/vae/ltx-2.3-22b-dev_video_vae.safetensors"
|
|
||||||
audio_vae_path = "../models/vae/ltx-2.3-22b-dev_audio_vae.safetensors"
|
|
||||||
|
|
||||||
first_frame_path = "../inputs/ernie_image/turbo_example.png"
|
|
||||||
output_path = "i2v.avi"
|
|
||||||
|
|
||||||
prompt = "a lovely cat"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 1280
|
|
||||||
height = 736
|
|
||||||
frames = 33
|
|
||||||
fps = 16
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 6.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "ltx2"
|
|
||||||
strength = 0.75
|
|
||||||
audio_scale = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fit_canvas(input, width, height, mode) {
|
|
||||||
shape = tensor::shape(input)
|
|
||||||
crop_width = math::min(shape[1], math::floor(shape[2] * width / height))
|
|
||||||
crop_height = math::min(shape[2], math::floor(shape[1] * height / width))
|
|
||||||
start = [math::floor((shape[1] - crop_width) / 2), math::floor((shape[2] - crop_height) / 2)]
|
|
||||||
cropped = tensor::crop(input, axes = [1, 2], start = start, size = [crop_width, crop_height])
|
|
||||||
return tensor::interpolate(cropped, size = [width, height], axes = [1, 2], mode = mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pack_av(video, audio, audio_scale) {
|
|
||||||
shape = tensor::shape(video)
|
|
||||||
count = tensor::numel(audio)
|
|
||||||
tail_channels = math::ceil_div(count, shape[0] * shape[1] * shape[2])
|
|
||||||
tail_shape = [shape[0], shape[1], shape[2], tail_channels, 1]
|
|
||||||
flat = tensor::reshape(tensor::mul(audio, audio_scale), [count])
|
|
||||||
padded = tensor::pad(flat, [0, math::product(tail_shape) - count])
|
|
||||||
return tensor::concat([video, tensor::reshape(padded, tail_shape)], axis = 3)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn unpack_audio(packed, channels, audio_shape, audio_scale) {
|
|
||||||
tail = packed[:, :, :, channels:]
|
|
||||||
flat = tensor::reshape(tail, [tensor::numel(tail)])
|
|
||||||
return tensor::div(tensor::reshape(flat[:math::product(audio_shape)], audio_shape), audio_scale)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
first_frame = image::load(first_frame_path)
|
|
||||||
|
|
||||||
model = load_dit(model_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, connectors_path = connectors_path, family = "ltxav", params_backend = "cpu", projection_path = model_path)
|
|
||||||
vae = load_vae(vae_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
video_base = tensor::zeros(latent_shape(vae, width = width, height = height, frames = frames))
|
|
||||||
first_frame_pixels = tensor::unsqueeze(image::to_f32(fit_canvas(first_frame, width, height, mode = "nearest"), channels = 3), axis = 2)
|
|
||||||
video_shape = tensor::shape(video_base)
|
|
||||||
video_mask = tensor::full([video_shape[0], video_shape[1], video_shape[2], 1, 1], 1)
|
|
||||||
first_latent = vae_to_dit_latents(vae, vae_encode(vae, first_frame_pixels, rng = rng))
|
|
||||||
video_conditioned = tensor::replace_slice(video_base, first_latent, axis = 2, start = 0)
|
|
||||||
mask_conditioned = tensor::index_fill(video_mask, axis = 2, indices = [0], value = 1 - strength)
|
|
||||||
audio_vae = load_audio_vae(audio_vae_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
audio_shape = audio_latent_shape(audio_vae, frames = frames, fps = fps)
|
|
||||||
base = pack_av(video_conditioned, tensor::zeros(audio_shape), audio_scale = audio_scale)
|
|
||||||
packed_shape = tensor::shape(base)
|
|
||||||
full_video_mask = tensor::broadcast_to(mask_conditioned, tensor::shape(video_conditioned))
|
|
||||||
packed_mask = tensor::concat([full_video_mask, tensor::full([packed_shape[0], packed_shape[1], packed_shape[2], packed_shape[3] - video_shape[3], 1], 1)], axis = 3)
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive, audio_length = audio_shape[1], fps = fps)
|
|
||||||
neg = predictor(model, negative, audio_length = audio_shape[1], fps = fps)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng, base = base, denoise_mask = packed_mask, mask_input = true)
|
|
||||||
video_latent = latent[:, :, :tensor::shape(video_base)[2], :tensor::shape(video_base)[3]]
|
|
||||||
output_frames = vae_decode(vae, dit_to_vae_latents(vae, video_latent))
|
|
||||||
sound_latent = unpack_audio(latent, channels = tensor::shape(video_base)[3], audio_shape = audio_shape, audio_scale = audio_scale)
|
|
||||||
audio = audio_vae_decode(audio_vae, sound_latent)
|
|
||||||
video::save(output_path, {frames = output_frames, fps_num = fps, fps_den = 1}, audio = audio)
|
|
||||||
return {video = {frames = output_frames, fps_num = fps, fps_den = 1}, latent = latent, audio = audio}
|
|
||||||
}
|
|
||||||
|
|
@ -1,70 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/ltx2.md — LTX-2.3 dev T2V
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/ltx-2.3-22b-dev-UD-Q4_K_M.gguf"
|
|
||||||
text_path = "../models/text_encoders/gemma-3-12b-it-qat-UD-Q4_K_XL.gguf"
|
|
||||||
connectors_path = "../models/text_encoders/ltx-2.3-22b-dev_embeddings_connectors.safetensors"
|
|
||||||
vae_path = "../models/vae/ltx-2.3-22b-dev_video_vae.safetensors"
|
|
||||||
audio_vae_path = "../models/vae/ltx-2.3-22b-dev_audio_vae.safetensors"
|
|
||||||
|
|
||||||
output_path = "t2v.avi"
|
|
||||||
|
|
||||||
prompt = "a lovely cat"
|
|
||||||
negative_prompt = "worst quality, low quality, blurry, distorted, artifacts"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 1280
|
|
||||||
height = 736
|
|
||||||
frames = 33
|
|
||||||
fps = 24
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 6.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "ltx2"
|
|
||||||
audio_scale = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pack_av(video, audio, audio_scale) {
|
|
||||||
shape = tensor::shape(video)
|
|
||||||
count = tensor::numel(audio)
|
|
||||||
tail_channels = math::ceil_div(count, shape[0] * shape[1] * shape[2])
|
|
||||||
tail_shape = [shape[0], shape[1], shape[2], tail_channels, 1]
|
|
||||||
flat = tensor::reshape(tensor::mul(audio, audio_scale), [count])
|
|
||||||
padded = tensor::pad(flat, [0, math::product(tail_shape) - count])
|
|
||||||
return tensor::concat([video, tensor::reshape(padded, tail_shape)], axis = 3)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn unpack_audio(packed, channels, audio_shape, audio_scale) {
|
|
||||||
tail = packed[:, :, :, channels:]
|
|
||||||
flat = tensor::reshape(tail, [tensor::numel(tail)])
|
|
||||||
return tensor::div(tensor::reshape(flat[:math::product(audio_shape)], audio_shape), audio_scale)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, connectors_path = connectors_path, family = "ltxav", params_backend = "cpu", projection_path = model_path)
|
|
||||||
vae = load_vae(vae_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
|
|
||||||
video_base = tensor::zeros(latent_shape(vae, width = width, height = height, frames = frames))
|
|
||||||
audio_vae = load_audio_vae(audio_vae_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
audio_shape = audio_latent_shape(audio_vae, frames = frames, fps = fps)
|
|
||||||
base = pack_av(video_base, tensor::zeros(audio_shape), audio_scale = audio_scale)
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive, audio_length = audio_shape[1], fps = fps)
|
|
||||||
neg = predictor(model, negative, audio_length = audio_shape[1], fps = fps)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
video_latent = latent[:, :, :tensor::shape(video_base)[2], :tensor::shape(video_base)[3]]
|
|
||||||
output_frames = vae_decode(vae, dit_to_vae_latents(vae, video_latent))
|
|
||||||
sound_latent = unpack_audio(latent, channels = tensor::shape(video_base)[3], audio_shape = audio_shape, audio_scale = audio_scale)
|
|
||||||
audio = audio_vae_decode(audio_vae, sound_latent)
|
|
||||||
video::save(output_path, {frames = output_frames, fps_num = fps, fps_den = 1}, audio = audio)
|
|
||||||
return {video = {frames = output_frames, fps_num = fps, fps_den = 1}, latent = latent, audio = audio}
|
|
||||||
}
|
|
||||||
|
|
@ -1,125 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/ltx2.md — LTX-2.3 spatial latent upscale
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/ltx-2.3-22b-dev-UD-Q4_K_M.gguf"
|
|
||||||
text_path = "../models/text_encoders/gemma-3-12b-it-qat-UD-Q4_K_XL.gguf"
|
|
||||||
connectors_path = "../models/text_encoders/ltx-2.3-22b-dev_embeddings_connectors.safetensors"
|
|
||||||
vae_path = "../models/vae/ltx-2.3-22b-dev_video_vae.safetensors"
|
|
||||||
audio_vae_path = "../models/vae/ltx-2.3-22b-dev_audio_vae.safetensors"
|
|
||||||
hires_model_path = "../models/latent_upscale_models/ltx-2.3-spatial-upscaler-x2-1.1.safetensors"
|
|
||||||
|
|
||||||
first_frame_path = "../inputs/ernie_image/turbo_example.png"
|
|
||||||
output_path = "hires_i2v.avi"
|
|
||||||
|
|
||||||
prompt = "a lovely cat"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 640
|
|
||||||
height = 352
|
|
||||||
frames = 33
|
|
||||||
fps = 16
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 6.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "ltx2"
|
|
||||||
strength = 0.75
|
|
||||||
audio_scale = 1
|
|
||||||
|
|
||||||
hires_steps = 4
|
|
||||||
hires_scheduler_steps = 5
|
|
||||||
hires_vae_scale = 32
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fit_canvas(input, width, height, mode) {
|
|
||||||
shape = tensor::shape(input)
|
|
||||||
crop_width = math::min(shape[1], math::floor(shape[2] * width / height))
|
|
||||||
crop_height = math::min(shape[2], math::floor(shape[1] * height / width))
|
|
||||||
start = [math::floor((shape[1] - crop_width) / 2), math::floor((shape[2] - crop_height) / 2)]
|
|
||||||
cropped = tensor::crop(input, axes = [1, 2], start = start, size = [crop_width, crop_height])
|
|
||||||
return tensor::interpolate(cropped, size = [width, height], axes = [1, 2], mode = mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pack_av(video, audio, audio_scale) {
|
|
||||||
shape = tensor::shape(video)
|
|
||||||
count = tensor::numel(audio)
|
|
||||||
tail_channels = math::ceil_div(count, shape[0] * shape[1] * shape[2])
|
|
||||||
tail_shape = [shape[0], shape[1], shape[2], tail_channels, 1]
|
|
||||||
flat = tensor::reshape(tensor::mul(audio, audio_scale), [count])
|
|
||||||
padded = tensor::pad(flat, [0, math::product(tail_shape) - count])
|
|
||||||
return tensor::concat([video, tensor::reshape(padded, tail_shape)], axis = 3)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn unpack_audio(packed, channels, audio_shape, audio_scale) {
|
|
||||||
tail = packed[:, :, :, channels:]
|
|
||||||
flat = tensor::reshape(tail, [tensor::numel(tail)])
|
|
||||||
return tensor::div(tensor::reshape(flat[:math::product(audio_shape)], audio_shape), audio_scale)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
first_frame = image::load(first_frame_path)
|
|
||||||
|
|
||||||
model = load_dit(model_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, connectors_path = connectors_path, family = "ltxav", params_backend = "cpu", projection_path = model_path)
|
|
||||||
vae = load_vae(vae_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
video_base = tensor::zeros(latent_shape(vae, width = width, height = height, frames = frames))
|
|
||||||
first_frame_pixels = tensor::unsqueeze(image::to_f32(fit_canvas(first_frame, width, height, mode = "nearest"), channels = 3), axis = 2)
|
|
||||||
video_shape = tensor::shape(video_base)
|
|
||||||
video_mask = tensor::full([video_shape[0], video_shape[1], video_shape[2], 1, 1], 1)
|
|
||||||
first_latent = vae_to_dit_latents(vae, vae_encode(vae, first_frame_pixels, rng = rng))
|
|
||||||
video_conditioned = tensor::replace_slice(video_base, first_latent, axis = 2, start = 0)
|
|
||||||
mask_conditioned = tensor::index_fill(video_mask, axis = 2, indices = [0], value = 1 - strength)
|
|
||||||
audio_vae = load_audio_vae(audio_vae_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
audio_shape = audio_latent_shape(audio_vae, frames = frames, fps = fps)
|
|
||||||
base = pack_av(video_conditioned, tensor::zeros(audio_shape), audio_scale = audio_scale)
|
|
||||||
packed_shape = tensor::shape(base)
|
|
||||||
full_video_mask = tensor::broadcast_to(mask_conditioned, tensor::shape(video_conditioned))
|
|
||||||
packed_mask = tensor::concat([full_video_mask, tensor::full([packed_shape[0], packed_shape[1], packed_shape[2], packed_shape[3] - video_shape[3], 1], 1)], axis = 3)
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive, audio_length = audio_shape[1], fps = fps)
|
|
||||||
neg = predictor(model, negative, audio_length = audio_shape[1], fps = fps)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng, base = base, denoise_mask = packed_mask, mask_input = true)
|
|
||||||
hires_source = latent[:, :, :tensor::shape(video_base)[2], :tensor::shape(video_base)[3]]
|
|
||||||
hires_upscaler = load_latent_upscaler(hires_model_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
hires_upscaled = upscale_latent(hires_upscaler, dit_to_vae_latents(vae, hires_source))
|
|
||||||
hires_upscaled_shape = tensor::shape(hires_upscaled)
|
|
||||||
hires_video = vae_to_dit_latents(vae, tensor::reshape(hires_upscaled, [hires_upscaled_shape[0], hires_upscaled_shape[1], hires_upscaled_shape[2], hires_upscaled_shape[3], 1]))
|
|
||||||
hires_video_shape = tensor::shape(hires_video)
|
|
||||||
hires_original_audio = unpack_audio(latent, channels = tensor::shape(video_base)[3], audio_shape = audio_shape, audio_scale = audio_scale)
|
|
||||||
hires_width = hires_video_shape[0] * hires_vae_scale
|
|
||||||
hires_height = hires_video_shape[1] * hires_vae_scale
|
|
||||||
hires_frames = (hires_video_shape[2] - 1) * 8 + 1
|
|
||||||
hires_audio_shape = audio_latent_shape(audio_vae, frames = hires_frames, fps = fps)
|
|
||||||
hires_audio_retained = math::min(audio_shape[1], hires_audio_shape[1])
|
|
||||||
hires_audio = tensor::pad(hires_original_audio[:, :hires_audio_retained], [0, 0, 0, hires_audio_shape[1] - hires_audio_retained])
|
|
||||||
hires_video_mask = tensor::full([hires_video_shape[0], hires_video_shape[1], hires_video_shape[2], 1, 1], 1)
|
|
||||||
hires_first_pixels = tensor::unsqueeze(image::to_f32(fit_canvas(first_frame, hires_width, hires_height, mode = "nearest"), channels = 3), axis = 2)
|
|
||||||
hires_first_latent = vae_to_dit_latents(vae, vae_encode(vae, hires_first_pixels, rng = rng))
|
|
||||||
hires_conditioned = tensor::replace_slice(hires_video, hires_first_latent, axis = 2, start = 0)
|
|
||||||
hires_condition_mask = tensor::index_fill(hires_video_mask, axis = 2, indices = [0], value = 0)
|
|
||||||
hires_base = pack_av(hires_conditioned, hires_audio, audio_scale = audio_scale)
|
|
||||||
hires_packed_shape = tensor::shape(hires_base)
|
|
||||||
hires_packed_mask = tensor::concat([tensor::broadcast_to(hires_condition_mask, tensor::shape(hires_conditioned)), tensor::full([hires_packed_shape[0], hires_packed_shape[1], hires_packed_shape[2], hires_packed_shape[3] - hires_video_shape[3], 1], 1)], axis = 3)
|
|
||||||
hires_pos = predictor(model, positive, audio_length = hires_audio_shape[1], fps = fps)
|
|
||||||
hires_neg = predictor(model, negative, audio_length = hires_audio_shape[1], fps = fps)
|
|
||||||
hires_guided = cfg(hires_pos, hires_neg, scale = cfg_scale)
|
|
||||||
hires_schedule = make_sigmas(hires_guided, latent = hires_base, steps = hires_scheduler_steps, scheduler = scheduler)
|
|
||||||
hires_sigmas = hires_schedule[-(hires_steps + 1):]
|
|
||||||
hires_start = add_noise(hires_guided, hires_base, tensor::randn_like(hires_base, rng = rng), sigma = hires_sigmas[0])
|
|
||||||
hires_latent = sample(hires_start, hires_sigmas, predict = hires_guided, method = method, rng = rng, base = hires_base, denoise_mask = hires_packed_mask, mask_input = true)
|
|
||||||
video_latent = hires_latent[:, :, :hires_video_shape[2], :tensor::shape(video_base)[3]]
|
|
||||||
output_frames = vae_decode(vae, dit_to_vae_latents(vae, video_latent))
|
|
||||||
sound_latent = unpack_audio(hires_latent, channels = tensor::shape(video_base)[3], audio_shape = hires_audio_shape, audio_scale = audio_scale)
|
|
||||||
audio = audio_vae_decode(audio_vae, sound_latent)
|
|
||||||
video::save(output_path, {frames = output_frames, fps_num = fps, fps_den = 1}, audio = audio)
|
|
||||||
return {video = {frames = output_frames, fps_num = fps, fps_den = 1}, latent = hires_latent, audio = audio}
|
|
||||||
}
|
|
||||||
|
|
@ -1,91 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/ltx2.md — LTX-2.5 dev I2V
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/ltx-2.5-22b-dev-transformer-Q8_0.gguf"
|
|
||||||
text_path = "../models/text_encoders/gemma4-12b-with-proj-ltx-2.5-Q8_0.gguf"
|
|
||||||
vae_path = "../models/vae/ltx-2.5-video-vae-conv-bf16.safetensors"
|
|
||||||
audio_vae_path = "../models/vae/ltx-2.5-audio-vae-bf16.safetensors"
|
|
||||||
|
|
||||||
first_frame_path = "../inputs/ernie_image/turbo_example.png"
|
|
||||||
output_path = "i2v.avi"
|
|
||||||
|
|
||||||
prompt = "a lovely cat blinking slowly, gentle camera push in"
|
|
||||||
negative_prompt = ""
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 1280
|
|
||||||
height = 736
|
|
||||||
frames = 121
|
|
||||||
fps = 16
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 3.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "ltx2"
|
|
||||||
strength = 0.75
|
|
||||||
audio_scale = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
fn fit_canvas(input, width, height, mode) {
|
|
||||||
shape = tensor::shape(input)
|
|
||||||
crop_width = math::min(shape[1], math::floor(shape[2] * width / height))
|
|
||||||
crop_height = math::min(shape[2], math::floor(shape[1] * height / width))
|
|
||||||
start = [math::floor((shape[1] - crop_width) / 2), math::floor((shape[2] - crop_height) / 2)]
|
|
||||||
cropped = tensor::crop(input, axes = [1, 2], start = start, size = [crop_width, crop_height])
|
|
||||||
return tensor::interpolate(cropped, size = [width, height], axes = [1, 2], mode = mode)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pack_av(video, audio, audio_scale) {
|
|
||||||
shape = tensor::shape(video)
|
|
||||||
count = tensor::numel(audio)
|
|
||||||
tail_channels = math::ceil_div(count, shape[0] * shape[1] * shape[2])
|
|
||||||
tail_shape = [shape[0], shape[1], shape[2], tail_channels, 1]
|
|
||||||
flat = tensor::reshape(tensor::mul(audio, audio_scale), [count])
|
|
||||||
padded = tensor::pad(flat, [0, math::product(tail_shape) - count])
|
|
||||||
return tensor::concat([video, tensor::reshape(padded, tail_shape)], axis = 3)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn unpack_audio(packed, channels, audio_shape, audio_scale) {
|
|
||||||
tail = packed[:, :, :, channels:]
|
|
||||||
flat = tensor::reshape(tail, [tensor::numel(tail)])
|
|
||||||
return tensor::div(tensor::reshape(flat[:math::product(audio_shape)], audio_shape), audio_scale)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
first_frame = image::load(first_frame_path)
|
|
||||||
|
|
||||||
model = load_dit(model_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "ltxav", params_backend = "cpu", projection_path = model_path)
|
|
||||||
vae = load_vae(vae_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
video_base = tensor::zeros(latent_shape(vae, width = width, height = height, frames = frames))
|
|
||||||
first_frame_pixels = tensor::unsqueeze(image::to_f32(fit_canvas(first_frame, width, height, mode = "nearest"), channels = 3), axis = 2)
|
|
||||||
video_shape = tensor::shape(video_base)
|
|
||||||
video_mask = tensor::full([video_shape[0], video_shape[1], video_shape[2], 1, 1], 1)
|
|
||||||
first_latent = vae_to_dit_latents(vae, vae_encode(vae, first_frame_pixels, rng = rng))
|
|
||||||
video_conditioned = tensor::replace_slice(video_base, first_latent, axis = 2, start = 0)
|
|
||||||
mask_conditioned = tensor::index_fill(video_mask, axis = 2, indices = [0], value = 1 - strength)
|
|
||||||
audio_vae = load_audio_vae(audio_vae_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
audio_shape = audio_latent_shape(audio_vae, frames = frames, fps = fps)
|
|
||||||
base = pack_av(video_conditioned, tensor::zeros(audio_shape), audio_scale = audio_scale)
|
|
||||||
packed_shape = tensor::shape(base)
|
|
||||||
full_video_mask = tensor::broadcast_to(mask_conditioned, tensor::shape(video_conditioned))
|
|
||||||
packed_mask = tensor::concat([full_video_mask, tensor::full([packed_shape[0], packed_shape[1], packed_shape[2], packed_shape[3] - video_shape[3], 1], 1)], axis = 3)
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive, audio_length = audio_shape[1], fps = fps)
|
|
||||||
neg = predictor(model, negative, audio_length = audio_shape[1], fps = fps)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng, base = base, denoise_mask = packed_mask, mask_input = true)
|
|
||||||
video_latent = latent[:, :, :tensor::shape(video_base)[2], :tensor::shape(video_base)[3]]
|
|
||||||
output_frames = vae_decode(vae, dit_to_vae_latents(vae, video_latent))
|
|
||||||
sound_latent = unpack_audio(latent, channels = tensor::shape(video_base)[3], audio_shape = audio_shape, audio_scale = audio_scale)
|
|
||||||
audio = audio_vae_decode(audio_vae, sound_latent)
|
|
||||||
video::save(output_path, {frames = output_frames, fps_num = fps, fps_den = 1}, audio = audio)
|
|
||||||
return {video = {frames = output_frames, fps_num = fps, fps_den = 1}, latent = latent, audio = audio}
|
|
||||||
}
|
|
||||||
|
|
@ -1,69 +0,0 @@
|
||||||
# version: 0.0.0
|
|
||||||
# docs/models/ltx2.md — LTX-2.5 dev T2V
|
|
||||||
|
|
||||||
var {
|
|
||||||
model_path = "../models/diffusion_models/ltx-2.5-22b-dev-transformer-Q8_0.gguf"
|
|
||||||
text_path = "../models/text_encoders/gemma4-12b-with-proj-ltx-2.5-Q8_0.gguf"
|
|
||||||
vae_path = "../models/vae/ltx-2.5-video-vae-conv-bf16.safetensors"
|
|
||||||
audio_vae_path = "../models/vae/ltx-2.5-audio-vae-bf16.safetensors"
|
|
||||||
|
|
||||||
output_path = "t2v.avi"
|
|
||||||
|
|
||||||
prompt = "A wide aerial shot of a red vintage convertible driving along a coastal cliff road at sunset, waves crashing below"
|
|
||||||
negative_prompt = "worst quality, low quality, blurry, distorted, artifacts"
|
|
||||||
|
|
||||||
seed = 42
|
|
||||||
rng_type = "cuda"
|
|
||||||
width = 1280
|
|
||||||
height = 736
|
|
||||||
frames = 121
|
|
||||||
fps = 24
|
|
||||||
|
|
||||||
steps = 20
|
|
||||||
cfg_scale = 3.0
|
|
||||||
method = "euler"
|
|
||||||
scheduler = "ltx2"
|
|
||||||
audio_scale = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
fn pack_av(video, audio, audio_scale) {
|
|
||||||
shape = tensor::shape(video)
|
|
||||||
count = tensor::numel(audio)
|
|
||||||
tail_channels = math::ceil_div(count, shape[0] * shape[1] * shape[2])
|
|
||||||
tail_shape = [shape[0], shape[1], shape[2], tail_channels, 1]
|
|
||||||
flat = tensor::reshape(tensor::mul(audio, audio_scale), [count])
|
|
||||||
padded = tensor::pad(flat, [0, math::product(tail_shape) - count])
|
|
||||||
return tensor::concat([video, tensor::reshape(padded, tail_shape)], axis = 3)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn unpack_audio(packed, channels, audio_shape, audio_scale) {
|
|
||||||
tail = packed[:, :, :, channels:]
|
|
||||||
flat = tensor::reshape(tail, [tensor::numel(tail)])
|
|
||||||
return tensor::div(tensor::reshape(flat[:math::product(audio_shape)], audio_shape), audio_scale)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
model = load_dit(model_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
text = load_text_encoder(text_path, family = "ltxav", params_backend = "cpu", projection_path = model_path)
|
|
||||||
vae = load_vae(vae_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
|
|
||||||
video_base = tensor::zeros(latent_shape(vae, width = width, height = height, frames = frames))
|
|
||||||
audio_vae = load_audio_vae(audio_vae_path, family = "ltxav", params_backend = "cpu")
|
|
||||||
audio_shape = audio_latent_shape(audio_vae, frames = frames, fps = fps)
|
|
||||||
base = pack_av(video_base, tensor::zeros(audio_shape), audio_scale = audio_scale)
|
|
||||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
|
||||||
negative = encode_prompt(text, negative_prompt, width = width, height = height)
|
|
||||||
pos = predictor(model, positive, audio_length = audio_shape[1], fps = fps)
|
|
||||||
neg = predictor(model, negative, audio_length = audio_shape[1], fps = fps)
|
|
||||||
guided = cfg(pos, neg, scale = cfg_scale)
|
|
||||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
|
||||||
rng = make_rng(rng_type, seed = seed)
|
|
||||||
start = add_noise(guided, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
|
||||||
latent = sample(start, sigmas, predict = guided, method = method, rng = rng)
|
|
||||||
video_latent = latent[:, :, :tensor::shape(video_base)[2], :tensor::shape(video_base)[3]]
|
|
||||||
output_frames = vae_decode(vae, dit_to_vae_latents(vae, video_latent))
|
|
||||||
sound_latent = unpack_audio(latent, channels = tensor::shape(video_base)[3], audio_shape = audio_shape, audio_scale = audio_scale)
|
|
||||||
audio = audio_vae_decode(audio_vae, sound_latent)
|
|
||||||
video::save(output_path, {frames = output_frames, fps_num = fps, fps_den = 1}, audio = audio)
|
|
||||||
return {video = {frames = output_frames, fps_num = fps, fps_den = 1}, latent = latent, audio = audio}
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue