Skip to content

Commit 4d842eb

Browse files
committed
add clone()
1 parent 6bc7a30 commit 4d842eb

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

tools/llava/clip-impl.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,15 @@ struct clip_image_u8_batch {
231231

232232
struct clip_image_f32_batch {
233233
std::vector<clip_image_f32_ptr> entries;
234+
235+
clip_image_f32_batch clone() const {
236+
clip_image_f32_batch new_batch;
237+
new_batch.entries.reserve(entries.size());
238+
for (const auto & entry : entries) {
239+
new_batch.entries.emplace_back(new clip_image_f32(*entry));
240+
}
241+
return new_batch;
242+
}
234243
};
235244

236245
//

tools/llava/mtmd.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,16 @@ struct mtmd_image_tokens {
166166
uint32_t n_tokens() const { return nx * ny; }
167167
clip_image_f32_batch batch_f32; // preprocessed image patches
168168
std::string id; // optional user-defined ID, useful for KV cache tracking
169+
170+
mtmd_image_tokens clone() {
171+
return mtmd_image_tokens{
172+
nx,
173+
ny,
174+
use_mrope_pos,
175+
batch_f32.clone(),
176+
id
177+
};
178+
}
169179
};
170180

171181
mtmd_context * mtmd_init_from_file(const char * mmproj_fname,
@@ -861,7 +871,8 @@ mtmd_input_chunk * mtmd_input_chunk_copy(const mtmd_input_chunk * chunk) {
861871
};
862872
if (chunk->tokens_image) {
863873
// copy the image tokens
864-
copy->tokens_image = mtmd_image_tokens_ptr(new mtmd_image_tokens(*chunk->tokens_image));
874+
copy->tokens_image = mtmd_image_tokens_ptr(new mtmd_image_tokens());
875+
*copy->tokens_image = chunk->tokens_image->clone();
865876
}
866877
return copy;
867878
}

0 commit comments

Comments
 (0)