Skip to content

Commit 11f768e

Browse files
committed
migrate llava to mtmd
1 parent 7c44196 commit 11f768e

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
@@ -3063,7 +3063,7 @@ def eval_image(self, llama: llama.Llama, image_url: str):
30633063
n_past = ctypes.c_int(llama.n_tokens)
30643064
n_past_p = ctypes.pointer(n_past)
30653065
with suppress_stdout_stderr(disable=self.verbose):
3066-
self._llava_cpp.llava_eval_image_embed(
3066+
self._mtmd_cpp.mtmd_cpp_eval_image_embed(
30673067
llama.ctx,
30683068
embed,
30693069
llama.n_batch,
@@ -3648,30 +3648,30 @@ def eval_image(self, llama: llama.Llama, image_url: str):
36483648
)
36493649

36503650
img_bytes = self.load_image(image_url)
3651-
img_u8_p = self._llava_cpp.clip_image_u8_init()
3652-
if not self._llava_cpp.clip_image_load_from_bytes(
3651+
img_u8_p = self._mtmd_cpp.clip_image_u8_init()
3652+
if not self._mtmd_cpp.clip_image_load_from_bytes(
36533653
ctypes.create_string_buffer(img_bytes, len(img_bytes)),
36543654
ctypes.c_size_t(len(img_bytes)),
36553655
img_u8_p,
36563656
):
3657-
self._llava_cpp.clip_image_u8_free(img_u8_p)
3657+
self._mtmd_cpp.clip_image_u8_free(img_u8_p)
36583658
raise ValueError("Failed to load image.")
36593659

3660-
img_f32_p = self._llava_cpp.clip_image_f32_batch_init()
3661-
if not self._llava_cpp.clip_image_preprocess(self.clip_ctx, img_u8_p, img_f32_p):
3662-
self._llava_cpp.clip_image_f32_batch_free(img_f32_p)
3663-
self._llava_cpp.clip_image_u8_free(img_u8_p)
3660+
img_f32_p = self._mtmd_cpp.clip_image_f32_batch_init()
3661+
if not self._mtmd_cpp.clip_image_preprocess(self.clip_ctx, img_u8_p, img_f32_p):
3662+
self._mtmd_cpp.clip_image_f32_batch_free(img_f32_p)
3663+
self._mtmd_cpp.clip_image_u8_free(img_u8_p)
36643664
raise ValueError("Failed to preprocess image.")
36653665

36663666
n_embd = llama_cpp.llama_model_n_embd(llama._model.model)
36673667
embed = (ctypes.c_float * (n_tokens * n_embd))()
3668-
if not self._llava_cpp.clip_image_batch_encode(self.clip_ctx, llama.n_threads, img_f32_p, embed):
3669-
self._llava_cpp.clip_image_f32_batch_free(img_f32_p)
3670-
self._llava_cpp.clip_image_u8_free(img_u8_p)
3668+
if not self._mtmd_cpp.clip_image_batch_encode(self.clip_ctx, llama.n_threads, img_f32_p, embed):
3669+
self._mtmd_cpp.clip_image_f32_batch_free(img_f32_p)
3670+
self._mtmd_cpp.clip_image_u8_free(img_u8_p)
36713671
raise ValueError("Failed to encode image.")
36723672

3673-
self._llava_cpp.clip_image_f32_batch_free(img_f32_p)
3674-
self._llava_cpp.clip_image_u8_free(img_u8_p)
3673+
self._mtmd_cpp.clip_image_f32_batch_free(img_f32_p)
3674+
self._mtmd_cpp.clip_image_u8_free(img_u8_p)
36753675
llama_cpp.llama_set_causal_attn(llama.ctx, False)
36763676

36773677
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)