@@ -29,8 +29,7 @@ struct mtmd_context {
2929 const mtmd_context_params & ctx_params) :
3030 print_timings (ctx_params.print_timings),
3131 n_threads (ctx_params.n_threads),
32- image_marker (ctx_params.image_marker),
33- calc_image_hash (ctx_params.calc_image_hash)
32+ image_marker (ctx_params.image_marker)
3433 {
3534 clip_context_params ctx_clip_params;
3635 ctx_clip_params.use_gpu = ctx_params.use_gpu ;
@@ -56,7 +55,7 @@ struct mtmd_image_tokens {
5655 uint32_t ny; // number of tokens in y direction
5756 uint32_t n_tokens () const { return nx * ny; }
5857 clip_image_f32_batch batch_f32; // preprocessed image patches
59- size_t image_hash = 0 ; // hash of the image , useful for KV cache tracking
58+ std::string id ; // optional user-defined ID , useful for KV cache tracking
6059};
6160
6261mtmd_context * mtmd_init_from_file (const char * mmproj_fname,
@@ -96,16 +95,6 @@ static std::vector<llama_token> mtmd_tokenize_text_internal(
9695 return result;
9796}
9897
99- static uint64_t hash_vector_float (const std::vector<float > & vec) {
100- uint64_t seed = vec.size ();
101- std::hash<float > hasher;
102- for (float val : vec) {
103- // inspired by boost::hash_combine
104- seed ^= hasher (val) + 0x9e3779b9 + (seed << 6 ) + (seed >> 2 );
105- }
106- return seed;
107- }
108-
10998int32_t mtmd_tokenize (mtmd_context * ctx,
11099 std::vector<mtmd_input_chunk> & output,
111100 const mtmd_input_text & text,
@@ -170,11 +159,7 @@ int32_t mtmd_tokenize(mtmd_context * ctx,
170159 image_tokens->nx = clip_n_patches (ctx->ctx_clip ); // TODO @ngxson : use clip_n_patches_by_image
171160 image_tokens->ny = 1 ; // TODO
172161 image_tokens->batch_f32 = std::move (batch_f32);
173-
174- // optionally calculate the hash
175- if (ctx->calc_image_hash ) {
176- image_tokens->image_hash = hash_vector_float (image_tokens->batch_f32 .entries [0 ]->buf );
177- }
162+ image_tokens->id = bitmaps[i_img].id ; // optional
178163
179164 mtmd_input_chunk chunk{
180165 MTMD_INPUT_CHUNK_TYPE_IMAGE,
@@ -207,8 +192,8 @@ size_t mtmd_image_tokens_get_ny(const mtmd_image_tokens * image_tokens) {
207192 return image_tokens->ny ;
208193}
209194
210- uint64_t mtmd_image_tokens_get_hash (const mtmd_image_tokens * image_tokens) {
211- return image_tokens->image_hash ;
195+ std::string mtmd_image_tokens_get_id (const mtmd_image_tokens * image_tokens) {
196+ return image_tokens->id ;
212197}
213198
214199int32_t mtmd_encode (mtmd_context * ctx, const mtmd_image_tokens * image_tokens) {
0 commit comments