@@ -169,6 +169,13 @@ class mtmd_pos_type(enum.IntEnum):
169169mtmd_batch_p = NewType ("mtmd_batch_p" , int )
170170mtmd_batch_p_ctypes = c_void_p
171171
172+ # typedef bool (*mtmd_progress_callback)(float progress, void * user_data);
173+ mtmd_progress_callback = CFUNCTYPE (
174+ c_bool ,
175+ c_float , # progress
176+ c_void_p , # user_data
177+ )
178+
172179# struct mtmd_input_text {
173180# const char * text;
174181# bool add_special;
@@ -217,19 +224,25 @@ class clip_context_params(Structure):
217224# const char * media_marker;
218225# enum llama_flash_attn_type flash_attn_type;
219226# bool warmup; // whether to run a warmup encode pass after initialization
220- #
227+
221228# // limit number of image tokens, only for vision models with dynamic resolution
222229# int image_min_tokens; // minimum number of tokens for image input (default: read from metadata)
223230# int image_max_tokens; // maximum number of tokens for image input (default: read from metadata)
224- #
231+
225232# // callback function passed over to mtmd proper
226233# ggml_backend_sched_eval_callback cb_eval;
227234# void * cb_eval_user_data;
228- #
235+
229236# // batching params
230237# int32_t batch_max_tokens; // maximum number of output tokens in a batch
231238# // (note: this is not a hard-limit, the first image will always be added even if it exceeds this limit)
232239# // (default: 1024)
240+
241+ # // Called with a progress value between 0.0 and 1.0. Pass NULL to disable.
242+ # // If the provided progress_callback returns true, model loading continues.
243+ # // If it returns false, model loading is immediately aborted.
244+ # mtmd_progress_callback progress_callback;
245+ # void * progress_callback_user_data;
233246# };
234247class mtmd_context_params (Structure ):
235248 _fields_ = [
@@ -245,6 +258,8 @@ class mtmd_context_params(Structure):
245258 ("cb_eval" , ggml_backend_sched_eval_callback ),
246259 ("cb_eval_user_data" , c_void_p ),
247260 ("batch_max_tokens" , c_int32 ),
261+ ("progress_callback" , mtmd_progress_callback ),
262+ ("progress_callback_user_data" , c_void_p )
248263 ]
249264
250265mtmd_context_params_p_ctypes = POINTER (mtmd_context_params )
@@ -499,7 +514,7 @@ def mtmd_bitmap_init_lazy(
499514 ctx : mtmd_context_p ,
500515 id : c_char_p ,
501516 user_data : c_void_p ,
502- callback : mtmd_bitmap_lazy_callback , # type: ignore
517+ callback : Optional [ mtmd_bitmap_lazy_callback ] , # type: ignore
503518 / ,
504519) -> mtmd_bitmap_p :
505520 ...
@@ -1238,7 +1253,7 @@ def mtmd_helper_decode_image_chunk(
12381253 seq_id : c_int32 ,
12391254 n_batch : c_int32 ,
12401255 new_n_past : POINTER (c_int32 ), # type: ignore
1241- callback : mtmd_helper_post_decode_callback , # type: ignore
1256+ callback : Optional [ mtmd_helper_post_decode_callback ] , # type: ignore
12421257 user_data : c_void_p ,
12431258 / ,
12441259) -> c_int32 :
0 commit comments