@@ -81,13 +81,20 @@ MTMD_API void mtmd_free(mtmd_context * ctx);
81
81
// 2. (image tokens)
82
82
// 3. "<end_of_image>\ndescribe it in detail."
83
83
// 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()
84
85
// this function is thread-safe (shared ctx)
85
86
MTMD_API mtmd_input_chunks * mtmd_tokenize (mtmd_context * ctx,
86
87
const mtmd_input_text & text,
87
88
const std::vector<mtmd_bitmap> & bitmaps);
88
89
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);
91
98
92
99
// returns 0 on success
93
100
MTMD_API int32_t mtmd_encode (mtmd_context * ctx,
@@ -96,6 +103,11 @@ MTMD_API int32_t mtmd_encode(mtmd_context * ctx,
96
103
// get output embeddings from the last encode pass
97
104
MTMD_API float * mtmd_get_output_embd (mtmd_context * ctx);
98
105
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
+
99
111
//
100
112
// helper functions (can be implemented based on other functions)
101
113
//
@@ -133,10 +145,15 @@ struct mtmd_context_deleter {
133
145
using mtmd_context_ptr = std::unique_ptr<mtmd_context, mtmd_context_deleter>;
134
146
135
147
struct 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 ); }
137
149
};
138
150
using mtmd_input_chunks_ptr = std::unique_ptr<mtmd_input_chunks, mtmd_input_chunks_deleter>;
139
151
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
+
140
157
#else
141
158
142
159
static_assert (false && " C header is not yet supported by this library" );
0 commit comments