Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ endif()
#

# general
#option(SD_BUILD_TESTS "sd: build tests" ${SD_STANDALONE})
option(SD_BUILD_TESTS "sd: build tests" OFF)
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)
Expand Down Expand Up @@ -340,6 +340,11 @@ if (SD_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

if (SD_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()

set(SD_PUBLIC_HEADERS include/stable-diffusion.h)
set_target_properties(${SD_LIB} PROPERTIES PUBLIC_HEADER "${SD_PUBLIC_HEADERS}")

Expand Down
33 changes: 32 additions & 1 deletion examples/common/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,14 @@ ArgOptions SDGenerationParams::get_options() {
"--vace-strength",
"wan vace strength",
&vace_strength},
{"",
"--reference-attention-strength",
"LTX IC-LoRA reference conditioning strength in [0, 1] (default: 1.0)",
&reference_attention_strength},
{"",
"--reference-downscale-factor",
"LTX IC-LoRA reference image downscale factor (currently must be 1.0; default: 1.0)",
&reference_downscale_factor},
{"",
"--vae-tile-overlap",
"tile overlap for vae tiling, in fraction of tile size (default: 0.5)",
Expand Down Expand Up @@ -1366,7 +1374,7 @@ ArgOptions SDGenerationParams::get_options() {
on_high_noise_skip_layers_arg},
{"-r",
"--ref-image",
"reference image for Flux Kontext models (can be used multiple times)",
"reference image for Flux Kontext or LTX IC-LoRA video models (can be used multiple times)",
on_ref_image_arg},
{"",
"--cache-mode",
Expand Down Expand Up @@ -2141,6 +2149,17 @@ bool SDGenerationParams::validate(SDMode mode) {
return false;
}

if (mode == VID_GEN && !ref_image_paths.empty()) {
if (reference_attention_strength < 0.f || reference_attention_strength > 1.f) {
LOG_ERROR("error: reference attention strength must be in [0, 1]");
return false;
}
if (reference_downscale_factor != 1.f) {
LOG_ERROR("error: LTX IC-LoRA currently requires reference downscale factor to be 1");
return false;
}
}

if (sample_params.shifted_timestep < 0 || sample_params.shifted_timestep > 1000) {
LOG_ERROR("error: shifted_timestep must be in range [0, 1000]");
return false;
Expand Down Expand Up @@ -2303,6 +2322,12 @@ sd_vid_gen_params_t SDGenerationParams::to_sd_vid_gen_params_t() {
control_frame_views.push_back(frame.get());
}

ref_image_views.clear();
ref_image_views.reserve(ref_images.size());
for (auto& ref_image : ref_images) {
ref_image_views.push_back(ref_image.get());
}

sample_params.guidance.slg.layers = skip_layers.empty() ? nullptr : skip_layers.data();
sample_params.guidance.slg.layer_count = skip_layers.size();
high_noise_sample_params.guidance.slg.layers = high_noise_skip_layers.empty() ? nullptr : high_noise_skip_layers.data();
Expand All @@ -2323,6 +2348,10 @@ sd_vid_gen_params_t SDGenerationParams::to_sd_vid_gen_params_t() {
params.end_image = end_image.get();
params.control_frames = control_frame_views.empty() ? nullptr : control_frame_views.data();
params.control_frames_size = static_cast<int>(control_frame_views.size());
params.reference_images = ref_image_views.empty() ? nullptr : ref_image_views.data();
params.reference_images_count = static_cast<int>(ref_image_views.size());
params.reference_attention_strength = reference_attention_strength;
params.reference_downscale_factor = reference_downscale_factor;
params.width = get_resolved_width();
params.height = get_resolved_height();
params.sample_params = sample_params;
Expand Down Expand Up @@ -2415,6 +2444,8 @@ std::string SDGenerationParams::to_string() const {
<< " video_frames: " << video_frames << ",\n"
<< " fps: " << fps << ",\n"
<< " vace_strength: " << vace_strength << ",\n"
<< " reference_attention_strength: " << reference_attention_strength << ",\n"
<< " reference_downscale_factor: " << reference_downscale_factor << ",\n"
<< " strength: " << strength << ",\n"
<< " control_strength: " << control_strength << ",\n"
<< " seed: " << seed << ",\n"
Expand Down
2 changes: 2 additions & 0 deletions examples/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ struct SDGenerationParams {
int video_frames = 1;
int fps = 16;
float vace_strength = 1.f;
float reference_attention_strength = 1.f;
float reference_downscale_factor = 1.f;
sd_tiling_params_t vae_tiling_params = {false, false, 0, 0, 0.5f, 0.0f, 0.0f, nullptr};
std::string extra_tiling_args;

Expand Down
11 changes: 11 additions & 0 deletions include/stable-diffusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,17 @@ typedef struct {
sd_tiling_params_t vae_tiling_params;
sd_cache_params_t cache;
sd_hires_params_t hires;
// LTX IC-LoRA reference conditioning. These fields are ignored for
// non-LTX video models. Each input is a reference sheet/image that is
// expanded into a static reference video before VAE encoding.
sd_image_t* reference_images;
int reference_images_count;
// [0, 1]. Zero disables the reference tokens; one preserves their full
// conditioning weight. Defaults are set by sd_vid_gen_params_init().
float reference_attention_strength;
// The current LTX Ingredients workflow requires 1.0. Values other than
// one are rejected until a spatial downscale implementation is added.
float reference_downscale_factor;
} sd_vid_gen_params_t;

typedef struct sd_ctx_t sd_ctx_t;
Expand Down
1 change: 1 addition & 0 deletions src/diffusion_model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct LTXAVDiffusionExtra {
int audio_length = 0;
float frame_rate = 24.f;
const sd::Tensor<float>* video_positions = nullptr;
const std::vector<int>* skip_video_self_attention_blocks = nullptr;
};

using DiffusionExtraParams = std::variant<std::monostate,
Expand Down
Loading
Loading