Skip to content

Commit e047457

Browse files
committed
add reset param to ucache
1 parent 9f053d2 commit e047457

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
@@ -1484,7 +1484,7 @@ struct SDGenerationParams {
14841484
on_cache_mode_arg},
14851485
{"",
14861486
"--cache-option",
1487-
"named cache params: easycache/ucache: threshold=,start=,end=,decay=,relative= | cache-dit: Fn=,Bn=,threshold=,warmup=",
1487+
"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\"",
14881488
on_cache_option_arg},
14891489
{"",
14901490
"--scm-mask",
@@ -1659,6 +1659,8 @@ struct SDGenerationParams {
16591659
cache_params.error_decay_rate = std::stof(val);
16601660
} else if (key == "relative") {
16611661
cache_params.use_relative_threshold = (std::stof(val) != 0.0f);
1662+
} else if (key == "reset") {
1663+
cache_params.reset_error_on_compute = (std::stof(val) != 0.0f);
16621664
} else if (key == "Fn" || key == "fn") {
16631665
cache_params.Fn_compute_blocks = std::stoi(val);
16641666
} else if (key == "Bn" || key == "bn") {
@@ -1684,13 +1686,15 @@ struct SDGenerationParams {
16841686
cache_params.end_percent = 0.95f;
16851687
cache_params.error_decay_rate = 1.0f;
16861688
cache_params.use_relative_threshold = true;
1689+
cache_params.reset_error_on_compute = true;
16871690
} else if (cache_mode == "ucache") {
16881691
cache_params.mode = SD_CACHE_UCACHE;
16891692
cache_params.reuse_threshold = 1.0f;
16901693
cache_params.start_percent = 0.15f;
16911694
cache_params.end_percent = 0.95f;
16921695
cache_params.error_decay_rate = 1.0f;
16931696
cache_params.use_relative_threshold = true;
1697+
cache_params.reset_error_on_compute = true;
16941698
} else if (cache_mode == "dbcache") {
16951699
cache_params.mode = SD_CACHE_DBCACHE;
16961700
cache_params.Fn_compute_blocks = 8;

stable-diffusion.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,15 +1548,17 @@ class StableDiffusionGGML {
15481548
ucache_config.end_percent = cache_params->end_percent;
15491549
ucache_config.error_decay_rate = std::max(0.0f, std::min(1.0f, cache_params->error_decay_rate));
15501550
ucache_config.use_relative_threshold = cache_params->use_relative_threshold;
1551+
ucache_config.reset_error_on_compute = cache_params->reset_error_on_compute;
15511552
ucache_state.init(ucache_config, denoiser.get());
15521553
if (ucache_state.enabled()) {
15531554
ucache_enabled = true;
1554-
LOG_INFO("UCache enabled - threshold: %.3f, start: %.2f, end: %.2f, decay: %.2f, relative: %s",
1555+
LOG_INFO("UCache enabled - threshold: %.3f, start: %.2f, end: %.2f, decay: %.2f, relative: %s, reset: %s",
15551556
ucache_config.reuse_threshold,
15561557
ucache_config.start_percent,
15571558
ucache_config.end_percent,
15581559
ucache_config.error_decay_rate,
1559-
ucache_config.use_relative_threshold ? "true" : "false");
1560+
ucache_config.use_relative_threshold ? "true" : "false",
1561+
ucache_config.reset_error_on_compute ? "true" : "false");
15601562
} else {
15611563
LOG_WARN("UCache requested but could not be initialized for this run");
15621564
}
@@ -2696,6 +2698,7 @@ void sd_cache_params_init(sd_cache_params_t* cache_params) {
26962698
cache_params->end_percent = 0.95f;
26972699
cache_params->error_decay_rate = 1.0f;
26982700
cache_params->use_relative_threshold = true;
2701+
cache_params->reset_error_on_compute = true;
26992702
cache_params->Fn_compute_blocks = 8;
27002703
cache_params->Bn_compute_blocks = 0;
27012704
cache_params->residual_diff_threshold = 0.08f;

stable-diffusion.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ typedef struct {
250250
float end_percent;
251251
float error_decay_rate;
252252
bool use_relative_threshold;
253+
bool reset_error_on_compute;
253254
int Fn_compute_blocks;
254255
int Bn_compute_blocks;
255256
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)