Skip to content

Commit 2413a66

Browse files
committed
preview: do not spam pretty progress when using tiled vae/tae as preview
1 parent 0bb0355 commit 2413a66

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 {
@@ -788,6 +796,14 @@ class StableDiffusionGGML {
788796
return {c_crossattn, y, c_concat};
789797
}
790798

799+
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) {
800+
sd_progress_cb_t cb = sd_get_progress_callback();
801+
void* cbd = sd_get_progress_callback_data();
802+
sd_set_progress_callback((sd_progress_cb_t)suppress_pp, NULL);
803+
sd_tiling(input, output, scale, tile_size, tile_overlap_factor, on_processing);
804+
sd_set_progress_callback(cb, cbd);
805+
}
806+
791807
void preview_image(ggml_context* work_ctx,
792808
int step,
793809
struct ggml_tensor* latents,
@@ -849,7 +865,8 @@ class StableDiffusionGGML {
849865
auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) {
850866
first_stage_model->compute(n_threads, in, true, &out);
851867
};
852-
sd_tiling(latents, result, 8, 32, 0.5f, on_tiling);
868+
silent_tiling(latents, result, 8, 32, 0.5f, on_tiling);
869+
853870
} else {
854871
first_stage_model->compute(n_threads, latents, true, &result);
855872
}
@@ -867,7 +884,7 @@ class StableDiffusionGGML {
867884
auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) {
868885
tae_first_stage->compute(n_threads, in, true, &out);
869886
};
870-
sd_tiling(latents, result, 8, 64, 0.5f, on_tiling);
887+
silent_tiling(latents, result, 8, 64, 0.5f, on_tiling);
871888
} else {
872889
tae_first_stage->compute(n_threads, latents, true, &result);
873890
}
@@ -1073,10 +1090,6 @@ class StableDiffusionGGML {
10731090
vec_denoised[i] = latent_result * c_out + vec_input[i] * c_skip;
10741091
}
10751092
int64_t t1 = ggml_time_us();
1076-
if (step > 0) {
1077-
pretty_progress(step, (int)steps, (t1 - t0) / 1000000.f);
1078-
// LOG_INFO("step %d sampling completed taking %.2fs", step, (t1 - t0) * 1.0f / 1000000);
1079-
}
10801093
if (noise_mask != nullptr) {
10811094
for (int64_t x = 0; x < denoised->ne[0]; x++) {
10821095
for (int64_t y = 0; y < denoised->ne[1]; y++) {
@@ -1089,6 +1102,10 @@ class StableDiffusionGGML {
10891102
}
10901103
}
10911104
}
1105+
if (step > 0) {
1106+
pretty_progress(step, (int)steps, (t1 - t0) / 1000000.f);
1107+
// LOG_INFO("step %d sampling completed taking %.2fs", step, (t1 - t0) * 1.0f / 1000000);
1108+
}
10921109

10931110
if (step_callback != nullptr) {
10941111
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)