@@ -29,8 +29,7 @@ struct mtmd_context {
29
29
const mtmd_context_params & ctx_params) :
30
30
print_timings (ctx_params.print_timings),
31
31
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)
34
33
{
35
34
clip_context_params ctx_clip_params;
36
35
ctx_clip_params.use_gpu = ctx_params.use_gpu ;
@@ -56,7 +55,7 @@ struct mtmd_image_tokens {
56
55
uint32_t ny; // number of tokens in y direction
57
56
uint32_t n_tokens () const { return nx * ny; }
58
57
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 hash ; // optional user-defined hash , useful for KV cache tracking
60
59
};
61
60
62
61
mtmd_context * mtmd_init_from_file (const char * mmproj_fname,
@@ -96,16 +95,6 @@ static std::vector<llama_token> mtmd_tokenize_text_internal(
96
95
return result;
97
96
}
98
97
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
-
109
98
int32_t mtmd_tokenize (mtmd_context * ctx,
110
99
std::vector<mtmd_input_chunk> & output,
111
100
const mtmd_input_text & text,
@@ -170,11 +159,7 @@ int32_t mtmd_tokenize(mtmd_context * ctx,
170
159
image_tokens->nx = clip_n_patches (ctx->ctx_clip ); // TODO @ngxson : use clip_n_patches_by_image
171
160
image_tokens->ny = 1 ; // TODO
172
161
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->hash = bitmaps[i_img].hash ;
178
163
179
164
mtmd_input_chunk chunk{
180
165
MTMD_INPUT_CHUNK_TYPE_IMAGE,
@@ -207,8 +192,8 @@ size_t mtmd_image_tokens_get_ny(const mtmd_image_tokens * image_tokens) {
207
192
return image_tokens->ny ;
208
193
}
209
194
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_hash (const mtmd_image_tokens * image_tokens) {
196
+ return image_tokens->hash ;
212
197
}
213
198
214
199
int32_t mtmd_encode (mtmd_context * ctx, const mtmd_image_tokens * image_tokens) {
0 commit comments