Skip to content

Commit d226a37

Browse files
committed
format code
1 parent 2c186cb commit d226a37

File tree

3 files changed

+68
-68
lines changed

3 files changed

+68
-68
lines changed

easycache.hpp

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
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

99
struct EasyCacheConfig {
1010
bool enabled = false;
@@ -19,48 +19,48 @@ struct EasyCacheCacheEntry {
1919

2020
struct 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
}

examples/cli/main.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,7 +1140,7 @@ void parse_args(int argc, const char** argv, SDParams& params) {
11401140

11411141
auto on_easycache_arg = [&](int argc, const char** argv, int index) {
11421142
const std::string default_values = "0.2,0.15,0.95";
1143-
auto looks_like_value = [](const std::string& token) {
1143+
auto looks_like_value = [](const std::string& token) {
11441144
if (token.empty()) {
11451145
return false;
11461146
}
@@ -1269,13 +1269,13 @@ void parse_args(int argc, const char** argv, SDParams& params) {
12691269
while (std::getline(ss, token, ',')) {
12701270
auto trim = [](std::string& s) {
12711271
const char* whitespace = " \t\r\n";
1272-
auto start = s.find_first_not_of(whitespace);
1272+
auto start = s.find_first_not_of(whitespace);
12731273
if (start == std::string::npos) {
12741274
s.clear();
12751275
return;
12761276
}
12771277
auto end = s.find_last_not_of(whitespace);
1278-
s = s.substr(start, end - start + 1);
1278+
s = s.substr(start, end - start + 1);
12791279
};
12801280
trim(token);
12811281
if (token.empty()) {

stable-diffusion.cpp

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
#include "control.hpp"
1212
#include "denoiser.hpp"
1313
#include "diffusion_model.hpp"
14+
#include "easycache.hpp"
1415
#include "esrgan.hpp"
1516
#include "lora.hpp"
1617
#include "pmid.hpp"
1718
#include "tae.hpp"
1819
#include "vae.hpp"
19-
#include "easycache.hpp"
2020

2121
#include "latent-preview.h"
2222
#include "name_conversion.h"
@@ -1482,11 +1482,11 @@ class StableDiffusionGGML {
14821482
const std::vector<float>& sigmas,
14831483
int start_merge_step,
14841484
SDCondition id_cond,
1485-
std::vector<ggml_tensor*> ref_latents = {},
1486-
bool increase_ref_index = false,
1487-
ggml_tensor* denoise_mask = nullptr,
1488-
ggml_tensor* vace_context = nullptr,
1489-
float vace_strength = 1.f,
1485+
std::vector<ggml_tensor*> ref_latents = {},
1486+
bool increase_ref_index = false,
1487+
ggml_tensor* denoise_mask = nullptr,
1488+
ggml_tensor* vace_context = nullptr,
1489+
float vace_strength = 1.f,
14901490
const sd_easycache_params_t* easycache_params = nullptr) {
14911491
if (shifted_timestep > 0 && !sd_version_is_sdxl(version)) {
14921492
LOG_WARN("timestep shifting is only supported for SDXL models!");
@@ -1511,11 +1511,11 @@ class StableDiffusionGGML {
15111511
LOG_WARN("EasyCache requested but not supported for this model type");
15121512
} else {
15131513
EasyCacheConfig easycache_config;
1514-
easycache_config.enabled = true;
1515-
easycache_config.reuse_threshold = std::max(0.0f, easycache_params->reuse_threshold);
1516-
easycache_config.start_percent = easycache_params->start_percent;
1517-
easycache_config.end_percent = easycache_params->end_percent;
1518-
bool percent_valid = easycache_config.start_percent >= 0.0f &&
1514+
easycache_config.enabled = true;
1515+
easycache_config.reuse_threshold = std::max(0.0f, easycache_params->reuse_threshold);
1516+
easycache_config.start_percent = easycache_params->start_percent;
1517+
easycache_config.end_percent = easycache_params->end_percent;
1518+
bool percent_valid = easycache_config.start_percent >= 0.0f &&
15191519
easycache_config.start_percent < 1.0f &&
15201520
easycache_config.end_percent > 0.0f &&
15211521
easycache_config.end_percent <= 1.0f &&
@@ -1612,7 +1612,7 @@ class StableDiffusionGGML {
16121612
DiffusionParams diffusion_params;
16131613

16141614
const bool easycache_step_active = easycache_enabled && step > 0;
1615-
int easycache_step_index = easycache_step_active ? (step - 1) : -1;
1615+
int easycache_step_index = easycache_step_active ? (step - 1) : -1;
16161616
if (easycache_step_active) {
16171617
easycache_state.begin_step(easycache_step_index, sigma);
16181618
}
@@ -1728,12 +1728,12 @@ class StableDiffusionGGML {
17281728
control_net->compute(n_threads, noised_input, control_hint, timesteps, uncond.c_crossattn, uncond.c_vector);
17291729
controls = control_net->controls;
17301730
}
1731-
current_step_skipped = easycache_step_is_skipped();
1731+
current_step_skipped = easycache_step_is_skipped();
17321732
diffusion_params.controls = controls;
17331733
diffusion_params.context = uncond.c_crossattn;
17341734
diffusion_params.c_concat = uncond.c_concat;
17351735
diffusion_params.y = uncond.c_vector;
1736-
bool skip_uncond = easycache_before_condition(&uncond, out_uncond);
1736+
bool skip_uncond = easycache_before_condition(&uncond, out_uncond);
17371737
if (!skip_uncond) {
17381738
work_diffusion_model->compute(n_threads,
17391739
diffusion_params,
@@ -1748,7 +1748,7 @@ class StableDiffusionGGML {
17481748
diffusion_params.context = img_cond.c_crossattn;
17491749
diffusion_params.c_concat = img_cond.c_concat;
17501750
diffusion_params.y = img_cond.c_vector;
1751-
bool skip_img_cond = easycache_before_condition(&img_cond, out_img_cond);
1751+
bool skip_img_cond = easycache_before_condition(&img_cond, out_img_cond);
17521752
if (!skip_img_cond) {
17531753
work_diffusion_model->compute(n_threads,
17541754
diffusion_params,
@@ -2403,8 +2403,8 @@ enum lora_apply_mode_t str_to_lora_apply_mode(const char* str) {
24032403
}
24042404

24052405
void sd_easycache_params_init(sd_easycache_params_t* easycache_params) {
2406-
*easycache_params = {};
2407-
easycache_params->enabled = false;
2406+
*easycache_params = {};
2407+
easycache_params->enabled = false;
24082408
easycache_params->reuse_threshold = 0.2f;
24092409
easycache_params->start_percent = 0.15f;
24102410
easycache_params->end_percent = 0.95f;
@@ -2702,8 +2702,8 @@ sd_image_t* generate_image_internal(sd_ctx_t* sd_ctx,
27022702
std::vector<sd_image_t*> ref_images,
27032703
std::vector<ggml_tensor*> ref_latents,
27042704
bool increase_ref_index,
2705-
ggml_tensor* concat_latent = nullptr,
2706-
ggml_tensor* denoise_mask = nullptr,
2705+
ggml_tensor* concat_latent = nullptr,
2706+
ggml_tensor* denoise_mask = nullptr,
27072707
const sd_easycache_params_t* easycache_params = nullptr) {
27082708
if (seed < 0) {
27092709
// Generally, when using the provided command line, the seed is always >0.

0 commit comments

Comments
 (0)