Skip to content

Commit 3fc6b15

Browse files
committed
migrate llava to mtmd
1 parent 8d7001e commit 3fc6b15

File tree

3 files changed

+16
-259
lines changed

3 files changed

+16
-259
lines changed

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.21)
33
project(llama_cpp)
44

55
option(LLAMA_BUILD "Build llama.cpp shared library and install alongside python package" ON)
6-
option(LLAVA_BUILD "Build llava shared library and install alongside python package" ON)
6+
option(MTMD_BUILD "Build multimodal (mtmd) shared library and install alongside python package" ON)
77

88
function(llama_cpp_python_install_target target)
99
if(NOT TARGET ${target})
@@ -143,7 +143,7 @@ if (LLAMA_BUILD)
143143
)
144144
endif()
145145

146-
if (LLAVA_BUILD)
146+
if (MTMD_BUILD)
147147
if (LLAMA_CUBLAS OR LLAMA_CUDA)
148148
add_compile_definitions(GGML_USE_CUBLAS)
149149
add_compile_definitions(GGML_USE_CUDA)
@@ -153,7 +153,7 @@ if (LLAMA_BUILD)
153153
add_compile_definitions(GGML_USE_METAL)
154154
endif()
155155

156-
# Building llava
156+
# Building multimodal support using mtmd
157157
add_subdirectory(vendor/llama.cpp/tools/mtmd)
158158

159159
if (WIN32)

llama_cpp/llama_chat_format.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3057,7 +3057,7 @@ def eval_image(self, llama: llama.Llama, image_url: str):
30573057
n_past = ctypes.c_int(llama.n_tokens)
30583058
n_past_p = ctypes.pointer(n_past)
30593059
with suppress_stdout_stderr(disable=self.verbose):
3060-
self._llava_cpp.llava_eval_image_embed(
3060+
self._mtmd_cpp.mtmd_cpp_eval_image_embed(
30613061
llama.ctx,
30623062
embed,
30633063
llama.n_batch,
@@ -3639,30 +3639,30 @@ def eval_image(self, llama: llama.Llama, image_url: str):
36393639
)
36403640

36413641
img_bytes = self.load_image(image_url)
3642-
img_u8_p = self._llava_cpp.clip_image_u8_init()
3643-
if not self._llava_cpp.clip_image_load_from_bytes(
3642+
img_u8_p = self._mtmd_cpp.clip_image_u8_init()
3643+
if not self._mtmd_cpp.clip_image_load_from_bytes(
36443644
ctypes.create_string_buffer(img_bytes, len(img_bytes)),
36453645
ctypes.c_size_t(len(img_bytes)),
36463646
img_u8_p,
36473647
):
3648-
self._llava_cpp.clip_image_u8_free(img_u8_p)
3648+
self._mtmd_cpp.clip_image_u8_free(img_u8_p)
36493649
raise ValueError("Failed to load image.")
36503650

3651-
img_f32_p = self._llava_cpp.clip_image_f32_batch_init()
3652-
if not self._llava_cpp.clip_image_preprocess(self.clip_ctx, img_u8_p, img_f32_p):
3653-
self._llava_cpp.clip_image_f32_batch_free(img_f32_p)
3654-
self._llava_cpp.clip_image_u8_free(img_u8_p)
3651+
img_f32_p = self._mtmd_cpp.clip_image_f32_batch_init()
3652+
if not self._mtmd_cpp.clip_image_preprocess(self.clip_ctx, img_u8_p, img_f32_p):
3653+
self._mtmd_cpp.clip_image_f32_batch_free(img_f32_p)
3654+
self._mtmd_cpp.clip_image_u8_free(img_u8_p)
36553655
raise ValueError("Failed to preprocess image.")
36563656

36573657
n_embd = llama_cpp.llama_model_n_embd(llama._model.model)
36583658
embed = (ctypes.c_float * (n_tokens * n_embd))()
3659-
if not self._llava_cpp.clip_image_batch_encode(self.clip_ctx, llama.n_threads, img_f32_p, embed):
3660-
self._llava_cpp.clip_image_f32_batch_free(img_f32_p)
3661-
self._llava_cpp.clip_image_u8_free(img_u8_p)
3659+
if not self._mtmd_cpp.clip_image_batch_encode(self.clip_ctx, llama.n_threads, img_f32_p, embed):
3660+
self._mtmd_cpp.clip_image_f32_batch_free(img_f32_p)
3661+
self._mtmd_cpp.clip_image_u8_free(img_u8_p)
36623662
raise ValueError("Failed to encode image.")
36633663

3664-
self._llava_cpp.clip_image_f32_batch_free(img_f32_p)
3665-
self._llava_cpp.clip_image_u8_free(img_u8_p)
3664+
self._mtmd_cpp.clip_image_f32_batch_free(img_f32_p)
3665+
self._mtmd_cpp.clip_image_u8_free(img_u8_p)
36663666
llama_cpp.llama_set_causal_attn(llama.ctx, False)
36673667

36683668
seq_id_0 = (ctypes.c_int32 * 1)()

llama_cpp/llava_cpp.py

Lines changed: 0 additions & 243 deletions
This file was deleted.

0 commit comments

Comments
 (0)