From 879bbc14842c9174e02c39235d2d8279ee185c32 Mon Sep 17 00:00:00 2001 From: Wagner Bruna Date: Tue, 16 Sep 2025 08:56:40 -0300 Subject: [PATCH 1/2] fix: better progress display for second-order samplers Second-order samplers call the model twice per step, except for the last iteration. Since the progress is updated only for each second call, the last step is never shown. The timing information is also misleading, since it's displaying the number of full steps, but measuring only the last half. Comparing to a first-order sampler, the progress shows the same timing for each iteration, and the same number of steps, but takes almost twice as long. So, change the display to show average time per step, which should give a better idea of the expected time until completion, and update the progress display after all model calls. --- stable-diffusion.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/stable-diffusion.cpp b/stable-diffusion.cpp index 62b40c6d0..147ec8af1 100644 --- a/stable-diffusion.cpp +++ b/stable-diffusion.cpp @@ -1130,11 +1130,12 @@ class StableDiffusionGGML { } struct ggml_tensor* denoised = ggml_dup_tensor(work_ctx, x); + int64_t t0 = ggml_time_us(); + auto denoise = [&](ggml_tensor* input, float sigma, int step) -> ggml_tensor* { - if (step == 1) { + if (step == 1 || step == -1) { pretty_progress(0, (int)steps, 0); } - int64_t t0 = ggml_time_us(); std::vector scaling = denoiser->get_scalings(sigma); GGML_ASSERT(scaling.size() == 3); @@ -1288,8 +1289,9 @@ class StableDiffusionGGML { } int64_t t1 = ggml_time_us(); - if (step > 0) { - pretty_progress(step, (int)steps, (t1 - t0) / 1000000.f); + if (step != 0) { + int showstep = std::abs(step); + pretty_progress(showstep, (int)steps, (t1 - t0) / 1000000.f / showstep); // LOG_INFO("step %d sampling completed taking %.2fs", step, (t1 - t0) * 1.0f / 1000000); } if (denoise_mask != nullptr) { From 852adcc4d24254881ab4475d01410fa4bc6cda31 Mon Sep 17 00:00:00 2001 From: Wagner Bruna Date: Sat, 11 Oct 2025 15:49:33 -0300 Subject: [PATCH 2/2] omit progress calls on half steps to avoid oscillation The progress call on each half step would increase the time without increasing the step count, making the average go up; it would then go down again on the whole step update. --- stable-diffusion.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stable-diffusion.cpp b/stable-diffusion.cpp index 147ec8af1..b08928420 100644 --- a/stable-diffusion.cpp +++ b/stable-diffusion.cpp @@ -1289,7 +1289,7 @@ class StableDiffusionGGML { } int64_t t1 = ggml_time_us(); - if (step != 0) { + if (step > 0 || step == -(int)steps) { int showstep = std::abs(step); pretty_progress(showstep, (int)steps, (t1 - t0) / 1000000.f / showstep); // LOG_INFO("step %d sampling completed taking %.2fs", step, (t1 - t0) * 1.0f / 1000000);