Skip to content

Commit 2d1bc7f

Browse files
committed
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.
1 parent 0ebe6fe commit 2d1bc7f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

stable-diffusion.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,11 +1089,12 @@ class StableDiffusionGGML {
10891089
}
10901090
struct ggml_tensor* denoised = ggml_dup_tensor(work_ctx, x);
10911091

1092+
int64_t t0 = ggml_time_us();
1093+
10921094
auto denoise = [&](ggml_tensor* input, float sigma, int step) -> ggml_tensor* {
1093-
if (step == 1) {
1095+
if (step == 1 || step == -1) {
10941096
pretty_progress(0, (int)steps, 0);
10951097
}
1096-
int64_t t0 = ggml_time_us();
10971098

10981099
std::vector<float> scaling = denoiser->get_scalings(sigma);
10991100
GGML_ASSERT(scaling.size() == 3);
@@ -1223,8 +1224,9 @@ class StableDiffusionGGML {
12231224
vec_denoised[i] = latent_result * c_out + vec_input[i] * c_skip;
12241225
}
12251226
int64_t t1 = ggml_time_us();
1226-
if (step > 0) {
1227-
pretty_progress(step, (int)steps, (t1 - t0) / 1000000.f);
1227+
if (step != 0) {
1228+
int showstep = std::abs(step);
1229+
pretty_progress(showstep, (int)steps, (t1 - t0) / 1000000.f / showstep);
12281230
// LOG_INFO("step %d sampling completed taking %.2fs", step, (t1 - t0) * 1.0f / 1000000);
12291231
}
12301232
if (denoise_mask != nullptr) {

0 commit comments

Comments
 (0)