Skip to content

Commit 4e026c7

Browse files
committed
preview: do not spam pretty progress when using tiled vae/tae as preview
1 parent b65ada3 commit 4e026c7

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

stable-diffusion.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ void calculate_alphas_cumprod(float* alphas_cumprod,
6868
}
6969
}
7070

71+
void suppress_pp(int step, int steps, float time, void* data) {
72+
(void)step;
73+
(void)steps;
74+
(void)time;
75+
(void)data;
76+
return;
77+
}
78+
7179
/*=============================================== StableDiffusionGGML ================================================*/
7280

7381
class StableDiffusionGGML {
@@ -782,6 +790,14 @@ class StableDiffusionGGML {
782790
return {c_crossattn, y, c_concat};
783791
}
784792

793+
void silent_tiling(ggml_tensor* input, ggml_tensor* output, const int scale, const int tile_size, const float tile_overlap_factor, on_tile_process on_processing) {
794+
sd_progress_cb_t cb = sd_get_progress_callback();
795+
void* cbd = sd_get_progress_callback_data();
796+
sd_set_progress_callback((sd_progress_cb_t)suppress_pp, NULL);
797+
sd_tiling(input, output, scale, tile_size, tile_overlap_factor, on_processing);
798+
sd_set_progress_callback(cb, cbd);
799+
}
800+
785801
void preview_image(ggml_context* work_ctx,
786802
int step,
787803
struct ggml_tensor* latents,
@@ -843,7 +859,8 @@ class StableDiffusionGGML {
843859
auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) {
844860
first_stage_model->compute(n_threads, in, true, &out);
845861
};
846-
sd_tiling(latents, result, 8, 32, 0.5f, on_tiling);
862+
silent_tiling(latents, result, 8, 32, 0.5f, on_tiling);
863+
847864
} else {
848865
first_stage_model->compute(n_threads, latents, true, &result);
849866
}
@@ -861,7 +878,7 @@ class StableDiffusionGGML {
861878
auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) {
862879
tae_first_stage->compute(n_threads, in, true, &out);
863880
};
864-
sd_tiling(latents, result, 8, 64, 0.5f, on_tiling);
881+
silent_tiling(latents, result, 8, 64, 0.5f, on_tiling);
865882
} else {
866883
tae_first_stage->compute(n_threads, latents, true, &result);
867884
}
@@ -1067,10 +1084,6 @@ class StableDiffusionGGML {
10671084
vec_denoised[i] = latent_result * c_out + vec_input[i] * c_skip;
10681085
}
10691086
int64_t t1 = ggml_time_us();
1070-
if (step > 0) {
1071-
pretty_progress(step, (int)steps, (t1 - t0) / 1000000.f);
1072-
// LOG_INFO("step %d sampling completed taking %.2fs", step, (t1 - t0) * 1.0f / 1000000);
1073-
}
10741087
if (noise_mask != nullptr) {
10751088
for (int64_t x = 0; x < denoised->ne[0]; x++) {
10761089
for (int64_t y = 0; y < denoised->ne[1]; y++) {
@@ -1083,6 +1096,10 @@ class StableDiffusionGGML {
10831096
}
10841097
}
10851098
}
1099+
if (step > 0) {
1100+
pretty_progress(step, (int)steps, (t1 - t0) / 1000000.f);
1101+
// LOG_INFO("step %d sampling completed taking %.2fs", step, (t1 - t0) * 1.0f / 1000000);
1102+
}
10861103

10871104
if (step_callback != nullptr) {
10881105
if (step % preview_interval == 0) {

stable-diffusion.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ typedef void (*sd_progress_cb_t)(int step, int steps, float time, void* data);
120120

121121
SD_API void sd_set_log_callback(sd_log_cb_t sd_log_cb, void* data);
122122
SD_API void sd_set_progress_callback(sd_progress_cb_t cb, void* data);
123+
SD_API sd_progress_cb_t sd_get_progress_callback();
124+
SD_API void* sd_get_progress_callback_data();
123125
SD_API int32_t get_num_physical_cores();
124126
SD_API const char* sd_get_system_info();
125127

util.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,12 @@ void sd_set_progress_callback(sd_progress_cb_t cb, void* data) {
407407
sd_progress_cb = cb;
408408
sd_progress_cb_data = data;
409409
}
410+
sd_progress_cb_t sd_get_progress_callback(){
411+
return sd_progress_cb;
412+
}
413+
void* sd_get_progress_callback_data(){
414+
return sd_progress_cb_data;
415+
}
410416
const char* sd_get_system_info() {
411417
static char buffer[1024];
412418
std::stringstream ss;

0 commit comments

Comments
 (0)