@@ -1026,32 +1026,36 @@ class StableDiffusionGGML {
1026
1026
result_cb (number, image_data, result_cb_data);
1027
1027
}
1028
1028
1029
- sd_result_step_cb_t result_step_cb = nullptr ;
1030
- int result_step_cb_interval = 1 ;
1031
- void * result_step_cb_data = nullptr ;
1029
+ sd_result_step_cb_t result_step_cb = nullptr ;
1030
+ int result_step_cb_preview_interval = - 1 ;
1031
+ void * result_step_cb_data = nullptr ;
1032
1032
1033
1033
void send_result_step_callback (ggml_context* task_work_ctx, ggml_tensor* x, size_t number, size_t step) {
1034
- if (result_step_cb == nullptr || step % result_step_cb_interval != 0 ) {
1034
+ if (result_step_cb == nullptr ) {
1035
1035
return ;
1036
1036
}
1037
1037
1038
- struct ggml_init_params params {};
1039
- params.mem_size = ggml_get_mem_size (task_work_ctx);
1040
- params.mem_buffer = nullptr ;
1041
- params.no_alloc = false ;
1038
+ if (result_step_cb_preview_interval != -1 && step % result_step_cb_preview_interval == 0 ) {
1039
+ struct ggml_init_params params {};
1040
+ params.mem_size = ggml_get_mem_size (task_work_ctx);
1041
+ params.mem_buffer = nullptr ;
1042
+ params.no_alloc = false ;
1042
1043
1043
- struct ggml_context * work_ctx = ggml_init (params);
1044
- if (!work_ctx) {
1045
- return ;
1046
- }
1044
+ struct ggml_context * work_ctx = ggml_init (params);
1045
+ if (!work_ctx) {
1046
+ return ;
1047
+ }
1047
1048
1048
- struct ggml_tensor * result = ggml_dup_tensor (work_ctx, x);
1049
- copy_ggml_tensor (result, x);
1049
+ struct ggml_tensor * result = ggml_dup_tensor (work_ctx, x);
1050
+ copy_ggml_tensor (result, x);
1050
1051
1051
- struct ggml_tensor * img = decode_first_stage (work_ctx, result);
1052
- result_step_cb (number, step, sd_tensor_to_image (img), result_step_cb_data);
1052
+ struct ggml_tensor * img = decode_first_stage (work_ctx, result);
1053
+ result_step_cb (number, step, sd_tensor_to_image (img), result_step_cb_data);
1053
1054
1054
- ggml_free (work_ctx);
1055
+ ggml_free (work_ctx);
1056
+ } else {
1057
+ result_step_cb (number, step, nullptr , result_step_cb_data);
1058
+ }
1055
1059
}
1056
1060
};
1057
1061
@@ -1140,13 +1144,13 @@ void free_sd_ctx(sd_ctx_t* sd_ctx) {
1140
1144
}
1141
1145
1142
1146
void sd_ctx_set_result_callback (sd_ctx_t * sd_ctx, sd_result_cb_t cb, void * data) {
1143
- sd_ctx->sd ->result_cb = cb;
1147
+ sd_ctx->sd ->result_cb = cb;
1144
1148
sd_ctx->sd ->result_cb_data = data;
1145
1149
}
1146
1150
1147
- void sd_ctx_set_result_step_callback (sd_ctx_t * sd_ctx, sd_result_step_cb_t cb, int cb_interval , void * data) {
1148
- sd_ctx->sd ->result_step_cb = cb;
1149
- sd_ctx->sd ->result_step_cb_interval = cb_interval ;
1151
+ void sd_ctx_set_result_step_callback (sd_ctx_t * sd_ctx, sd_result_step_cb_t cb, int cb_preview_interval , void * data) {
1152
+ sd_ctx->sd ->result_step_cb = cb;
1153
+ sd_ctx->sd ->result_step_cb_preview_interval = cb_preview_interval ;
1150
1154
sd_ctx->sd ->result_step_cb_data = data;
1151
1155
}
1152
1156
0 commit comments