Skip to content

Commit 3170c13

Browse files
committed
do not spam pretty progress when using tiled vae/tae as preview
1 parent ef3d7d5 commit 3170c13

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

stable-diffusion.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@ void calculate_alphas_cumprod(float* alphas_cumprod,
7171
}
7272
}
7373

74+
void suppress_pp(int step, int steps, float time, void* data) {
75+
(void)step;
76+
(void)steps;
77+
(void)time;
78+
(void)data;
79+
return;
80+
}
81+
7482
/*=============================================== StableDiffusionGGML ================================================*/
7583

7684
class StableDiffusionGGML {
@@ -837,7 +845,16 @@ class StableDiffusionGGML {
837845
LOG_DEBUG("computing svd condition graph completed, taking %" PRId64 " ms", t1 - t0);
838846
return {c_crossattn, y, c_concat};
839847
}
840-
void preview_image(ggml_context* work_ctx,
848+
849+
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) {
850+
sd_progress_cb_t cb = sd_get_progress_callback();
851+
void* cbd = sd_get_progress_callback_data();
852+
sd_set_progress_callback((sd_progress_cb_t)suppress_pp, NULL);
853+
sd_tiling(input, output, scale, tile_size, tile_overlap_factor, on_processing);
854+
sd_set_progress_callback(cb, cbd);
855+
}
856+
857+
void preview_image(ggml_context* work_ctx,
841858
int step,
842859
struct ggml_tensor* latents,
843860
enum SDVersion version,
@@ -898,7 +915,8 @@ void preview_image(ggml_context* work_ctx,
898915
auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) {
899916
first_stage_model->compute(n_threads, in, true, &out);
900917
};
901-
sd_tiling(latents, result, 8, 32, 0.5f, on_tiling);
918+
silent_tiling(latents, result, 8, 32, 0.5f, on_tiling);
919+
902920
} else {
903921
first_stage_model->compute(n_threads, latents, true, &result);
904922
}
@@ -916,7 +934,7 @@ void preview_image(ggml_context* work_ctx,
916934
auto on_tiling = [&](ggml_tensor* in, ggml_tensor* out, bool init) {
917935
tae_first_stage->compute(n_threads, in, true, &out);
918936
};
919-
sd_tiling(latents, result, 8, 64, 0.5f, on_tiling);
937+
silent_tiling(latents, result, 8, 64, 0.5f, on_tiling);
920938
} else {
921939
tae_first_stage->compute(n_threads, latents, true, &result);
922940
}
@@ -1194,6 +1212,10 @@ void preview_image(ggml_context* work_ctx,
11941212
}
11951213
}
11961214
}
1215+
if (step > 0) {
1216+
pretty_progress(step, (int)steps, (t1 - t0) / 1000000.f);
1217+
// LOG_INFO("step %d sampling completed taking %.2fs", step, (t1 - t0) * 1.0f / 1000000);
1218+
}
11971219

11981220
if (step_callback != nullptr) {
11991221
if (step % preview_interval == 0) {

stable-diffusion.h

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

218218
SD_API void sd_set_log_callback(sd_log_cb_t sd_log_cb, void* data);
219219
SD_API void sd_set_progress_callback(sd_progress_cb_t cb, void* data);
220+
SD_API sd_progress_cb_t sd_get_progress_callback();
221+
SD_API void* sd_get_progress_callback_data();
220222
SD_API int32_t get_num_physical_cores();
221223
SD_API const char* sd_get_system_info();
222224

util.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,12 @@ void sd_set_progress_callback(sd_progress_cb_t cb, void* data) {
420420
sd_progress_cb = cb;
421421
sd_progress_cb_data = data;
422422
}
423+
sd_progress_cb_t sd_get_progress_callback(){
424+
return sd_progress_cb;
425+
}
426+
void* sd_get_progress_callback_data(){
427+
return sd_progress_cb_data;
428+
}
423429
const char* sd_get_system_info() {
424430
static char buffer[1024];
425431
std::stringstream ss;

0 commit comments

Comments
 (0)