Skip to content

Commit c6f0e22

Browse files
committed
add reset param to ucache
1 parent f04166f commit c6f0e22

File tree

4 files changed

+14
-3
lines changed

4 files changed

+14
-3
lines changed

examples/cli/main.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,7 @@ struct SDGenerationParams {
14771477
on_cache_mode_arg},
14781478
{"",
14791479
"--cache-option",
1480-
"named cache params: easycache/ucache: threshold=,start=,end=,decay=,relative= | cache-dit: Fn=,Bn=,threshold=,warmup=",
1480+
"named cache params (key=value format, comma-separated):\n - easycache/ucache: threshold=,start=,end=,decay=,relative=,reset=\n - dbcache/taylorseer/cache-dit: Fn=,Bn=,threshold=,warmup=\n Examples: \"threshold=0.25\" or \"threshold=1.5,reset=0\"",
14811481
on_cache_option_arg},
14821482
{"",
14831483
"--scm-mask",
@@ -1652,6 +1652,8 @@ struct SDGenerationParams {
16521652
cache_params.error_decay_rate = std::stof(val);
16531653
} else if (key == "relative") {
16541654
cache_params.use_relative_threshold = (std::stof(val) != 0.0f);
1655+
} else if (key == "reset") {
1656+
cache_params.reset_error_on_compute = (std::stof(val) != 0.0f);
16551657
} else if (key == "Fn" || key == "fn") {
16561658
cache_params.Fn_compute_blocks = std::stoi(val);
16571659
} else if (key == "Bn" || key == "bn") {
@@ -1677,13 +1679,15 @@ struct SDGenerationParams {
16771679
cache_params.end_percent = 0.95f;
16781680
cache_params.error_decay_rate = 1.0f;
16791681
cache_params.use_relative_threshold = true;
1682+
cache_params.reset_error_on_compute = true;
16801683
} else if (cache_mode == "ucache") {
16811684
cache_params.mode = SD_CACHE_UCACHE;
16821685
cache_params.reuse_threshold = 1.0f;
16831686
cache_params.start_percent = 0.15f;
16841687
cache_params.end_percent = 0.95f;
16851688
cache_params.error_decay_rate = 1.0f;
16861689
cache_params.use_relative_threshold = true;
1690+
cache_params.reset_error_on_compute = true;
16871691
} else if (cache_mode == "dbcache") {
16881692
cache_params.mode = SD_CACHE_DBCACHE;
16891693
cache_params.Fn_compute_blocks = 8;

stable-diffusion.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,15 +1558,17 @@ class StableDiffusionGGML {
15581558
ucache_config.end_percent = cache_params->end_percent;
15591559
ucache_config.error_decay_rate = std::max(0.0f, std::min(1.0f, cache_params->error_decay_rate));
15601560
ucache_config.use_relative_threshold = cache_params->use_relative_threshold;
1561+
ucache_config.reset_error_on_compute = cache_params->reset_error_on_compute;
15611562
ucache_state.init(ucache_config, denoiser.get());
15621563
if (ucache_state.enabled()) {
15631564
ucache_enabled = true;
1564-
LOG_INFO("UCache enabled - threshold: %.3f, start: %.2f, end: %.2f, decay: %.2f, relative: %s",
1565+
LOG_INFO("UCache enabled - threshold: %.3f, start: %.2f, end: %.2f, decay: %.2f, relative: %s, reset: %s",
15651566
ucache_config.reuse_threshold,
15661567
ucache_config.start_percent,
15671568
ucache_config.end_percent,
15681569
ucache_config.error_decay_rate,
1569-
ucache_config.use_relative_threshold ? "true" : "false");
1570+
ucache_config.use_relative_threshold ? "true" : "false",
1571+
ucache_config.reset_error_on_compute ? "true" : "false");
15701572
} else {
15711573
LOG_WARN("UCache requested but could not be initialized for this run");
15721574
}
@@ -2718,6 +2720,7 @@ void sd_cache_params_init(sd_cache_params_t* cache_params) {
27182720
cache_params->end_percent = 0.95f;
27192721
cache_params->error_decay_rate = 1.0f;
27202722
cache_params->use_relative_threshold = true;
2723+
cache_params->reset_error_on_compute = true;
27212724
cache_params->Fn_compute_blocks = 8;
27222725
cache_params->Bn_compute_blocks = 0;
27232726
cache_params->residual_diff_threshold = 0.08f;

stable-diffusion.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ typedef struct {
251251
float end_percent;
252252
float error_decay_rate;
253253
bool use_relative_threshold;
254+
bool reset_error_on_compute;
254255
int Fn_compute_blocks;
255256
int Bn_compute_blocks;
256257
float residual_diff_threshold;

ucache.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct UCacheConfig {
1919
bool adaptive_threshold = true;
2020
float early_step_multiplier = 0.5f;
2121
float late_step_multiplier = 1.5f;
22+
bool reset_error_on_compute = true;
2223
};
2324

2425
struct UCacheCacheEntry {
@@ -319,6 +320,8 @@ struct UCacheState {
319320
total_steps_skipped++;
320321
apply_cache(cond, input, output);
321322
return true;
323+
} else if (config.reset_error_on_compute) {
324+
accumulated_error = 0.0f;
322325
}
323326
}
324327

0 commit comments

Comments
 (0)