mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-11-26 23:29:53 +00:00
feat: add Diffusion Graph Language support (#2396)
This commit is contained in:
parent
9e7eed71e4
commit
6cd0ef1e1e
674 changed files with 41892 additions and 18780 deletions
18
.github/workflows/build.yml
vendored
18
.github/workflows/build.yml
vendored
|
|
@ -15,6 +15,7 @@ on:
|
|||
[
|
||||
".github/workflows/**",
|
||||
".dockerignore",
|
||||
"docs/dgl-builtins.md",
|
||||
"docker/Dockerfile*",
|
||||
"scripts/ci-cuda-cache.sh",
|
||||
"**/CMakeLists.txt",
|
||||
|
|
@ -38,6 +39,7 @@ on:
|
|||
[
|
||||
".github/workflows/**",
|
||||
".dockerignore",
|
||||
"docs/dgl-builtins.md",
|
||||
"docker/Dockerfile*",
|
||||
"scripts/ci-cuda-cache.sh",
|
||||
"**/CMakeLists.txt",
|
||||
|
|
@ -100,6 +102,7 @@ jobs:
|
|||
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 --build . --config Release
|
||||
cmake --build . --config Release --target dgl-check-builtins
|
||||
|
||||
- name: Get commit hash
|
||||
id: commit
|
||||
|
|
@ -121,6 +124,8 @@ jobs:
|
|||
run: |
|
||||
cp ggml/LICENSE ./build/bin/ggml.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
|
||||
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
|
||||
|
||||
|
|
@ -186,6 +191,8 @@ jobs:
|
|||
run: |
|
||||
cp ggml/LICENSE ./build/bin/ggml.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
|
||||
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
|
||||
|
||||
|
|
@ -366,6 +373,8 @@ jobs:
|
|||
run: |
|
||||
cp ggml/LICENSE ./build/bin/ggml.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
|
||||
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
|
||||
|
||||
|
|
@ -474,8 +483,11 @@ jobs:
|
|||
ls .\build\bin
|
||||
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 (Split-Path -Parent $filePath) 'cutlass.txt')
|
||||
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
|
||||
|
||||
|
|
@ -633,6 +645,8 @@ jobs:
|
|||
- name: Pack artifacts
|
||||
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
|
||||
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
|
||||
|
||||
- name: Upload artifacts
|
||||
|
|
@ -796,6 +810,8 @@ jobs:
|
|||
run: |
|
||||
cp ggml/LICENSE ./build/bin/ggml.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
|
||||
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
|
||||
|
||||
|
|
|
|||
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -2,7 +2,10 @@ build*/
|
|||
cmake-build-*/
|
||||
test/
|
||||
tests/
|
||||
/dgl/*
|
||||
!/dgl/.gitkeep
|
||||
logs/
|
||||
output/
|
||||
.vscode/
|
||||
.idea/
|
||||
.cache/
|
||||
|
|
|
|||
10
AGENTS.md
10
AGENTS.md
|
|
@ -50,8 +50,11 @@ Core implementation lives under `src/`.
|
|||
|
||||
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
|
||||
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_io/` - model file loading, GGUF, safetensors, pickle, and related
|
||||
serialization helpers.
|
||||
|
|
@ -92,6 +95,7 @@ documentation.
|
|||
|
||||
* `docs/` - documentation for supported models, build options, behavior, and
|
||||
workflows; start from `docs/README.md`.
|
||||
* `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.
|
||||
|
|
@ -127,6 +131,12 @@ documentation.
|
|||
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
|
||||
update policy, and security rules. For tokenizer additions, follow its embedded-data
|
||||
allowlist and default to an external `tokenizer.json`.
|
||||
|
|
|
|||
|
|
@ -9,14 +9,8 @@ if (NOT XCODE AND NOT MSVC AND NOT CMAKE_BUILD_TYPE)
|
|||
endif()
|
||||
|
||||
if (MSVC)
|
||||
cmake_host_system_information(RESULT SD_LOGICAL_CORES QUERY NUMBER_OF_LOGICAL_CORES)
|
||||
if (SD_LOGICAL_CORES GREATER 8)
|
||||
math(EXPR SD_DEFAULT_MSVC_MP_COUNT "${SD_LOGICAL_CORES} - 2")
|
||||
elseif (SD_LOGICAL_CORES GREATER 2)
|
||||
math(EXPR SD_DEFAULT_MSVC_MP_COUNT "${SD_LOGICAL_CORES} - 1")
|
||||
else()
|
||||
set(SD_DEFAULT_MSVC_MP_COUNT "${SD_LOGICAL_CORES}")
|
||||
endif()
|
||||
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()
|
||||
|
|
@ -24,6 +18,7 @@ if (MSVC)
|
|||
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(_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING)
|
||||
# /MP is MSVC-only: icx rejects it outright once offloading is enabled.
|
||||
|
|
@ -98,7 +93,7 @@ endif()
|
|||
option(SD_BUILD_EXAMPLES "sd: build examples" ${SD_STANDALONE})
|
||||
option(SD_WEBP "sd: enable WebP image I/O support" ${SD_WEBP_DEFAULT})
|
||||
option(SD_USE_SYSTEM_WEBP "sd: link against system libwebp" OFF)
|
||||
option(SD_WEBM "sd: enable WebM video output support" ${SD_WEBM_DEFAULT})
|
||||
option(SD_WEBM "sd: enable WebM video I/O support" ${SD_WEBM_DEFAULT})
|
||||
option(SD_USE_SYSTEM_WEBM "sd: link against system libwebm" OFF)
|
||||
option(SD_CUDA "sd: cuda backend" OFF)
|
||||
option(SD_HIPBLAS "sd: rocm backend" OFF)
|
||||
|
|
@ -184,13 +179,21 @@ if(SD_WEBP)
|
|||
"Expected WebP::libwebpmux or WebP::webpmux."
|
||||
)
|
||||
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()
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(WebP REQUIRED IMPORTED_TARGET GLOBAL libwebp)
|
||||
pkg_check_modules(WebPMux REQUIRED IMPORTED_TARGET GLOBAL libwebpmux)
|
||||
link_libraries(PkgConfig::WebP)
|
||||
link_libraries(PkgConfig::WebPMux)
|
||||
pkg_check_modules(WebPDemux REQUIRED IMPORTED_TARGET GLOBAL libwebpdemux)
|
||||
add_library(webp ALIAS PkgConfig::WebP)
|
||||
add_library(libwebpmux ALIAS PkgConfig::WebPMux)
|
||||
add_library(webpdemux ALIAS PkgConfig::WebPDemux)
|
||||
endif()
|
||||
endif()
|
||||
endif()
|
||||
|
|
@ -210,7 +213,7 @@ if(SD_WEBM)
|
|||
pkg_check_modules(WebM REQUIRED IMPORTED_TARGET GLOBAL libwebm)
|
||||
endif()
|
||||
if(PkgConfig_FOUND AND WebM_FOUND)
|
||||
link_libraries(PkgConfig::WebM)
|
||||
add_library(webm ALIAS PkgConfig::WebM)
|
||||
else()
|
||||
find_path(WEBM_INCLUDE_DIR
|
||||
NAMES mkvmuxer/mkvmuxer.h mkvparser/mkvparser.h common/webmids.h
|
||||
|
|
@ -236,6 +239,17 @@ endif ()
|
|||
|
||||
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
|
||||
"src/*.h"
|
||||
"src/*.cpp"
|
||||
|
|
@ -255,11 +269,19 @@ file(GLOB SD_LIB_SOURCES CONFIGURE_DEPENDS
|
|||
"src/extensions/*.h"
|
||||
"src/extensions/*.cpp"
|
||||
"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/*/*.cpp"
|
||||
"src/model/*/*.hpp"
|
||||
"src/pipeline/*.h"
|
||||
"src/pipeline/*.cpp"
|
||||
"src/runtime/*.h"
|
||||
"src/runtime/*.cpp"
|
||||
"src/runtime/*.hpp"
|
||||
|
|
@ -363,6 +385,14 @@ target_link_libraries(${SD_LIB} PUBLIC ggml)
|
|||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(${SD_LIB} PRIVATE Threads::Threads)
|
||||
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)
|
||||
find_package(CUDAToolkit REQUIRED)
|
||||
# Keep the driver stub on downstream link lines when no driver is installed.
|
||||
|
|
@ -430,7 +460,7 @@ if (SD_HIPBLAS)
|
|||
endif()
|
||||
endif()
|
||||
target_include_directories(${SD_LIB} PUBLIC include)
|
||||
target_include_directories(${SD_LIB} PRIVATE src src/core)
|
||||
target_include_directories(${SD_LIB} PRIVATE src src/core "${CMAKE_CURRENT_BINARY_DIR}/generated")
|
||||
target_include_directories(${SD_LIB} PUBLIC thirdparty)
|
||||
target_compile_features(${SD_LIB} PUBLIC c_std_11 cxx_std_17)
|
||||
set_target_properties(${SD_LIB} PROPERTIES
|
||||
|
|
@ -444,6 +474,7 @@ endif()
|
|||
|
||||
|
||||
|
||||
|
||||
#
|
||||
# install
|
||||
#
|
||||
|
|
@ -459,12 +490,9 @@ 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_BIN_INSTALL_DIR ${CMAKE_INSTALL_BINDIR} CACHE PATH "Location of binary files")
|
||||
|
||||
set(SD_PUBLIC_HEADERS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include/stable-diffusion.h)
|
||||
|
||||
set_target_properties(${SD_LIB}
|
||||
PROPERTIES
|
||||
PUBLIC_HEADER "${SD_PUBLIC_HEADERS}")
|
||||
PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/include/stable-diffusion.h")
|
||||
|
||||
|
||||
install(TARGETS ${SD_LIB}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,12 @@ 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
|
||||
|
|
@ -60,7 +66,9 @@ omitting other sections when they have no content:
|
|||
- `Model files`, with component, weights/downloads, CLI option, and requirement
|
||||
columns. Include tokenizers, projectors, connectors, downloads, conversion, and
|
||||
required preprocessing.
|
||||
- `Usage`, with `Web UI` and `CLI` subsections where applicable. Link to the
|
||||
- `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
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ API and command-line option may change frequently.***
|
|||
- [Qwen Image 2.1](./docs/models/qwen_image_2.1.md)
|
||||
- [PiD](./docs/models/pid.md)
|
||||
- [LongCat Image](./docs/models/longcat_image.md)
|
||||
- [Z-Image](./docs/models/z_image.md)
|
||||
- [Z-Image](./docs/models/z_image.md), including [DGL ControlNet](./docs/models/z_image.md#controlnet)
|
||||
- [Z-Image L2P](./docs/models/z_image_l2p.md)
|
||||
- [MiniT2I](./docs/models/minit2i.md)
|
||||
- [P-H3-Image](./docs/models/p_h3_image.md)
|
||||
|
|
@ -213,6 +213,7 @@ 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)
|
||||
|
|
|
|||
0
dgl/.gitkeep
Normal file
0
dgl/.gitkeep
Normal file
|
|
@ -15,6 +15,8 @@ For the project overview and supported models, see the [project README](../READM
|
|||
|
||||
## 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)
|
||||
|
|
@ -40,6 +42,7 @@ For the project overview and supported models, see the [project README](../READM
|
|||
## 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)
|
||||
|
|
|
|||
|
|
@ -59,9 +59,22 @@ including `GGML_MAX_NAME`. For an upstream package, also set
|
|||
`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 in Examples
|
||||
## WebP and WebM Support
|
||||
|
||||
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`.
|
||||
WebP and WebM support are enabled by default. The library links `libwebp`,
|
||||
`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:
|
||||
|
||||
|
|
|
|||
|
|
@ -37,10 +37,13 @@ measurement pair; it cannot interrupt an in-flight backend operation.
|
|||
Only use `candidate_faster` when `completed` is true. On incomplete probes,
|
||||
`error` reports why comparison failed and the timing totals may be partial.
|
||||
The caller handles logging, known architecture rules, fallback policy, and
|
||||
context-lifetime caching. Keep caches separate by operation (or key a shared
|
||||
cache by both operation and backend); an attention result must not select a
|
||||
convolution implementation. If shapes or settings vary within one context,
|
||||
include them in the corresponding cache key as well.
|
||||
context-lifetime caching. DGL uses one `BackendProbeCache` shared by all models
|
||||
in an execution context, including LoRA variants and models loaded by later
|
||||
programs. It caches both enabled and disabled decisions by operation and compute
|
||||
backend; CPU attention additionally keys the effective thread count. GPU results
|
||||
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
|
||||
in the context, just like attention results. Each probe logs its backend, decision,
|
||||
|
|
|
|||
|
|
@ -13,26 +13,30 @@ See the [C API guide](../guides/c_api.md) for keys, value types and ownership ru
|
|||
| `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/generation_info.h/.cpp` | Construction of generation metadata JSON. |
|
||||
| `src/pipeline/generation.h` | Internal generation entry declarations. |
|
||||
| `src/stable-diffusion.cpp` | Internal typed image/video generation and model-specific validation. |
|
||||
| `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 once at the API boundary. The runtime reads
|
||||
typed configuration fields. Internal callers such as ADetailer pass typed
|
||||
configuration directly to the internal generation entry; they do not rebuild
|
||||
options or call public setters.
|
||||
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. ADetailer applies its operation-specific
|
||||
strength default before the overlay.
|
||||
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 pipeline after refreshing the model sources. Their internal
|
||||
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.
|
||||
|
||||
|
|
@ -46,18 +50,43 @@ 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 result metadata reports effective values. Post-generation
|
||||
ADetailer clears inherited dimensions and strength before applying pass overrides,
|
||||
so its operation defaults also come from 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. Raw pipeline output buffers are converted to tensors at
|
||||
the boundary and released there. Internal producers with an `sd::Tensor<T>` can
|
||||
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.
|
||||
Metadata construction is separate from its attachment to a result.
|
||||
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.
|
||||
`sd_ctx_prepare()` runs a component-only template using the same loading
|
||||
parameters as generation. Server startup and model selection call it after
|
||||
installing file permissions, before publishing `ready`. Capability queries read
|
||||
an atomic snapshot of the last detected type and do not acquire a generation
|
||||
run or reset its cancellation state. Only an initial probe takes the context
|
||||
lock.
|
||||
|
||||
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.
|
||||
|
|
|
|||
69
docs/development/dgl.md
Normal file
69
docs/development/dgl.md
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
# 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).
|
||||
|
|
@ -132,8 +132,9 @@ To add a model:
|
|||
1. Add its identity to `SDVersion` without renumbering existing values.
|
||||
2. Implement the network and `*Config::detect_from_weights` following the
|
||||
conventions above, or reuse an existing runner.
|
||||
3. Add a definition in its integration file, including its component
|
||||
factory, traits, geometry, and sampling policy.
|
||||
3. Add a definition in its integration file with its display name, stable
|
||||
lowercase DGL family ID, component factory, traits, geometry, and sampling
|
||||
policy. Use underscores between words in the ID.
|
||||
4. Add the family's explicit registration in `src/model_registry.cpp`. For a new
|
||||
variant of a registered family, add its definition to that family's list.
|
||||
5. Add version detection signatures and any required weight-name mappings in
|
||||
|
|
@ -175,6 +176,15 @@ and the output runners. Backend checks, optional IP-Adapter setup, scale
|
|||
overrides, and tokenizer usage validation remain in the common builder. A
|
||||
factory returns failure if any required additional backend cannot initialize.
|
||||
|
||||
`Context::params` contains `ModelBuildParams`, limited to model construction.
|
||||
The native pipeline extracts these values from its `ContextConfig` at the
|
||||
builder boundary. DGL uses its own typed `ModelLoadParams` for common loader
|
||||
options and separate DiT, text encoder and VAE parameters for specialized
|
||||
options. It does not store or convert through `ContextConfig`. Threading,
|
||||
file mapping, caching and memory budgets belong to the DGL execution context.
|
||||
The placement cache takes `PlacementOptions` rather than an entry point's
|
||||
context configuration.
|
||||
|
||||
LLM architecture selection, tokenizer requirements, prompt preparation, and
|
||||
encoding remain centralized in `src/conditioning/conditioner.hpp`. Integration
|
||||
factories instantiate the conditioner with the model version; models requiring
|
||||
|
|
@ -204,28 +214,35 @@ the values that differ from the struct defaults. `prediction_from_weights` and
|
|||
`flow_shift_from_weights` preserve checkpoint-dependent defaults during automatic
|
||||
prediction selection; `probe_v_prediction` enables SD2's runtime v-prediction
|
||||
probe. Explicit prediction settings take precedence over automatic selection.
|
||||
In DGL the override belongs to `predictor`, rather than a model loader. A
|
||||
resolved `Denoising` configuration supplies prediction scalings, time mapping
|
||||
and noise conventions without changing the model's resource identity. Model
|
||||
flow-shift defaults are resolved independently of an explicit prediction override.
|
||||
MOSS's default unconditional skip layer stays
|
||||
in the diffusion engine, with active unconditional SLG taking precedence.
|
||||
|
||||
The resolved `prediction_t` selects the denoiser directly. Flux3, MiniMax H3 AV,
|
||||
and Ming-Image use `FLUX3_FLOW_PRED`, `H3_AV_FLOW_PRED`, and
|
||||
`MING_IMAGE_FLOW_PRED`; their CLI overrides are `flux3_flow`, `h3_av_flow`, and
|
||||
`ming_image_flow`. Explicit `sd3_flow` always selects `DiscreteFlowDenoiser`,
|
||||
`ming_image_flow`. Explicit `flow` always selects `DiscreteFlowDenoiser`,
|
||||
and `flux_flow` always selects `FluxFlowDenoiser`, regardless of model version.
|
||||
Automatic selection retains each model's default implementation. New prediction
|
||||
values are appended before `PREDICTION_COUNT`, preserving existing valid values;
|
||||
clients using the automatic-selection sentinel must rebuild with the new header.
|
||||
|
||||
`ModelGeometry` declares `diffusion_down_factor`, `latent_channels`, and
|
||||
`image_channels`. `ref_image_preset` defaults to `"default"`; set it only for models
|
||||
that need another reference-image preset.
|
||||
`image_channels`. Reference-image workflow defaults belong to API program
|
||||
generation and its DGL templates. Model definitions do not select shared
|
||||
reference presets. C++ prepares reference sizes, buckets and crop coordinates;
|
||||
templates express the pixel transformations and encoding calls. The rendered
|
||||
program explicitly supplies prompt media and predictor reference latents.
|
||||
|
||||
The common pipeline executes these policies; specialized video, multimodal,
|
||||
cache, and extension algorithms remain in their existing runtime components.
|
||||
Model-specific diffusion extra parameters are assembled in the diffusion engine.
|
||||
Video frame conversion and alignment also remain in the diffusion engine.
|
||||
`get_vae_scale_factor()` retains PiD's pixel-space special case and otherwise
|
||||
uses the VAE's scale factor.
|
||||
DGL executes the resulting program. Diffusion models consume reference latents,
|
||||
`ref_index_mode` and `force_ref_timestep_zero`; a separate enable flag is not
|
||||
needed. Text encoders retain their native patch alignment, normalization and
|
||||
model-specific image processing. These model operations do not receive API
|
||||
resizing or routing policies. Specialized video, multimodal, cache and extension
|
||||
algorithms remain in their typed model and runtime components.
|
||||
|
||||
Validate migrations against the previous implementation using synthetic metadata,
|
||||
name conversions, prompt preparation, default/override selection, and focused
|
||||
|
|
|
|||
|
|
@ -38,9 +38,9 @@ a new combination of model + backend + hardware:
|
|||
|
||||
| Run | Expected hash relation |
|
||||
|----------------------------------------------|------------------------------------|
|
||||
| A: no `--pulid-*` flags | baseline |
|
||||
| B: PuLID flags, `--pulid-id-weight 0.0` | **byte-identical to A** |
|
||||
| C: PuLID flags, `--pulid-id-weight 1.0` | **different from A,B**, preserves source identity |
|
||||
| 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.
|
||||
|
|
|
|||
215
docs/dgl-builtins.md
Normal file
215
docs/dgl-builtins.md
Normal file
|
|
@ -0,0 +1,215 @@
|
|||
<!-- 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`, `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 |
|
||||
1943
docs/dgl.md
Normal file
1943
docs/dgl.md
Normal file
File diff suppressed because it is too large
Load diff
116
docs/dgl/README.md
Normal file
116
docs/dgl/README.md
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
# 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) |
|
||||
| [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. |
|
||||
107
docs/dgl/adetailer/adetailer-existing-image.dgl
Normal file
107
docs/dgl/adetailer/adetailer-existing-image.dgl
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
# 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 }
|
||||
}
|
||||
128
docs/dgl/adetailer/adetailer-generated-image.dgl
Normal file
128
docs/dgl/adetailer/adetailer-generated-image.dgl
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
# 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 }
|
||||
}
|
||||
43
docs/dgl/anima/anima-preview-txt2img.dgl
Normal file
43
docs/dgl/anima/anima-preview-txt2img.dgl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# 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}
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
# 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 }
|
||||
}
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
# 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 }
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
# 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 }
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
# 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 }
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
# 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 }
|
||||
}
|
||||
39
docs/dgl/animatediff/realisticvision-v6-txt2img.dgl
Normal file
39
docs/dgl/animatediff/realisticvision-v6-txt2img.dgl
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# 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 }
|
||||
}
|
||||
43
docs/dgl/boogu_image/boogu-image-base-txt2img.dgl
Normal file
43
docs/dgl/boogu_image/boogu-image-base-txt2img.dgl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# 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}
|
||||
}
|
||||
68
docs/dgl/boogu_image/boogu-image-edit.dgl
Normal file
68
docs/dgl/boogu_image/boogu-image-edit.dgl
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
# 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}
|
||||
}
|
||||
43
docs/dgl/chroma/chroma-unlocked-v40-txt2img.dgl
Normal file
43
docs/dgl/chroma/chroma-unlocked-v40-txt2img.dgl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# 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}
|
||||
}
|
||||
42
docs/dgl/chroma_radiance/chroma1-radiance-v0-4-txt2img.dgl
Normal file
42
docs/dgl/chroma_radiance/chroma1-radiance-v0-4-txt2img.dgl
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# 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}
|
||||
}
|
||||
36
docs/dgl/distilled_sd/sdxs-512-dreamshaper-txt2img.dgl
Normal file
36
docs/dgl/distilled_sd/sdxs-512-dreamshaper-txt2img.dgl
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# 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}
|
||||
}
|
||||
54
docs/dgl/distilled_sd/ssd1b-txt2img.dgl
Normal file
54
docs/dgl/distilled_sd/ssd1b-txt2img.dgl
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
# 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}
|
||||
}
|
||||
38
docs/dgl/ernie_image/ernie-image-turbo-txt2img.dgl
Normal file
38
docs/dgl/ernie_image/ernie-image-turbo-txt2img.dgl
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# 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}
|
||||
}
|
||||
43
docs/dgl/ernie_image/ernie-image-txt2img.dgl
Normal file
43
docs/dgl/ernie_image/ernie-image-txt2img.dgl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# 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}
|
||||
}
|
||||
17
docs/dgl/esrgan/realesrgan-x4plus-anime-6b-upscale.dgl
Normal file
17
docs/dgl/esrgan/realesrgan-x4plus-anime-6b-upscale.dgl
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# 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
|
||||
}
|
||||
44
docs/dgl/esrgan/sd1-5-txt2img-esrgan.dgl
Normal file
44
docs/dgl/esrgan/sd1-5-txt2img-esrgan.dgl
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# 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}
|
||||
}
|
||||
61
docs/dgl/fibo2/fibo2-dev-edit.dgl
Normal file
61
docs/dgl/fibo2/fibo2-dev-edit.dgl
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
# 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}
|
||||
}
|
||||
44
docs/dgl/fibo2/fibo2-dev-txt2img.dgl
Normal file
44
docs/dgl/fibo2/fibo2-dev-txt2img.dgl
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# 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}
|
||||
}
|
||||
56
docs/dgl/fibo2/fibo2-edit-turbo.dgl
Normal file
56
docs/dgl/fibo2/fibo2-edit-turbo.dgl
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
# 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}
|
||||
}
|
||||
42
docs/dgl/flux/flux1-dev-lora.dgl
Normal file
42
docs/dgl/flux/flux1-dev-lora.dgl
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# 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}
|
||||
}
|
||||
39
docs/dgl/flux/flux1-dev-txt2img.dgl
Normal file
39
docs/dgl/flux/flux1-dev-txt2img.dgl
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# 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}
|
||||
}
|
||||
39
docs/dgl/flux/flux1-schnell-txt2img.dgl
Normal file
39
docs/dgl/flux/flux1-schnell-txt2img.dgl
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# 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}
|
||||
}
|
||||
62
docs/dgl/flux2/flux2-dev-edit.dgl
Normal file
62
docs/dgl/flux2/flux2-dev-edit.dgl
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
# 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}
|
||||
}
|
||||
62
docs/dgl/flux2/flux2-klein-4b-edit.dgl
Normal file
62
docs/dgl/flux2/flux2-klein-4b-edit.dgl
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
# 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}
|
||||
}
|
||||
38
docs/dgl/flux2/flux2-klein-4b-txt2img.dgl
Normal file
38
docs/dgl/flux2/flux2-klein-4b-txt2img.dgl
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# 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}
|
||||
}
|
||||
62
docs/dgl/flux2/flux2-klein-9b-edit.dgl
Normal file
62
docs/dgl/flux2/flux2-klein-9b-edit.dgl
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
# 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}
|
||||
}
|
||||
38
docs/dgl/flux2/flux2-klein-9b-txt2img.dgl
Normal file
38
docs/dgl/flux2/flux2-klein-9b-txt2img.dgl
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# 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}
|
||||
}
|
||||
43
docs/dgl/flux2/flux2-klein-base-4b-txt2img.dgl
Normal file
43
docs/dgl/flux2/flux2-klein-base-4b-txt2img.dgl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# 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}
|
||||
}
|
||||
43
docs/dgl/flux2/flux2-klein-base-9b-txt2img.dgl
Normal file
43
docs/dgl/flux2/flux2-klein-base-9b-txt2img.dgl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# 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}
|
||||
}
|
||||
43
docs/dgl/flux3/flux3-image-klein-base-txt2img.dgl
Normal file
43
docs/dgl/flux3/flux3-image-klein-base-txt2img.dgl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# 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}
|
||||
}
|
||||
62
docs/dgl/flux3/flux3-image-klein-edit.dgl
Normal file
62
docs/dgl/flux3/flux3-image-klein-edit.dgl
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
# 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}
|
||||
}
|
||||
38
docs/dgl/flux3/flux3-image-klein-txt2img.dgl
Normal file
38
docs/dgl/flux3/flux3-image-klein-txt2img.dgl
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# 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}
|
||||
}
|
||||
38
docs/dgl/hidream_o1_image/hidream-o1-image-dev-txt2img.dgl
Normal file
38
docs/dgl/hidream_o1_image/hidream-o1-image-dev-txt2img.dgl
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# 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 = 20
|
||||
method = "euler"
|
||||
scheduler = "discrete"
|
||||
noise_scale = 8.0
|
||||
}
|
||||
|
||||
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)
|
||||
image = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
||||
image::save(output_path, image)
|
||||
return {image = image, latent = latent}
|
||||
}
|
||||
46
docs/dgl/hunyuan_video/hunyuanvideo1-5-720p-txt2video.dgl
Normal file
46
docs/dgl/hunyuan_video/hunyuanvideo1-5-720p-txt2video.dgl
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# 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 = {}}
|
||||
}
|
||||
43
docs/dgl/ideogram4/ideogram4-txt2img.dgl
Normal file
43
docs/dgl/ideogram4/ideogram4-txt2img.dgl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# 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}
|
||||
}
|
||||
49
docs/dgl/ip_adapter/ip-adapter-plus-sd1-5.dgl
Normal file
49
docs/dgl/ip_adapter/ip-adapter-plus-sd1-5.dgl
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# 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 }
|
||||
}
|
||||
47
docs/dgl/ip_adapter/ip-adapter-sd1-5.dgl
Normal file
47
docs/dgl/ip_adapter/ip-adapter-sd1-5.dgl
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# 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 }
|
||||
}
|
||||
76
docs/dgl/ip_adapter/ip-adapter-sdxl-controlnet.dgl
Normal file
76
docs/dgl/ip_adapter/ip-adapter-sdxl-controlnet.dgl
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
# 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 }
|
||||
}
|
||||
47
docs/dgl/ip_adapter/ip-adapter-sdxl.dgl
Normal file
47
docs/dgl/ip_adapter/ip-adapter-sdxl.dgl
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# 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 }
|
||||
}
|
||||
42
docs/dgl/iris/iris-3b-txt2img.dgl
Normal file
42
docs/dgl/iris/iris-3b-txt2img.dgl
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# 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}
|
||||
}
|
||||
63
docs/dgl/kontext/flux1-kontext-dev-edit.dgl
Normal file
63
docs/dgl/kontext/flux1-kontext-dev-edit.dgl
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
# 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}
|
||||
}
|
||||
43
docs/dgl/krea2/krea2-raw-txt2img.dgl
Normal file
43
docs/dgl/krea2/krea2-raw-txt2img.dgl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# 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}
|
||||
}
|
||||
39
docs/dgl/lcm/lcm-lora-sd1-5.dgl
Normal file
39
docs/dgl/lcm/lcm-lora-sd1-5.dgl
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# 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}
|
||||
}
|
||||
39
docs/dgl/lens/lens-turbo-txt2img.dgl
Normal file
39
docs/dgl/lens/lens-turbo-txt2img.dgl
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# 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}
|
||||
}
|
||||
44
docs/dgl/lens/lens-txt2img.dgl
Normal file
44
docs/dgl/lens/lens-txt2img.dgl
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# 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}
|
||||
}
|
||||
45
docs/dgl/lingbot_video/lingbot-video-dens-1-3b-txt2video.dgl
Normal file
45
docs/dgl/lingbot_video/lingbot-video-dens-1-3b-txt2video.dgl
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
# 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 = {}}
|
||||
}
|
||||
48
docs/dgl/llada_image/llada-image-turbo-edit.dgl
Normal file
48
docs/dgl/llada_image/llada-image-turbo-edit.dgl
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# 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}
|
||||
}
|
||||
40
docs/dgl/llada_image/llada-image-turbo-txt2img.dgl
Normal file
40
docs/dgl/llada_image/llada-image-turbo-txt2img.dgl
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
# 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}
|
||||
}
|
||||
43
docs/dgl/longcat_image/longcat-image-txt2img.dgl
Normal file
43
docs/dgl/longcat_image/longcat-image-txt2img.dgl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# 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}
|
||||
}
|
||||
45
docs/dgl/lora/sd1-5-lora.dgl
Normal file
45
docs/dgl/lora/sd1-5-lora.dgl
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
# 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}
|
||||
}
|
||||
100
docs/dgl/ltx2/ltx-2-3-dev-first-last-frame.dgl
Normal file
100
docs/dgl/ltx2/ltx-2-3-dev-first-last-frame.dgl
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
# 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}
|
||||
}
|
||||
92
docs/dgl/ltx2/ltx-2-3-dev-img2video.dgl
Normal file
92
docs/dgl/ltx2/ltx-2-3-dev-img2video.dgl
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
# 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}
|
||||
}
|
||||
70
docs/dgl/ltx2/ltx-2-3-dev-txt2video.dgl
Normal file
70
docs/dgl/ltx2/ltx-2-3-dev-txt2video.dgl
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
# 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}
|
||||
}
|
||||
125
docs/dgl/ltx2/ltx-2-3-spatial-upscale.dgl
Normal file
125
docs/dgl/ltx2/ltx-2-3-spatial-upscale.dgl
Normal file
|
|
@ -0,0 +1,125 @@
|
|||
# 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}
|
||||
}
|
||||
91
docs/dgl/ltx2/ltx-2-5-dev-img2video.dgl
Normal file
91
docs/dgl/ltx2/ltx-2-5-dev-img2video.dgl
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
# 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}
|
||||
}
|
||||
69
docs/dgl/ltx2/ltx-2-5-dev-txt2video.dgl
Normal file
69
docs/dgl/ltx2/ltx-2-5-dev-txt2video.dgl
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
# 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}
|
||||
}
|
||||
92
docs/dgl/ltx2/ltx-2-5-spatial-upscale.dgl
Normal file
92
docs/dgl/ltx2/ltx-2-5-spatial-upscale.dgl
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/ltx2.md — LTX-2.5 spatial latent upscale
|
||||
|
||||
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"
|
||||
hires_model_path = "../models/latent_upscale_models/ltx-2.5-latent-spatial-upscaler-x2-bf16-1.0.safetensors"
|
||||
|
||||
output_path = "hires_t2v.avi"
|
||||
|
||||
prompt = "a lovely cat"
|
||||
negative_prompt = ""
|
||||
|
||||
seed = 42
|
||||
rng_type = "cuda"
|
||||
width = 640
|
||||
height = 352
|
||||
frames = 121
|
||||
fps = 16
|
||||
|
||||
steps = 20
|
||||
cfg_scale = 3.0
|
||||
method = "euler"
|
||||
scheduler = "ltx2"
|
||||
audio_scale = 1
|
||||
|
||||
hires_steps = 6
|
||||
hires_scheduler_steps = 8
|
||||
}
|
||||
|
||||
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)
|
||||
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_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_base = pack_av(hires_video, hires_audio, audio_scale = audio_scale)
|
||||
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)
|
||||
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}
|
||||
}
|
||||
52
docs/dgl/mage_flow/mage-flow-edit.dgl
Normal file
52
docs/dgl/mage_flow/mage-flow-edit.dgl
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/mage_flow.md — Image editing
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/Mage-Flow-Edit.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/mage_vae.safetensors"
|
||||
|
||||
reference_0_path = "../inputs/flux/flux1-dev-q8_0.png"
|
||||
output_path = "output.png"
|
||||
|
||||
prompt = "change 'flux.cpp' to 'mage.cpp'"
|
||||
negative_prompt = ""
|
||||
|
||||
seed = 42
|
||||
rng_type = "cuda"
|
||||
|
||||
steps = 20
|
||||
cfg_scale = 4.0
|
||||
method = "euler"
|
||||
scheduler = "discrete"
|
||||
}
|
||||
|
||||
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 = "mage_flow", params_backend = "cpu")
|
||||
text = load_text_encoder(text_path, family = "mage_flow", params_backend = "cpu", vision_path = vision_path)
|
||||
vae = load_vae(vae_path, family = "mage_flow", 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 = 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))
|
||||
|
||||
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], 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}
|
||||
}
|
||||
38
docs/dgl/mage_flow/mage-flow-turbo-txt2img.dgl
Normal file
38
docs/dgl/mage_flow/mage-flow-turbo-txt2img.dgl
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/mage_flow.md — Text-to-image
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/Mage-Flow-Turbo.safetensors"
|
||||
text_path = "../models/text_encoders/Qwen3-VL-4B-Instruct-Q4_K_M.gguf"
|
||||
vae_path = "../models/vae/mage_vae.safetensors"
|
||||
|
||||
output_path = "output.png"
|
||||
|
||||
prompt = "a lovely cat holding a sign says 'mage.cpp'"
|
||||
|
||||
seed = 42
|
||||
rng_type = "cuda"
|
||||
width = 512
|
||||
height = 512
|
||||
|
||||
steps = 4
|
||||
method = "euler"
|
||||
scheduler = "discrete"
|
||||
}
|
||||
|
||||
fn main() {
|
||||
model = load_dit(model_path, family = "mage_flow", params_backend = "cpu")
|
||||
text = load_text_encoder(text_path, family = "mage_flow", params_backend = "cpu")
|
||||
vae = load_vae(vae_path, family = "mage_flow", 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}
|
||||
}
|
||||
39
docs/dgl/ming_image/ming-image-0-1-design-txt2img.dgl
Normal file
39
docs/dgl/ming_image/ming-image-0-1-design-txt2img.dgl
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/ming_image.md — Text-to-image
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/ming_image_0.1_design_bf16.safetensors"
|
||||
text_path = "../models/text_encoders/ming_image_0.1_ling_mini_2.0_bf16.safetensors"
|
||||
tokenizer_path = "../models/tokenizers/tokenizer.json"
|
||||
vae_path = "../models/vae/ming_image_vae_bf16.safetensors"
|
||||
|
||||
output_path = "ming_image.png"
|
||||
|
||||
prompt = "A cheerful orange cat sticker, transparent background"
|
||||
|
||||
seed = 42
|
||||
rng_type = "cuda"
|
||||
width = 1024
|
||||
height = 1024
|
||||
|
||||
steps = 12
|
||||
method = "euler"
|
||||
scheduler = "discrete"
|
||||
}
|
||||
|
||||
fn main() {
|
||||
model = load_dit(model_path, family = "ming_image", params_backend = "cpu")
|
||||
text = load_text_encoder(text_path, family = "ming_image", params_backend = "cpu", tokenizer = tokenizer_path)
|
||||
vae = load_vae(vae_path, family = "ming_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}
|
||||
}
|
||||
85
docs/dgl/minimax_h3/minimax-h3-first-last-frame.dgl
Normal file
85
docs/dgl/minimax_h3/minimax-h3-first-last-frame.dgl
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/minimax_h3.md — First/last-frame conditioning
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/minimax_h3_fl2va-Q4_K_M.gguf"
|
||||
text_path = "../models/text_encoders/qwen3vl_32b_minimax_h3-Q4_K_M.gguf"
|
||||
vae_path = "../models/vae/minimax_h3_video_vae_fp16.safetensors"
|
||||
audio_vae_path = "../models/vae/minimax_h3_audio_vae_fp32.safetensors"
|
||||
|
||||
first_frame_path = "../inputs/ernie_image/turbo_example.png"
|
||||
output_path = "output.avi"
|
||||
|
||||
prompt = "a lovely cat"
|
||||
|
||||
seed = 42
|
||||
rng_type = "cpu"
|
||||
width = 864
|
||||
height = 480
|
||||
frames = 56
|
||||
fps = 24
|
||||
|
||||
steps = 20
|
||||
method = "euler"
|
||||
scheduler = "discrete"
|
||||
audio_scale = 4
|
||||
}
|
||||
|
||||
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 h3_reference_noise(latent, seed) {
|
||||
rng = make_rng("cuda", seed = seed)
|
||||
return tensor::lerp(latent, tensor::randn_like(latent, rng = rng), 0.001)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
first_frame = image::load(first_frame_path)
|
||||
|
||||
model = load_dit(model_path, family = "minimax_h3", params_backend = "cpu")
|
||||
text = load_text_encoder(text_path, family = "minimax_h3", params_backend = "cpu")
|
||||
vae = load_vae(vae_path, family = "minimax_h3", 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)
|
||||
audio_vae = load_audio_vae(audio_vae_path, family = "minimax_h3", 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)
|
||||
h3_visual_0_raw = vae_to_dit_latents(vae, vae_encode(vae, first_frame_pixels, rng = rng))
|
||||
h3_visual_0 = h3_reference_noise(h3_visual_0_raw, seed)
|
||||
|
||||
condition = encode_prompt(text, prompt, width = width, height = height, media = [first_frame_pixels[:, :, 0]])
|
||||
predict = predictor(model, condition, audio_length = audio_shape[0], ref_latents = [h3_visual_0], keyframe_indices = [0])
|
||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
||||
latent = sample(start, sigmas, predict = predict, 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}
|
||||
}
|
||||
81
docs/dgl/minimax_h3/minimax-h3-latent-hires.dgl
Normal file
81
docs/dgl/minimax_h3/minimax-h3-latent-hires.dgl
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/minimax_h3.md — Latent hires second pass (two-stage sampling)
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/minimax_h3_fl2va-Q4_K_M.gguf"
|
||||
text_path = "../models/text_encoders/qwen3vl_32b_minimax_h3-Q4_K_M.gguf"
|
||||
vae_path = "../models/vae/minimax_h3_video_vae_fp16.safetensors"
|
||||
audio_vae_path = "../models/vae/minimax_h3_audio_vae_fp32.safetensors"
|
||||
|
||||
output_path = "output.avi"
|
||||
|
||||
prompt = "a lovely cat"
|
||||
|
||||
seed = 42
|
||||
rng_type = "cpu"
|
||||
width = 864
|
||||
height = 480
|
||||
frames = 56
|
||||
fps = 24
|
||||
|
||||
steps = 20
|
||||
method = "euler"
|
||||
scheduler = "discrete"
|
||||
audio_scale = 4
|
||||
|
||||
hires_target_width = 1216
|
||||
hires_target_height = 672
|
||||
hires_vae_scale = 16
|
||||
hires_steps = 4
|
||||
hires_scheduler_steps = 9
|
||||
hires_mode = "bicubic"
|
||||
}
|
||||
|
||||
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 = "minimax_h3", flash_attn_mode = "on", params_backend = "cpu")
|
||||
text = load_text_encoder(text_path, family = "minimax_h3", params_backend = "cpu")
|
||||
vae = load_vae(vae_path, family = "minimax_h3", 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 = "minimax_h3", 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)
|
||||
|
||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
||||
predict = predictor(model, condition, audio_length = audio_shape[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)
|
||||
hires_source = latent[:, :, :tensor::shape(video_base)[2], :tensor::shape(video_base)[3]]
|
||||
hires_video = tensor::interpolate(hires_source, size = [math::floor(hires_target_width / hires_vae_scale), math::floor(hires_target_height / hires_vae_scale)], mode = hires_mode)
|
||||
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_base = pack_av(hires_video, hires_original_audio, audio_scale = audio_scale)
|
||||
hires_schedule = make_sigmas(predict, latent = hires_base, steps = hires_scheduler_steps, scheduler = scheduler)
|
||||
hires_sigmas = hires_schedule[-(hires_steps + 1):]
|
||||
hires_start = add_noise(predict, hires_base, tensor::randn_like(hires_base, rng = rng), sigma = hires_sigmas[0])
|
||||
hires_latent = sample(hires_start, hires_sigmas, predict = predict, method = method, rng = rng)
|
||||
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 = 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}
|
||||
}
|
||||
84
docs/dgl/minimax_h3/minimax-h3-learned-hires.dgl
Normal file
84
docs/dgl/minimax_h3/minimax-h3-learned-hires.dgl
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/minimax_h3.md — Latent hires second pass (two-stage sampling)
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/minimax_h3_fl2va-Q4_K_M.gguf"
|
||||
text_path = "../models/text_encoders/qwen3vl_32b_minimax_h3-Q4_K_M.gguf"
|
||||
vae_path = "../models/vae/minimax_h3_video_vae_fp16.safetensors"
|
||||
audio_vae_path = "../models/vae/minimax_h3_audio_vae_fp32.safetensors"
|
||||
hires_model_path = "../models/latent_upscale_models/h3-latent-upscaler-3d.safetensors"
|
||||
|
||||
output_path = "output.avi"
|
||||
|
||||
prompt = "a lovely cat"
|
||||
|
||||
seed = 42
|
||||
rng_type = "cpu"
|
||||
width = 864
|
||||
height = 480
|
||||
frames = 56
|
||||
fps = 24
|
||||
|
||||
steps = 20
|
||||
method = "euler"
|
||||
scheduler = "discrete"
|
||||
audio_scale = 4
|
||||
|
||||
hires_target_width = 1216
|
||||
hires_target_height = 672
|
||||
hires_vae_scale = 16
|
||||
hires_steps = 4
|
||||
hires_scheduler_steps = 9
|
||||
}
|
||||
|
||||
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 = "minimax_h3", params_backend = "cpu")
|
||||
text = load_text_encoder(text_path, family = "minimax_h3", params_backend = "cpu")
|
||||
vae = load_vae(vae_path, family = "minimax_h3", 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 = "minimax_h3", 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)
|
||||
|
||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
||||
predict = predictor(model, condition, audio_length = audio_shape[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)
|
||||
hires_source = latent[:, :, :tensor::shape(video_base)[2], :tensor::shape(video_base)[3]]
|
||||
hires_upscaler = load_latent_upscaler(hires_model_path, family = "minimax_h3", params_backend = "cpu")
|
||||
hires_upscaled = upscale_latent(hires_upscaler, hires_source, width = math::floor(hires_target_width / hires_vae_scale), height = math::floor(hires_target_height / hires_vae_scale))
|
||||
hires_upscaled_shape = tensor::shape(hires_upscaled)
|
||||
hires_video = 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_base = pack_av(hires_video, hires_original_audio, audio_scale = audio_scale)
|
||||
hires_schedule = make_sigmas(predict, latent = hires_base, steps = hires_scheduler_steps, scheduler = scheduler)
|
||||
hires_sigmas = hires_schedule[-(hires_steps + 1):]
|
||||
hires_start = add_noise(predict, hires_base, tensor::randn_like(hires_base, rng = rng), sigma = hires_sigmas[0])
|
||||
hires_latent = sample(hires_start, hires_sigmas, predict = predict, method = method, rng = rng)
|
||||
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 = 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}
|
||||
}
|
||||
94
docs/dgl/minimax_h3/minimax-h3-reference-to-av.dgl
Normal file
94
docs/dgl/minimax_h3/minimax-h3-reference-to-av.dgl
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/minimax_h3.md — Reference-to-audio-video conditioning
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/minimax_h3_ref2va_pruned-Q4_K_M.gguf"
|
||||
text_path = "../models/text_encoders/qwen3vl_32b_minimax_h3-Q4_K_M.gguf"
|
||||
vae_path = "../models/vae/minimax_h3_video_vae_fp16.safetensors"
|
||||
audio_vae_path = "../models/vae/minimax_h3_audio_vae_fp32.safetensors"
|
||||
|
||||
h3_image_0_path = "../inputs/ernie_image/turbo_example.png"
|
||||
output_path = "output.avi"
|
||||
|
||||
prompt = "Use the cat from <Picture 1> as the main character. Keep the cat鈥檚 appearance, fur color, facial features, and identity consistent with the reference image. Create a 2-second cinematic video: start with an extreme close-up shot of the cat鈥檚 face, focusing on its cute expression and detailed fur texture. The camera slowly rotates around the cat鈥檚 head, creating a dynamic reveal. Then smoothly pull back and zoom out to reveal the full scene: the cat is standing confidently on a surfboard, riding ocean waves. Water splashes around the board, sea breeze gently moves the cat鈥檚 fur, and the cat maintains a cute and fearless expression while surfing. Smooth camera movement, cinematic orbit shot, seamless zoom-out transition, low-angle wide shot, realistic ocean environment, golden sunlight, dynamic waves, high-quality realistic style, natural motion, no distortion, keep the cat鈥檚 identity unchanged."
|
||||
|
||||
seed = 42
|
||||
rng_type = "cpu"
|
||||
width = 864
|
||||
height = 480
|
||||
frames = 56
|
||||
fps = 24
|
||||
|
||||
steps = 20
|
||||
method = "euler"
|
||||
scheduler = "discrete"
|
||||
audio_scale = 4
|
||||
}
|
||||
|
||||
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 h3_reference_noise(latent, seed) {
|
||||
rng = make_rng("cuda", seed = seed)
|
||||
return tensor::lerp(latent, tensor::randn_like(latent, rng = rng), 0.001)
|
||||
}
|
||||
|
||||
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() {
|
||||
h3_image_0 = image::load(h3_image_0_path)
|
||||
|
||||
model = load_dit(model_path, family = "minimax_h3", params_backend = "cpu")
|
||||
text = load_text_encoder(text_path, family = "minimax_h3", params_backend = "cpu")
|
||||
vae = load_vae(vae_path, family = "minimax_h3", params_backend = "cpu")
|
||||
|
||||
rng = make_rng(rng_type, seed = seed)
|
||||
video_base = tensor::zeros(latent_shape(vae, width = width, height = height, frames = frames))
|
||||
audio_vae = load_audio_vae(audio_vae_path, family = "minimax_h3", 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)
|
||||
h3_image_0_original = image::to_f32(h3_image_0, channels = 3)
|
||||
h3_image_0_area = math::min(width * height, tensor::shape(h3_image_0_original)[0] * tensor::shape(h3_image_0_original)[1])
|
||||
h3_image_0_pixels = fit_reference_area(h3_image_0_original, h3_image_0_area, 32, mode = "bilinear")
|
||||
h3_visual_0_raw = vae_to_dit_latents(vae, vae_encode(vae, h3_image_0_pixels, rng = rng))
|
||||
h3_visual_0 = h3_reference_noise(h3_visual_0_raw, seed)
|
||||
|
||||
condition = encode_prompt(text, prompt, width = width, height = height, media = [{image = h3_image_0_pixels}])
|
||||
predict = predictor(model, condition, audio_length = audio_shape[0], ref_latents = [h3_visual_0], reference_blocks = [{kind = "image", video = 0}])
|
||||
sigmas = make_sigmas(predict, latent = base, steps = steps, scheduler = scheduler)
|
||||
start = add_noise(predict, base, tensor::randn_like(base, rng = rng), sigma = sigmas[0])
|
||||
latent = sample(start, sigmas, predict = predict, 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}
|
||||
}
|
||||
65
docs/dgl/minimax_h3/minimax-h3-text-to-av.dgl
Normal file
65
docs/dgl/minimax_h3/minimax-h3-text-to-av.dgl
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/minimax_h3.md — Text-to-audio-video
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/minimax_h3_fl2va-Q4_K_M.gguf"
|
||||
text_path = "../models/text_encoders/qwen3vl_32b_minimax_h3-Q4_K_M.gguf"
|
||||
vae_path = "../models/vae/minimax_h3_video_vae_fp16.safetensors"
|
||||
audio_vae_path = "../models/vae/minimax_h3_audio_vae_fp32.safetensors"
|
||||
|
||||
output_path = "output.avi"
|
||||
|
||||
prompt = "A cute American Shorthair silver tabby kitten surfs on a tropical ocean wave, riding a white surfboard with the clear text 'sd.cpp' on it. Cinematic tracking shot, realistic water, bright sunlight, smooth motion, and consistent character appearance. Add upbeat tropical surf-rock background music with cheerful drums and guitar, synchronized with the kitten鈥檚 energetic surfing."
|
||||
|
||||
seed = 42
|
||||
rng_type = "cpu"
|
||||
width = 864
|
||||
height = 480
|
||||
frames = 56
|
||||
fps = 24
|
||||
|
||||
steps = 20
|
||||
method = "euler"
|
||||
scheduler = "discrete"
|
||||
audio_scale = 4
|
||||
}
|
||||
|
||||
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 = "minimax_h3", params_backend = "cpu")
|
||||
text = load_text_encoder(text_path, family = "minimax_h3", params_backend = "cpu")
|
||||
vae = load_vae(vae_path, family = "minimax_h3", 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 = "minimax_h3", 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)
|
||||
|
||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
||||
predict = predictor(model, condition, audio_length = audio_shape[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)
|
||||
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}
|
||||
}
|
||||
73
docs/dgl/minimax_h3_image/minimax-h3-image-edit.dgl
Normal file
73
docs/dgl/minimax_h3_image/minimax-h3-image-edit.dgl
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/minimax_h3_image.md — Reference-image editing
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/minimax_h3_image_pruned_bf16.safetensors"
|
||||
text_path = "../models/text_encoders/qwen3vl_32b_minimax_h3-Q4_K_M.gguf"
|
||||
vae_path = "../models/vae/minimax_h3_image_vae_fp16.safetensors"
|
||||
|
||||
reference_0_path = "../inputs/ernie_image/turbo_example.png"
|
||||
output_path = "output.png"
|
||||
|
||||
prompt = "Edit <Picture 1>. Put a red scarf on the cat, preserving its face and the background."
|
||||
|
||||
seed = 42
|
||||
rng_type = "cpu"
|
||||
width = 1024
|
||||
height = 1024
|
||||
|
||||
method = "euler"
|
||||
custom_sigmas = [1.0, 0.9675236940383911, 0.8875485062599182, 0.75, 0.5327739119529724, 0.23200887441635132, 0.0]
|
||||
}
|
||||
|
||||
fn h3_image_reference_noise(latent, seed) {
|
||||
shape = tensor::shape(latent)
|
||||
patches = tensor::zeros([2, 2, shape[-2], math::floor(shape[0] / 2), math::floor(shape[1] / 2)])
|
||||
rng = make_rng("cpu", seed = seed)
|
||||
noise = tensor::reshape(tensor::permute(tensor::randn_like(patches, rng = rng), [0, 3, 1, 4, 2]), shape)
|
||||
return tensor::lerp(latent, noise, 0.001)
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
model = load_dit(model_path, family = "minimax_h3_image", flash_attn_mode = "on", params_backend = "cpu")
|
||||
text = load_text_encoder(text_path, family = "minimax_h3_image", params_backend = "cpu")
|
||||
vae = load_vae(vae_path, family = "minimax_h3_image", params_backend = "cpu")
|
||||
|
||||
encode_rng = make_rng(rng_type, seed = seed)
|
||||
image_base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
||||
base = tensor::unsqueeze(image_base, axis = 2)
|
||||
reference_0_original = image::to_f32(reference_0, channels = 3)
|
||||
reference_0_short = math::min(tensor::shape(reference_0_original)[0], tensor::shape(reference_0_original)[1])
|
||||
reference_0_side = math::min(2048, -math::min(-1024, -reference_0_short))
|
||||
reference_0_pixels = fit_reference_area(reference_0_original, tensor::shape(reference_0_original)[0] * tensor::shape(reference_0_original)[1] * reference_0_side * reference_0_side / (reference_0_short * reference_0_short), 32, mode = "lanczos")
|
||||
reference_latent_0_raw = vae_to_dit_latents(vae, vae_encode(vae, reference_0_pixels, rng = encode_rng, tiling = tiling()))
|
||||
reference_latent_0 = h3_image_reference_noise(reference_latent_0_raw, seed)
|
||||
|
||||
condition = encode_prompt(text, prompt, width = width, height = height, media = [reference_0_original])
|
||||
predict = predictor(model, condition, video_sigma_shift = 1, reference_blocks = [{kind = "image", video = 0}], ref_latents = [reference_latent_0], ref_index_mode = "increase")
|
||||
sigmas = tensor::vector(custom_sigmas, dtype = "f32")
|
||||
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), tiling = tiling())
|
||||
image::save(output_path, image)
|
||||
return {image = image, latent = latent}
|
||||
}
|
||||
39
docs/dgl/minimax_h3_image/minimax-h3-image-txt2img.dgl
Normal file
39
docs/dgl/minimax_h3_image/minimax-h3-image-txt2img.dgl
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/minimax_h3_image.md — Text-to-image
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/minimax_h3_image_pruned_bf16.safetensors"
|
||||
text_path = "../models/text_encoders/qwen3vl_32b_minimax_h3-Q4_K_M.gguf"
|
||||
vae_path = "../models/vae/minimax_h3_image_vae_fp16.safetensors"
|
||||
|
||||
output_path = "output.png"
|
||||
|
||||
prompt = "A silver tabby kitten holding a sign reading 'sd.cpp', natural daylight"
|
||||
|
||||
seed = 42
|
||||
rng_type = "cpu"
|
||||
width = 1024
|
||||
height = 1024
|
||||
|
||||
method = "euler"
|
||||
custom_sigmas = [1.0, 0.9675236940383911, 0.8875485062599182, 0.75, 0.5327739119529724, 0.23200887441635132, 0.0]
|
||||
}
|
||||
|
||||
fn main() {
|
||||
model = load_dit(model_path, family = "minimax_h3_image", flash_attn_mode = "on", params_backend = "cpu")
|
||||
text = load_text_encoder(text_path, family = "minimax_h3_image", params_backend = "cpu")
|
||||
vae = load_vae(vae_path, family = "minimax_h3_image", params_backend = "cpu")
|
||||
|
||||
image_base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
||||
base = tensor::unsqueeze(image_base, axis = 2)
|
||||
|
||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
||||
predict = predictor(model, condition, video_sigma_shift = 1)
|
||||
sigmas = tensor::vector(custom_sigmas, dtype = "f32")
|
||||
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), tiling = tiling())
|
||||
image::save(output_path, image)
|
||||
return {image = image, latent = latent}
|
||||
}
|
||||
41
docs/dgl/minit2i/minit2i-cuda-txt2img.dgl
Normal file
41
docs/dgl/minit2i/minit2i-cuda-txt2img.dgl
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/minit2i.md — CUDA
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/minit2i/diffusion_pytorch_model.safetensors"
|
||||
text_path = "../models/text_encoders/flan-t5-large/model.safetensors"
|
||||
|
||||
output_path = "minit2i_cuda.png"
|
||||
|
||||
prompt = "a cat"
|
||||
|
||||
seed = 42
|
||||
rng_type = "cuda"
|
||||
width = 512
|
||||
height = 512
|
||||
|
||||
steps = 100
|
||||
cfg_scale = 6.0
|
||||
method = "euler"
|
||||
scheduler = "discrete"
|
||||
}
|
||||
|
||||
fn main() {
|
||||
model = load_dit(model_path, family = "minit2i")
|
||||
text = load_text_encoder(text_path, family = "minit2i", t5_path = text_path)
|
||||
base = tensor::zeros([width, height, 3, 1])
|
||||
|
||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
||||
negative = zero_out(positive, fields = ["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)
|
||||
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}
|
||||
}
|
||||
42
docs/dgl/minit2i/minit2i-metal-txt2img.dgl
Normal file
42
docs/dgl/minit2i/minit2i-metal-txt2img.dgl
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
# version: 0.0.0
|
||||
# CLI/context: --threads 8
|
||||
# docs/models/minit2i.md — macOS with Metal
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/minit2i/diffusion_pytorch_model.safetensors"
|
||||
text_path = "../models/text_encoders/flan-t5-large/model.safetensors"
|
||||
|
||||
output_path = "minit2i_metal.png"
|
||||
|
||||
prompt = "a cat"
|
||||
|
||||
seed = 42
|
||||
rng_type = "cpu"
|
||||
width = 512
|
||||
height = 512
|
||||
|
||||
steps = 100
|
||||
cfg_scale = 6.0
|
||||
method = "euler"
|
||||
scheduler = "discrete"
|
||||
}
|
||||
|
||||
fn main() {
|
||||
model = load_dit(model_path, backend = "metal", family = "minit2i")
|
||||
text = load_text_encoder(text_path, backend = "metal", family = "minit2i", t5_path = text_path)
|
||||
base = tensor::zeros([width, height, 3, 1])
|
||||
|
||||
positive = encode_prompt(text, prompt, width = width, height = height)
|
||||
negative = zero_out(positive, fields = ["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)
|
||||
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}
|
||||
}
|
||||
44
docs/dgl/moss_image/moss-image-base-txt2img.dgl
Normal file
44
docs/dgl/moss_image/moss-image-base-txt2img.dgl
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/moss_image.md — MOSS-Image Base
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/moss_image_base_int8_convrot_attn.safetensors"
|
||||
text_path = "../models/text_encoders/Qwen3.5-9B-Q4_K_M.gguf"
|
||||
tokenizer_path = "../models/tokenizers/tokenizer_qwen3.5.json"
|
||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
||||
|
||||
output_path = "output.png"
|
||||
|
||||
prompt = "a lovely cat holding a sign says 'moss-image.cpp'"
|
||||
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 = "moss_image", params_backend = "cpu")
|
||||
text = load_text_encoder(text_path, family = "moss_image", params_backend = "cpu", tokenizer = tokenizer_path)
|
||||
vae = load_vae(vae_path, family = "moss_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, skip_layers = [22])
|
||||
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}
|
||||
}
|
||||
45
docs/dgl/moss_image/moss-image-sft-inline-images.dgl
Normal file
45
docs/dgl/moss_image/moss-image-sft-inline-images.dgl
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
# version: 0.0.0
|
||||
|
||||
var {
|
||||
weights = "MOSS-Image-SFT-Q8_0.gguf"
|
||||
encoder_path = "Qwen3.5-9B-Q4_K_M.gguf"
|
||||
vision_path = "Qwen3.5-9B-mmproj-BF16.gguf"
|
||||
tokenizer_path = "tokenizer_qwen3.5.json"
|
||||
vae_path = "flux2_ae.safetensors"
|
||||
|
||||
image_path = "subject.png"
|
||||
output_path = "moss-image-prompt.png"
|
||||
|
||||
prompt = "Draw the subject from <image:subject> in watercolor."
|
||||
negative_prompt = ""
|
||||
|
||||
seed = 42
|
||||
width = 1024
|
||||
height = 1024
|
||||
|
||||
steps = 20
|
||||
cfg_scale = 3
|
||||
}
|
||||
|
||||
fn main() {
|
||||
dit = load_dit(weights)
|
||||
encoder = load_text_encoder(encoder_path, family_from = weights,
|
||||
tokenizer = tokenizer_path, vision_path = vision_path)
|
||||
vae = load_vae(vae_path, family_from = weights)
|
||||
subject = image::load(image_path)
|
||||
positive = encode_prompt(encoder, prompt,
|
||||
image_bindings = {subject = subject}, width = width, height = height)
|
||||
negative = encode_prompt(encoder, negative_prompt, width = width, height = height)
|
||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
||||
rng = make_rng("cuda", seed = seed)
|
||||
noise = tensor::randn_like(base, rng = rng)
|
||||
positive_predictor = predictor(dit, positive)
|
||||
negative_predictor = predictor(dit, negative, skip_layers = [22])
|
||||
guided = cfg(positive_predictor, negative_predictor, scale = cfg_scale)
|
||||
sigmas = make_sigmas(guided, latent = base, steps = steps)
|
||||
start = add_noise(guided, base, noise, sigma = sigmas[0])
|
||||
latent = sample(start, sigmas, predict = guided, rng = rng)
|
||||
output = vae_decode(vae, dit_to_vae_latents(vae, latent))
|
||||
image::save(output_path, output)
|
||||
return output
|
||||
}
|
||||
44
docs/dgl/moss_image/moss-image-sft-txt2img.dgl
Normal file
44
docs/dgl/moss_image/moss-image-sft-txt2img.dgl
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/moss_image.md — MOSS-Image SFT
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/moss_image_sft_int8_convrot_attn.safetensors"
|
||||
text_path = "../models/text_encoders/Qwen3.5-9B-Q4_K_M.gguf"
|
||||
tokenizer_path = "../models/tokenizers/tokenizer_qwen3.5.json"
|
||||
vae_path = "../models/vae/flux2_ae.safetensors"
|
||||
|
||||
output_path = "output.png"
|
||||
|
||||
prompt = "a lovely cat holding a sign says 'moss-image.cpp'"
|
||||
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 = "moss_image", params_backend = "cpu")
|
||||
text = load_text_encoder(text_path, family = "moss_image", params_backend = "cpu", tokenizer = tokenizer_path)
|
||||
vae = load_vae(vae_path, family = "moss_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, skip_layers = [22])
|
||||
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}
|
||||
}
|
||||
43
docs/dgl/ovis_image/ovis-image-txt2img.dgl
Normal file
43
docs/dgl/ovis_image/ovis-image-txt2img.dgl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/ovis_image.md — CLI
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/ovis_image-Q4_0.gguf"
|
||||
text_path = "../models/text_encoders/ovis_2.5.safetensors"
|
||||
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 = 5.0
|
||||
method = "euler"
|
||||
scheduler = "flux"
|
||||
}
|
||||
|
||||
fn main() {
|
||||
model = load_dit(model_path, family = "ovis_image", params_backend = "cpu")
|
||||
text = load_text_encoder(text_path, family = "ovis_image", params_backend = "cpu")
|
||||
vae = load_vae(vae_path, family = "ovis_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}
|
||||
}
|
||||
71
docs/dgl/p_h3_image/p-h3-image-edit.dgl
Normal file
71
docs/dgl/p_h3_image/p-h3-image-edit.dgl
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/p_h3_image.md — Image editing
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/p-h3-image_int8_convrot.safetensors"
|
||||
text_path = "../models/text_encoders/qwen3vl_4b_bf16.safetensors"
|
||||
connectors_path = "../models/text_encoders/p-h3-image_text_connector.safetensors"
|
||||
vae_path = "../models/vae/p-h3-image_vae_bf16.safetensors"
|
||||
|
||||
reference_0_path = "source.png"
|
||||
reference_1_path = "reference.png"
|
||||
output_path = "output.png"
|
||||
|
||||
prompt = "Edit <Picture 1>. Give the cat the scarf from <Picture 2>, preserving its face and the background."
|
||||
|
||||
seed = 42
|
||||
rng_type = "cpu"
|
||||
width = 2912
|
||||
height = 2912
|
||||
|
||||
method = "euler"
|
||||
custom_sigmas = [1.0, 0.9847530126571655, 0.9679049849510193, 0.9516879916191101, 0.9253720045089722, 0.8819230198860168, 0.8100829720497131, 0.5287179946899414, 0.0]
|
||||
}
|
||||
|
||||
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)
|
||||
reference_1 = image::load(reference_1_path)
|
||||
|
||||
model = load_dit(model_path, family = "p_h3_image", params_backend = "cpu")
|
||||
text = load_text_encoder(text_path, connectors_path = connectors_path, family = "p_h3_image", params_backend = "cpu", projection_path = model_path)
|
||||
vae = load_vae(vae_path, family = "p_h3_image", params_backend = "cpu")
|
||||
|
||||
encode_rng = make_rng(rng_type, seed = seed)
|
||||
image_base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
||||
image_shape = tensor::shape(image_base)
|
||||
image_video = tensor::unsqueeze(image_base, axis = 2)
|
||||
audio_channels = math::ceil_div(128, image_shape[0] * image_shape[1])
|
||||
base = tensor::concat([image_video, tensor::zeros([image_shape[0], image_shape[1], 1, audio_channels, 1])], axis = 3)
|
||||
reference_0_original = image::to_f32(reference_0, channels = 3)
|
||||
reference_0_pixels = fit_reference_area(reference_0_original, math::min(width * height, tensor::shape(reference_0_original)[0] * tensor::shape(reference_0_original)[1]), 32, mode = "bilinear")
|
||||
reference_latent_0 = vae_to_dit_latents(vae, vae_encode(vae, reference_0_pixels, rng = encode_rng))
|
||||
reference_1_original = image::to_f32(reference_1, channels = 3)
|
||||
reference_1_pixels = fit_reference_area(reference_1_original, math::min(width * height, tensor::shape(reference_1_original)[0] * tensor::shape(reference_1_original)[1]), 32, mode = "bilinear")
|
||||
reference_latent_1 = vae_to_dit_latents(vae, vae_encode(vae, reference_1_pixels, rng = encode_rng))
|
||||
|
||||
condition = encode_prompt(text, prompt, width = width, height = height, media = [reference_0_original, reference_1_original])
|
||||
predict = predictor(model, condition, video_sigma_shift = 1, audio_length = 2, audio_sigma_shift = 1, reference_blocks = [{kind = "image", video = 0}, {kind = "image", video = 1}], ref_latents = [reference_latent_0, reference_latent_1], ref_index_mode = "increase")
|
||||
sigmas = tensor::vector(custom_sigmas, dtype = "f32")
|
||||
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[:, :, :, :24]))
|
||||
image::save(output_path, image)
|
||||
return {image = image, latent = latent}
|
||||
}
|
||||
43
docs/dgl/p_h3_image/p-h3-image-txt2img.dgl
Normal file
43
docs/dgl/p_h3_image/p-h3-image-txt2img.dgl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/p_h3_image.md — Text-to-image
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/p-h3-image_int8_convrot.safetensors"
|
||||
text_path = "../models/text_encoders/qwen3vl_4b_bf16.safetensors"
|
||||
connectors_path = "../models/text_encoders/p-h3-image_text_connector.safetensors"
|
||||
vae_path = "../models/vae/p-h3-image_vae_bf16.safetensors"
|
||||
|
||||
output_path = "output.png"
|
||||
|
||||
prompt = "a lovely cat holding a sign says 'p-h3-image.cpp'"
|
||||
|
||||
seed = 42
|
||||
rng_type = "cpu"
|
||||
width = 2912
|
||||
height = 2912
|
||||
|
||||
method = "euler"
|
||||
custom_sigmas = [1.0, 0.9847530126571655, 0.9679049849510193, 0.9516879916191101, 0.9253720045089722, 0.8819230198860168, 0.8100829720497131, 0.5287179946899414, 0.0]
|
||||
}
|
||||
|
||||
fn main() {
|
||||
model = load_dit(model_path, family = "p_h3_image", params_backend = "cpu")
|
||||
text = load_text_encoder(text_path, connectors_path = connectors_path, family = "p_h3_image", params_backend = "cpu", projection_path = model_path)
|
||||
vae = load_vae(vae_path, family = "p_h3_image", params_backend = "cpu")
|
||||
|
||||
image_base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
||||
image_shape = tensor::shape(image_base)
|
||||
image_video = tensor::unsqueeze(image_base, axis = 2)
|
||||
audio_channels = math::ceil_div(128, image_shape[0] * image_shape[1])
|
||||
base = tensor::concat([image_video, tensor::zeros([image_shape[0], image_shape[1], 1, audio_channels, 1])], axis = 3)
|
||||
|
||||
condition = encode_prompt(text, prompt, width = width, height = height)
|
||||
predict = predictor(model, condition, video_sigma_shift = 1, audio_length = 2, audio_sigma_shift = 1)
|
||||
sigmas = tensor::vector(custom_sigmas, dtype = "f32")
|
||||
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[:, :, :, :24]))
|
||||
image::save(output_path, image)
|
||||
return {image = image, latent = latent}
|
||||
}
|
||||
49
docs/dgl/photo_maker/photomaker-v1-sdxl.dgl
Normal file
49
docs/dgl/photo_maker/photomaker-v1-sdxl.dgl
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/photo_maker.md — PhotoMaker Version 1
|
||||
|
||||
var {
|
||||
weights = "../models/checkpoints/sdxlUnstableDiffusers_v11.safetensors"
|
||||
model_path = "../models/photomaker/photomaker-v1.safetensors"
|
||||
vae_path = "../models/vae/sdxl_vae.safetensors"
|
||||
|
||||
image_dir = "../inputs/photomaker_examples/scarletthead_woman"
|
||||
output_path = "output.png"
|
||||
|
||||
prompt = "a girl img, retro futurism, retro game art style but extremely beautiful, intricate details, masterpiece, best quality, space-themed, cosmic, celestial, stars, galaxies, nebulas, planets, science fiction, highly detailed"
|
||||
negative_prompt = "realistic, photo-realistic, worst quality, greyscale, bad anatomy, bad hands, error, text"
|
||||
|
||||
seed = 42
|
||||
width = 1024
|
||||
height = 1024
|
||||
|
||||
steps = 50
|
||||
cfg_scale = 5.0
|
||||
method = "euler"
|
||||
scheduler = "discrete"
|
||||
style_strength = 10.0
|
||||
}
|
||||
|
||||
fn main() {
|
||||
base_unet = load_unet(weights)
|
||||
text = load_text_encoder(weights)
|
||||
vae = load_vae(vae_path, conv_scale = 0.03125, backend = "cpu")
|
||||
photomaker = photomaker::load(model_path, family = "sdxl")
|
||||
photomaker_lora = load_lora(model_path)
|
||||
unet = apply_lora(base_unet, photomaker_lora)
|
||||
tokens = photomaker::encode_images(photomaker, image::load_dir(image_dir))
|
||||
conditions = photomaker::encode_prompt(text, prompt, tokens, width = width, height = height)
|
||||
identity = photomaker::apply(conditions.condition, photomaker, tokens, conditions.mask)
|
||||
plain_predictor = predictor(unet, conditions.plain)
|
||||
identity_predictor = predictor(unet, identity)
|
||||
pos = switch_predictor(plain_predictor, identity_predictor, after_steps = math::floor(steps * style_strength / 100))
|
||||
neg = predictor(unet, encode_prompt(text, negative_prompt, width = width, height = height))
|
||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
||||
guided = cfg(pos, neg, scale = cfg_scale)
|
||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
||||
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, identity = identity }
|
||||
}
|
||||
52
docs/dgl/photo_maker/photomaker-v2-sdxl.dgl
Normal file
52
docs/dgl/photo_maker/photomaker-v2-sdxl.dgl
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/photo_maker.md — PhotoMaker Version 2
|
||||
|
||||
var {
|
||||
weights = "../models/checkpoints/sdxlUnstableDiffusers_v11.safetensors"
|
||||
model_path = "../models/photomaker/photomaker-v2.safetensors"
|
||||
vae_path = "../models/vae/sdxl_vae.safetensors"
|
||||
|
||||
image_dir = "../inputs/photomaker_examples/scarletthead_woman"
|
||||
embedding_path = "../inputs/photomaker_examples/scarletthead_woman/id_embeds.npy"
|
||||
output_path = "output.png"
|
||||
|
||||
prompt = "a girl img, retro futurism, retro game art style but extremely beautiful, intricate details, masterpiece, best quality, space-themed, cosmic, celestial, stars, galaxies, nebulas, planets, science fiction, highly detailed"
|
||||
negative_prompt = "realistic, photo-realistic, worst quality, greyscale, bad anatomy, bad hands, error, text"
|
||||
|
||||
seed = 42
|
||||
width = 1024
|
||||
height = 1024
|
||||
|
||||
steps = 50
|
||||
cfg_scale = 5.0
|
||||
method = "euler"
|
||||
scheduler = "discrete"
|
||||
style_strength = 10.0
|
||||
}
|
||||
|
||||
fn main() {
|
||||
base_unet = load_unet(weights)
|
||||
text = load_text_encoder(weights)
|
||||
vae = load_vae(vae_path, conv_scale = 0.03125, backend = "cpu")
|
||||
photomaker = photomaker::load(model_path, family = "sdxl")
|
||||
images = image::load_dir(image_dir)
|
||||
identity = tensor::load(embedding_path)
|
||||
photomaker_lora = load_lora(model_path)
|
||||
unet = apply_lora(base_unet, photomaker_lora)
|
||||
tokens = photomaker::encode_images(photomaker, images, id_embedding = identity)
|
||||
conditions = photomaker::encode_prompt(text, prompt, tokens, width = width, height = height)
|
||||
fused = photomaker::apply(conditions.condition, photomaker, tokens, conditions.mask)
|
||||
plain_predictor = predictor(unet, conditions.plain)
|
||||
identity_predictor = predictor(unet, fused)
|
||||
pos = switch_predictor(plain_predictor, identity_predictor, after_steps = math::floor(steps * style_strength / 100))
|
||||
neg = predictor(unet, encode_prompt(text, negative_prompt, width = width, height = height))
|
||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
||||
guided = cfg(pos, neg, scale = cfg_scale)
|
||||
sigmas = make_sigmas(guided, latent = base, steps = steps, scheduler = scheduler)
|
||||
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)
|
||||
output = vae_decode(vae, unet_to_vae_latents(vae, latent))
|
||||
image::save(output_path, output)
|
||||
return output
|
||||
}
|
||||
47
docs/dgl/pid/pid-flux1-512-to-2048-txt2img.dgl
Normal file
47
docs/dgl/pid/pid-flux1-512-to-2048-txt2img.dgl
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/pid.md — CLI
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/pid_flux1_512_to_2048_4step_bf16.safetensors"
|
||||
text_path = "../models/text_encoders/gemma_2_2b_it_elm_bf16.safetensors"
|
||||
tokenizer_path = "../models/tokenizers/tokenizer_gemma2.json"
|
||||
vae_path = "../models/vae/ae.sft"
|
||||
|
||||
reference_0_path = "../inputs/ernie_image/turbo_example.png"
|
||||
output_path = "output.png"
|
||||
|
||||
prompt = "a lovely cat"
|
||||
|
||||
seed = 42
|
||||
rng_type = "cpu"
|
||||
width = 2048
|
||||
height = 2048
|
||||
|
||||
steps = 4
|
||||
method = "lcm"
|
||||
scheduler = "lcm"
|
||||
}
|
||||
|
||||
fn main() {
|
||||
reference_0 = image::load(reference_0_path)
|
||||
|
||||
model = load_dit(model_path, family = "pid")
|
||||
text = load_text_encoder(text_path, family = "pid", tokenizer = tokenizer_path)
|
||||
vae = load_vae(vae_path, family = "pid", vae_format = "flux")
|
||||
|
||||
encode_rng = make_rng(rng_type, seed = seed)
|
||||
base = tensor::zeros([width, height, 3, 1])
|
||||
reference_0_pixels = image::to_f32(reference_0, channels = 3)
|
||||
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)
|
||||
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}
|
||||
}
|
||||
43
docs/dgl/pixart/pixart-sigma-xl2-1024-ms-txt2img.dgl
Normal file
43
docs/dgl/pixart/pixart-sigma-xl2-1024-ms-txt2img.dgl
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/pixart.md — CLI
|
||||
|
||||
var {
|
||||
model_path = "../models/diffusion_models/pixart_sigma_xl2_1024_ms.safetensors"
|
||||
text_path = "../models/text_encoders/t5xxl.safetensors"
|
||||
vae_path = "../models/vae/pixart_vae.safetensors"
|
||||
|
||||
output_path = "output.png"
|
||||
|
||||
prompt = "a lovely cat"
|
||||
negative_prompt = ""
|
||||
|
||||
seed = 42
|
||||
rng_type = "cuda"
|
||||
width = 1024
|
||||
height = 1024
|
||||
|
||||
steps = 20
|
||||
cfg_scale = 4.5
|
||||
method = "euler"
|
||||
scheduler = "discrete"
|
||||
}
|
||||
|
||||
fn main() {
|
||||
model = load_dit(model_path, family = "pixart")
|
||||
text = load_text_encoder(text_path, family = "pixart", t5_path = text_path)
|
||||
vae = load_vae(vae_path, family = "pixart")
|
||||
|
||||
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}
|
||||
}
|
||||
41
docs/dgl/pulid/pulid-flux1-schnell.dgl
Normal file
41
docs/dgl/pulid/pulid-flux1-schnell.dgl
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# version: 0.0.0
|
||||
# docs/models/pulid.md — CLI
|
||||
|
||||
var {
|
||||
dit_path = "../models/diffusion_models/flux1-schnell-Q4_K_S.gguf"
|
||||
pulid_path = "../models/pulid/pulid_flux_v0.9.1.safetensors"
|
||||
encoder_path = "../models/text_encoders/t5xxl_fp16.safetensors"
|
||||
clip_l_path = "../models/text_encoders/clip_l.safetensors"
|
||||
vae_path = "../models/vae/ae.safetensors"
|
||||
|
||||
identity_path = "../inputs/source.pulidembd"
|
||||
output_path = "out.png"
|
||||
|
||||
prompt = "candid photograph of a young woman on a beach at sunset"
|
||||
|
||||
seed = 42
|
||||
width = 512
|
||||
height = 512
|
||||
|
||||
steps = 4
|
||||
method = "euler"
|
||||
scheduler = "flux"
|
||||
}
|
||||
|
||||
fn main() {
|
||||
dit = load_dit(dit_path)
|
||||
pulid = pulid::load(pulid_path)
|
||||
text = load_text_encoder(encoder_path, family = "flux", clip_l_path = clip_l_path, backend = "cpu")
|
||||
vae = load_vae(vae_path, family = "flux")
|
||||
identity = pulid::load_embedding(identity_path)
|
||||
condition = pulid::apply(encode_prompt(text, prompt), pulid, identity, strength = 1.0)
|
||||
predict = predictor(dit, condition)
|
||||
base = tensor::zeros(latent_shape(vae, width = width, height = height))
|
||||
sigmas = make_sigmas(predict, latent = base, scheduler = scheduler, steps = steps)
|
||||
rng = make_rng("cuda", 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 }
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue