1- #include < vector>
2- #include < unordered_map>
3- #include < limits>
41#include < cmath>
2+ #include < limits>
3+ #include < unordered_map>
4+ #include < vector>
55
6- #include " ggml_extend.hpp"
76#include " denoiser.hpp"
7+ #include " ggml_extend.hpp"
88
99struct EasyCacheConfig {
1010 bool enabled = false ;
@@ -19,48 +19,48 @@ struct EasyCacheCacheEntry {
1919
2020struct EasyCacheState {
2121 EasyCacheConfig config;
22- Denoiser* denoiser = nullptr ;
23- float start_sigma = std::numeric_limits<float >::max();
24- float end_sigma = 0 .0f ;
25- bool initialized = false ;
26- bool initial_step = true ;
27- bool skip_current_step = false ;
28- bool step_active = false ;
22+ Denoiser* denoiser = nullptr ;
23+ float start_sigma = std::numeric_limits<float >::max();
24+ float end_sigma = 0 .0f ;
25+ bool initialized = false ;
26+ bool initial_step = true ;
27+ bool skip_current_step = false ;
28+ bool step_active = false ;
2929 const SDCondition* anchor_condition = nullptr ;
3030 std::unordered_map<const SDCondition*, EasyCacheCacheEntry> cache_diffs;
3131 std::vector<float > prev_input;
3232 std::vector<float > prev_output;
33- float output_prev_norm = 0 .0f ;
34- bool has_prev_input = false ;
35- bool has_prev_output = false ;
36- bool has_output_prev_norm = false ;
37- bool has_relative_transformation_rate = false ;
38- float relative_transformation_rate = 0 .0f ;
39- float cumulative_change_rate = 0 .0f ;
40- float last_input_change = 0 .0f ;
41- bool has_last_input_change = false ;
42- int total_steps_skipped = 0 ;
43- int current_step_index = -1 ;
33+ float output_prev_norm = 0 .0f ;
34+ bool has_prev_input = false ;
35+ bool has_prev_output = false ;
36+ bool has_output_prev_norm = false ;
37+ bool has_relative_transformation_rate = false ;
38+ float relative_transformation_rate = 0 .0f ;
39+ float cumulative_change_rate = 0 .0f ;
40+ float last_input_change = 0 .0f ;
41+ bool has_last_input_change = false ;
42+ int total_steps_skipped = 0 ;
43+ int current_step_index = -1 ;
4444
4545 void reset_runtime () {
46- initial_step = true ;
47- skip_current_step = false ;
48- step_active = false ;
49- anchor_condition = nullptr ;
46+ initial_step = true ;
47+ skip_current_step = false ;
48+ step_active = false ;
49+ anchor_condition = nullptr ;
5050 cache_diffs.clear ();
5151 prev_input.clear ();
5252 prev_output.clear ();
53- output_prev_norm = 0 .0f ;
54- has_prev_input = false ;
55- has_prev_output = false ;
56- has_output_prev_norm = false ;
53+ output_prev_norm = 0 .0f ;
54+ has_prev_input = false ;
55+ has_prev_output = false ;
56+ has_output_prev_norm = false ;
5757 has_relative_transformation_rate = false ;
58- relative_transformation_rate = 0 .0f ;
59- cumulative_change_rate = 0 .0f ;
60- last_input_change = 0 .0f ;
61- has_last_input_change = false ;
62- total_steps_skipped = 0 ;
63- current_step_index = -1 ;
58+ relative_transformation_rate = 0 .0f ;
59+ cumulative_change_rate = 0 .0f ;
60+ last_input_change = 0 .0f ;
61+ has_last_input_change = false ;
62+ total_steps_skipped = 0 ;
63+ current_step_index = -1 ;
6464 }
6565
6666 void init (const EasyCacheConfig& cfg, Denoiser* d) {
@@ -99,10 +99,10 @@ struct EasyCacheState {
9999 if (step_index == current_step_index) {
100100 return ;
101101 }
102- current_step_index = step_index;
103- skip_current_step = false ;
102+ current_step_index = step_index;
103+ skip_current_step = false ;
104104 has_last_input_change = false ;
105- step_active = false ;
105+ step_active = false ;
106106 if (sigma > start_sigma) {
107107 return ;
108108 }
@@ -142,7 +142,7 @@ struct EasyCacheState {
142142 return ;
143143 }
144144 copy_ggml_tensor (output, input);
145- float * out_data = (float *)output->data ;
145+ float * out_data = (float *)output->data ;
146146 const std::vector<float >& diff = it->second .diff ;
147147 for (size_t i = 0 ; i < diff.size (); ++i) {
148148 out_data[i] += diff[i];
@@ -220,15 +220,15 @@ struct EasyCacheState {
220220 return ;
221221 }
222222
223- size_t ne = static_cast <size_t >(ggml_nelements (input));
224- float * in_data = (float *)input->data ;
223+ size_t ne = static_cast <size_t >(ggml_nelements (input));
224+ float * in_data = (float *)input->data ;
225225 prev_input.resize (ne);
226226 for (size_t i = 0 ; i < ne; ++i) {
227227 prev_input[i] = in_data[i];
228228 }
229229 has_prev_input = true ;
230230
231- float * out_data = (float *)output->data ;
231+ float * out_data = (float *)output->data ;
232232 float output_change = 0 .0f ;
233233 if (has_prev_output && prev_output.size () == ne) {
234234 for (size_t i = 0 ; i < ne; ++i) {
@@ -249,13 +249,13 @@ struct EasyCacheState {
249249 for (size_t i = 0 ; i < ne; ++i) {
250250 mean_abs += std::fabs (out_data[i]);
251251 }
252- output_prev_norm = (ne > 0 ) ? (mean_abs / static_cast <float >(ne)) : 0 .0f ;
253- has_output_prev_norm = output_prev_norm > 0 .0f ;
252+ output_prev_norm = (ne > 0 ) ? (mean_abs / static_cast <float >(ne)) : 0 .0f ;
253+ has_output_prev_norm = output_prev_norm > 0 .0f ;
254254
255255 if (has_last_input_change && last_input_change > 0 .0f && output_change > 0 .0f ) {
256256 float rate = output_change / last_input_change;
257257 if (std::isfinite (rate)) {
258- relative_transformation_rate = rate;
258+ relative_transformation_rate = rate;
259259 has_relative_transformation_rate = true ;
260260 }
261261 }
0 commit comments