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
68 changes: 68 additions & 0 deletions examples/cli/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ struct SDParams {
std::vector<int> high_noise_skip_layers = {7, 8, 9};
sd_sample_params_t high_noise_sample_params;

std::string easycache_option;
sd_easycache_params_t easycache_params;

float moe_boundary = 0.875f;
int video_frames = 1;
int fps = 16;
Expand Down Expand Up @@ -139,6 +142,7 @@ struct SDParams {
sd_sample_params_init(&sample_params);
sd_sample_params_init(&high_noise_sample_params);
high_noise_sample_params.sample_steps = -1;
sd_easycache_params_init(&easycache_params);
}
};

Expand Down Expand Up @@ -208,6 +212,11 @@ void print_params(SDParams params) {
printf(" chroma_use_t5_mask: %s\n", params.chroma_use_t5_mask ? "true" : "false");
printf(" chroma_t5_mask_pad: %d\n", params.chroma_t5_mask_pad);
printf(" video_frames: %d\n", params.video_frames);
printf(" easycache: %s (threshold=%.3f, start=%.2f, end=%.2f)\n",
params.easycache_params.enabled ? "enabled" : "disabled",
params.easycache_params.reuse_threshold,
params.easycache_params.start_percent,
params.easycache_params.end_percent);
printf(" vace_strength: %.2f\n", params.vace_strength);
printf(" fps: %d\n", params.fps);
free(sample_params_str);
Expand Down Expand Up @@ -593,6 +602,10 @@ void parse_args(int argc, const char** argv, SDParams& params) {
"--upscale-model",
"path to esrgan model.",
&params.esrgan_path},
{"",
"--easycache",
"enable EasyCache for DiT models with \"threshold,start_percent,end_percent\" (example: 0.2,0.15,0.95)",
&params.easycache_option},
};

options.int_options = {
Expand Down Expand Up @@ -1117,6 +1130,59 @@ void parse_args(int argc, const char** argv, SDParams& params) {
exit(1);
}

if (!params.easycache_option.empty()) {
float values[3] = {0.0f, 0.0f, 0.0f};
std::stringstream ss(params.easycache_option);
std::string token;
int idx = 0;
while (std::getline(ss, token, ',')) {
auto trim = [](std::string& s) {
const char* whitespace = " \t\r\n";
auto start = s.find_first_not_of(whitespace);
if (start == std::string::npos) {
s.clear();
return;
}
auto end = s.find_last_not_of(whitespace);
s = s.substr(start, end - start + 1);
};
trim(token);
if (token.empty()) {
fprintf(stderr, "error: invalid easycache option '%s'\n", params.easycache_option.c_str());
exit(1);
}
if (idx >= 3) {
fprintf(stderr, "error: easycache expects exactly 3 comma-separated values (threshold,start,end)\n");
exit(1);
}
try {
values[idx] = std::stof(token);
} catch (const std::exception&) {
fprintf(stderr, "error: invalid easycache value '%s'\n", token.c_str());
exit(1);
}
idx++;
}
if (idx != 3) {
fprintf(stderr, "error: easycache expects exactly 3 comma-separated values (threshold,start,end)\n");
exit(1);
}
if (values[0] < 0.0f) {
fprintf(stderr, "error: easycache threshold must be non-negative\n");
exit(1);
}
if (values[1] < 0.0f || values[1] >= 1.0f || values[2] <= 0.0f || values[2] > 1.0f || values[1] >= values[2]) {
fprintf(stderr, "error: easycache start/end percents must satisfy 0.0 <= start < end <= 1.0\n");
exit(1);
}
params.easycache_params.enabled = true;
params.easycache_params.reuse_threshold = values[0];
params.easycache_params.start_percent = values[1];
params.easycache_params.end_percent = values[2];
} else {
params.easycache_params.enabled = false;
}

if (params.n_threads <= 0) {
params.n_threads = get_num_physical_cores();
}
Expand Down Expand Up @@ -1716,6 +1782,7 @@ int main(int argc, const char* argv[]) {
params.pm_style_strength,
}, // pm_params
params.vae_tiling_params,
params.easycache_params,
};

results = generate_image(sd_ctx, &img_gen_params);
Expand All @@ -1738,6 +1805,7 @@ int main(int argc, const char* argv[]) {
params.seed,
params.video_frames,
params.vace_strength,
params.easycache_params,
};

results = generate_video(sd_ctx, &vid_gen_params, &num_results);
Expand Down
Loading
Loading