Skip to content

Commit 50f355d

Browse files
authored
Add pretty_progress() with time remainder
1 parent 41ae63f commit 50f355d

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

util.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,39 @@ void pretty_progress(int step, int steps, float time) {
357357
}
358358
}
359359

360+
#ifdef SD_SHOW_REMAINING_TIME
361+
void pretty_progress(int step, int steps, float time, float left) {
362+
if (sd_progress_cb) {
363+
sd_progress_cb(step, steps, time, sd_progress_cb_data);
364+
return;
365+
}
366+
if (step == 0) {
367+
return;
368+
}
369+
std::string progress = " |";
370+
int max_progress = 50;
371+
int32_t current = (int32_t)(step * 1.f * max_progress / steps);
372+
for (int i = 0; i < 50; i++) {
373+
if (i > current) {
374+
progress += " ";
375+
} else if (i == current && i != max_progress - 1) {
376+
progress += ">";
377+
} else {
378+
progress += "=";
379+
}
380+
}
381+
progress += "|";
382+
printf(time > 1.0f ? "\r%s %i/%i - %.2fs/it" : "\r%s %i/%i - %.2fit/s\033[K",
383+
progress.c_str(), step, steps,
384+
time > 1.0f || time == 0 ? time : (1.0f / time));
385+
printf(", %.0fm %.2fs left ", left / 60, fmod(left, 60));
386+
fflush(stdout); // for linux
387+
if (step == steps) {
388+
printf("\n");
389+
}
390+
}
391+
#endif // SD_SHOW_REMAINING_TIME
392+
360393
std::string ltrim(const std::string& s) {
361394
auto it = std::find_if(s.begin(), s.end(), [](int ch) {
362395
return !std::isspace(ch);
@@ -686,4 +719,4 @@ std::vector<std::pair<std::string, float>> parse_prompt_attention(const std::str
686719
}
687720

688721
return res;
689-
}
722+
}

0 commit comments

Comments
 (0)