@@ -81,13 +81,20 @@ MTMD_API void mtmd_free(mtmd_context * ctx);
8181// 2. (image tokens)
8282// 3. "<end_of_image>\ndescribe it in detail."
8383// number of bitmaps must be equal to the number of image markers in the prompt
84+ // the returned value must be freed using mtmd_input_chunks_free()
8485// this function is thread-safe (shared ctx)
8586MTMD_API mtmd_input_chunks * mtmd_tokenize (mtmd_context * ctx,
8687 const mtmd_input_text & text,
8788 const std::vector<mtmd_bitmap> & bitmaps);
8889
89- // free image chunk data
90- MTMD_API void mtmd_input_chunks_free (mtmd_input_chunks * chunks);
90+ // if free_images = true, free the image tokens ; otherwise, you must free them using mtmd_image_free()
91+ MTMD_API void mtmd_input_chunks_free (mtmd_input_chunks * chunks, bool free_images);
92+
93+ // access mtmd_image_tokens
94+ MTMD_API size_t mtmd_image_tokens_get_n_tokens (const mtmd_image_tokens * image_tokens);
95+ MTMD_API size_t mtmd_image_tokens_get_nx (const mtmd_image_tokens * image_tokens);
96+ MTMD_API size_t mtmd_image_tokens_get_ny (const mtmd_image_tokens * image_tokens);
97+ MTMD_API void mtmd_image_tokens_free (mtmd_image_tokens * image_tokens);
9198
9299// returns 0 on success
93100MTMD_API int32_t mtmd_encode (mtmd_context * ctx,
@@ -96,6 +103,11 @@ MTMD_API int32_t mtmd_encode(mtmd_context * ctx,
96103// get output embeddings from the last encode pass
97104MTMD_API float * mtmd_get_output_embd (mtmd_context * ctx);
98105
106+ // whether we need to set non-causal mask before llama_decode
107+ MTMD_API bool mtmd_decode_use_non_causal (mtmd_context * ctx);
108+
109+
110+
99111//
100112// helper functions (can be implemented based on other functions)
101113//
@@ -133,10 +145,15 @@ struct mtmd_context_deleter {
133145using mtmd_context_ptr = std::unique_ptr<mtmd_context, mtmd_context_deleter>;
134146
135147struct mtmd_input_chunks_deleter {
136- void operator ()(mtmd_input_chunks * val) { mtmd_input_chunks_free (val); }
148+ void operator ()(mtmd_input_chunks * val) { mtmd_input_chunks_free (val, true ); }
137149};
138150using mtmd_input_chunks_ptr = std::unique_ptr<mtmd_input_chunks, mtmd_input_chunks_deleter>;
139151
152+ struct mtmd_image_tokens_deleter {
153+ void operator ()(mtmd_image_tokens * val) { mtmd_image_tokens_free (val); }
154+ };
155+ using mtmd_image_tokens_ptr = std::unique_ptr<mtmd_image_tokens, mtmd_image_tokens_deleter>;
156+
140157#else
141158
142159static_assert (false && " C header is not yet supported by this library" );
0 commit comments