Skip to content

Commit e72f586

Browse files
committed
Change pointer to lower overhead byref
1 parent 14da46f commit e72f586

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

llama_cpp/llama.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -295,47 +295,47 @@ def _sample_top_p_top_k(
295295
ctx=self.ctx,
296296
last_tokens_data=last_n_tokens_data,
297297
last_tokens_size=last_n_tokens_size,
298-
candidates=llama_cpp.ctypes.pointer(candidates),
298+
candidates=llama_cpp.ctypes.byref(candidates), # type: ignore
299299
penalty=repeat_penalty,
300300
)
301301
if float(temp.value) == 0.0:
302302
return llama_cpp.llama_sample_token_greedy(
303303
ctx=self.ctx,
304-
candidates=llama_cpp.ctypes.pointer(candidates),
304+
candidates=llama_cpp.ctypes.byref(candidates), # type: ignore
305305
)
306306
else:
307307
llama_cpp.llama_sample_top_k(
308308
ctx=self.ctx,
309-
candidates=llama_cpp.ctypes.pointer(candidates),
309+
candidates=llama_cpp.ctypes.byref(candidates), # type: ignore
310310
k=top_k,
311311
min_keep=llama_cpp.c_size_t(1),
312312
)
313313
llama_cpp.llama_sample_tail_free(
314314
ctx=self.ctx,
315-
candidates=llama_cpp.ctypes.pointer(candidates),
315+
candidates=llama_cpp.ctypes.byref(candidates), # type: ignore
316316
z=llama_cpp.c_float(1.0),
317317
min_keep=llama_cpp.c_size_t(1),
318318
)
319319
llama_cpp.llama_sample_typical(
320320
ctx=self.ctx,
321-
candidates=llama_cpp.ctypes.pointer(candidates),
321+
candidates=llama_cpp.ctypes.byref(candidates), # type: ignore
322322
p=llama_cpp.c_float(1.0),
323323
min_keep=llama_cpp.c_size_t(1),
324324
)
325325
llama_cpp.llama_sample_top_p(
326326
ctx=self.ctx,
327-
candidates=llama_cpp.ctypes.pointer(candidates),
327+
candidates=llama_cpp.ctypes.byref(candidates), # type: ignore
328328
p=top_p,
329329
min_keep=llama_cpp.c_size_t(1),
330330
)
331331
llama_cpp.llama_sample_temperature(
332332
ctx=self.ctx,
333-
candidates=llama_cpp.ctypes.pointer(candidates),
333+
candidates=llama_cpp.ctypes.byref(candidates), # type: ignore
334334
temp=temp,
335335
)
336336
return llama_cpp.llama_sample_token(
337337
ctx=self.ctx,
338-
candidates=llama_cpp.ctypes.pointer(candidates),
338+
candidates=llama_cpp.ctypes.byref(candidates), # type: ignore
339339
)
340340

341341
def sample(

0 commit comments

Comments
 (0)