Skip to content

Commit 14a51f4

Browse files
committed
fix: add compatibility with v0.3.9 for Gemma3ChatHandler
1 parent 0a929e1 commit 14a51f4

File tree

2 files changed

+10
-39
lines changed

2 files changed

+10
-39
lines changed

llama_cpp/llama_chat_format.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3468,8 +3468,7 @@ def eval_image(self, llama: llama.Llama, image_url: str):
34683468
self._llava_cpp.clip_image_u8_free(img_u8_p)
34693469
raise ValueError("Failed to load image.")
34703470

3471-
img_f32 = self._llava_cpp.clip_image_f32_batch()
3472-
img_f32_p = ctypes.byref(img_f32)
3471+
img_f32_p = self._llava_cpp.clip_image_f32_batch_init()
34733472
if not self._llava_cpp.clip_image_preprocess(self.clip_ctx, img_u8_p, img_f32_p):
34743473
self._llava_cpp.clip_image_f32_batch_free(img_f32_p)
34753474
self._llava_cpp.clip_image_u8_free(img_u8_p)

llama_cpp/llava_cpp.py

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -142,28 +142,6 @@ def llava_eval_image_embed(
142142
################################################
143143

144144

145-
# struct clip_image_u8_batch {
146-
# struct clip_image_u8 * data;
147-
# size_t size;
148-
# };
149-
class clip_image_u8_batch(Structure):
150-
_fields_ = [
151-
("data", c_void_p),
152-
("size", c_size_t),
153-
]
154-
155-
156-
# struct clip_image_f32_batch {
157-
# struct clip_image_f32 * data;
158-
# size_t size;
159-
# };
160-
class clip_image_f32_batch(Structure):
161-
_fields_ = [
162-
("data", c_void_p),
163-
("size", c_size_t),
164-
]
165-
166-
167145
# /** load mmproj model */
168146
# CLIP_API struct clip_ctx * clip_model_load (const char * fname, int verbosity);
169147
@ctypes_function("clip_model_load", [c_char_p, c_int], clip_ctx_p_ctypes)
@@ -192,21 +170,15 @@ def clip_image_u8_free(img: c_void_p, /):
192170
...
193171

194172

195-
# CLIP_API void clip_image_f32_free(struct clip_image_f32 * img);
196-
@ctypes_function("clip_image_f32_free", [c_void_p], None)
197-
def clip_image_f32_free(img: c_void_p, /):
198-
...
199-
200-
201-
# CLIP_API void clip_image_u8_batch_free (struct clip_image_u8_batch * batch);
202-
@ctypes_function("clip_image_u8_batch_free", [POINTER(clip_image_u8_batch)], None)
203-
def clip_image_u8_batch_free(batch: "_Pointer[clip_image_u8_batch]", /):
173+
# CLIP_API struct clip_image_f32_batch * clip_image_f32_batch_init();
174+
@ctypes_function("clip_image_f32_batch_init", [], c_void_p)
175+
def clip_image_f32_batch_init() -> Optional[c_void_p]:
204176
...
205177

206178

207179
# CLIP_API void clip_image_f32_batch_free(struct clip_image_f32_batch * batch);
208-
@ctypes_function("clip_image_f32_batch_free", [POINTER(clip_image_f32_batch)], None)
209-
def clip_image_f32_batch_free(batch: "_Pointer[clip_image_f32_batch]", /):
180+
@ctypes_function("clip_image_f32_batch_free", [c_void_p], None)
181+
def clip_image_f32_batch_free(batch: c_void_p, /):
210182
...
211183

212184

@@ -217,14 +189,14 @@ def clip_image_f32_batch_free(batch: "_Pointer[clip_image_f32_batch]", /):
217189
[
218190
clip_ctx_p_ctypes,
219191
c_void_p,
220-
POINTER(clip_image_f32_batch),
192+
c_void_p,
221193
],
222194
c_bool,
223195
)
224196
def clip_image_preprocess(
225197
ctx: clip_ctx_p,
226198
img: c_void_p,
227-
res_imgs: "_Pointer[clip_image_f32_batch]",
199+
res_imgs: c_void_p,
228200
/,
229201
) -> bool:
230202
...
@@ -236,15 +208,15 @@ def clip_image_preprocess(
236208
[
237209
clip_ctx_p_ctypes,
238210
c_int,
239-
POINTER(clip_image_f32_batch),
211+
c_void_p,
240212
POINTER(c_float),
241213
],
242214
c_bool,
243215
)
244216
def clip_image_batch_encode(
245217
ctx: clip_ctx_p,
246218
n_threads: c_int,
247-
imgs: "_Pointer[clip_image_f32_batch]",
219+
imgs: c_void_p,
248220
vec: c_void_p,
249221
/,
250222
) -> bool:

0 commit comments

Comments
 (0)