@@ -43,14 +43,18 @@ static bool diffusion_step_callback(int32_t step, int32_t total_steps, const lla
4343 void * user_data) {
4444 callback_data * data = static_cast <callback_data *>(user_data);
4545
46+ auto print_progress_bar = [](int32_t step, int32_t total_steps) {
47+ int progress_percent = (step * 100 ) / total_steps;
48+ int progress_bars = (step * 50 ) / total_steps;
49+ std::cerr << " diffusion step: " << step << " /" << total_steps << " [" << std::string (progress_bars, ' =' )
50+ << std::string (50 - progress_bars, ' ' ) << " ] " << progress_percent << " %\n " ;
51+ };
52+
4653 if (data->diff_params ->visual_mode ) {
4754 // Visual mode: clear
4855 std::cerr << " \033 [2J\033 [H" ; // Clear screen and move cursor to top-left
4956
50- int progress_percent = (step * 100 ) / total_steps;
51- int progress_bars = (step * 50 ) / total_steps;
52- std::cerr << " Diffusion Step " << step << " /" << total_steps << " [" << std::string (progress_bars, ' =' )
53- << std::string (50 - progress_bars, ' ' ) << " ] " << progress_percent << " %\n " ;
57+ print_progress_bar (step, total_steps);
5458
5559 std::string current_text = " " ;
5660
@@ -73,11 +77,7 @@ static bool diffusion_step_callback(int32_t step, int32_t total_steps, const lla
7377 std::cerr << current_text << " \n " ;
7478 std::cerr << std::flush;
7579 } else {
76- int progress_percent = (step * 100 ) / total_steps;
77- int progress_bars = (step * 50 ) / total_steps;
78-
79- std::cerr << " \r Diffusion Step " << step << " /" << total_steps << " [" << std::string (progress_bars, ' =' )
80- << std::string (50 - progress_bars, ' ' ) << " ] " << progress_percent << " %" << std::flush;
80+ print_progress_bar (step, total_steps);
8181 }
8282
8383 return true ; // Continue generation
@@ -175,8 +175,11 @@ int main(int argc, char ** argv) {
175175 ldiff_params.step_callback_user_data = &cb_data;
176176
177177 int32_t n_generated = 0 ;
178+
179+ int64_t t1 = ggml_time_us ();
178180 llama_token * generated = diffusion_generate (ctx, input_tokens.data (), n_input, params.diffusion .max_length ,
179181 ldiff_params, &n_generated);
182+ int64_t t2 = ggml_time_us ();
180183 if (params.diffusion .visual_mode ) {
181184 std::cerr << " \033 [2J\033 [H" ; // Clear screen and move cursor to top-left
182185 } else {
@@ -197,6 +200,8 @@ int main(int argc, char ** argv) {
197200 return 1 ;
198201 }
199202
203+ std::cerr << " diffusion time: " << (t2 - t1)/1000.0 << " ms time per step: " << (t2 - t1)/1000.0 /params.diffusion .steps << " ms" << std::endl;
204+
200205 llama_free (ctx);
201206 llama_model_free (model);
202207 llama_backend_free ();
0 commit comments