Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 53861c9

Browse filesBrowse files
committed
Update llama.cpp
1 parent acf50f1 commit 53861c9
Copy full SHA for 53861c9

File tree

Expand file treeCollapse file tree

3 files changed

+73
-103
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+73
-103
lines changed

‎llama_cpp/llama.py

Copy file name to clipboardExpand all lines: llama_cpp/llama.py
+11-17Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -595,20 +595,14 @@ def _sample(
595595
candidates.data = candidates_data.ctypes.data_as(llama_cpp.llama_token_data_p)
596596
candidates.sorted = llama_cpp.c_bool(False)
597597
candidates.size = llama_cpp.c_size_t(n_vocab)
598-
llama_cpp.llama_sample_repetition_penalty(
599-
ctx=self.ctx,
600-
last_tokens_data=last_n_tokens_data,
601-
last_tokens_size=last_n_tokens_size,
602-
candidates=llama_cpp.ctypes.byref(candidates), # type: ignore
603-
penalty=repeat_penalty,
604-
)
605-
llama_cpp.llama_sample_frequency_and_presence_penalties(
598+
llama_cpp.llama_sample_repetition_penalties(
606599
ctx=self.ctx,
607600
candidates=llama_cpp.ctypes.byref(candidates), # type: ignore
608601
last_tokens_data=last_n_tokens_data,
609-
last_tokens_size=last_n_tokens_size,
610-
alpha_frequency=frequency_penalty,
611-
alpha_presence=presence_penalty,
602+
penalty_last_n=last_n_tokens_size,
603+
penalty_repeat=repeat_penalty,
604+
penalty_freq=frequency_penalty,
605+
penalty_present=presence_penalty,
612606
)
613607
if not penalize_nl:
614608
candidates.data[self._token_nl].logit = llama_cpp.c_float(nl_logit)
@@ -1793,18 +1787,18 @@ def tokenizer(self) -> "LlamaTokenizer":
17931787

17941788
def token_eos(self) -> int:
17951789
"""Return the end-of-sequence token."""
1796-
assert self.ctx is not None
1797-
return llama_cpp.llama_token_eos(self.ctx)
1790+
assert self.model is not None
1791+
return llama_cpp.llama_token_eos(self.model)
17981792

17991793
def token_bos(self) -> int:
18001794
"""Return the beginning-of-sequence token."""
1801-
assert self.ctx is not None
1802-
return llama_cpp.llama_token_bos(self.ctx)
1795+
assert self.model is not None
1796+
return llama_cpp.llama_token_bos(self.model)
18031797

18041798
def token_nl(self) -> int:
18051799
"""Return the newline token."""
1806-
assert self.ctx is not None
1807-
return llama_cpp.llama_token_nl(self.ctx)
1800+
assert self.model is not None
1801+
return llama_cpp.llama_token_nl(self.model)
18081802

18091803
@staticmethod
18101804
def logits_to_logprobs(logits: List[float]) -> List[float]:

‎llama_cpp/llama_cpp.py

Copy file name to clipboardExpand all lines: llama_cpp/llama_cpp.py
+61-85Lines changed: 61 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,97 +1180,97 @@ def llama_get_embeddings(
11801180
# //
11811181

11821182

1183-
# LLAMA_API const char * llama_token_get_text(const struct llama_context * ctx, llama_token token);
1184-
def llama_token_get_text(ctx: llama_context_p, token: llama_token) -> bytes:
1185-
return _lib.llama_token_get_text(ctx, token)
1183+
# LLAMA_API const char * llama_token_get_text(const struct llama_model * model, llama_token token);
1184+
def llama_token_get_text(model: llama_model_p, token: llama_token) -> bytes:
1185+
return _lib.llama_token_get_text(model, token)
11861186

11871187

1188-
_lib.llama_token_get_text.argtypes = [llama_context_p, llama_token]
1188+
_lib.llama_token_get_text.argtypes = [llama_model_p, llama_token]
11891189
_lib.llama_token_get_text.restype = c_char_p
11901190

11911191

1192-
# LLAMA_API float llama_token_get_score(const struct llama_context * ctx, llama_token token);
1193-
def llama_token_get_score(ctx: llama_context_p, token: llama_token) -> float:
1194-
return _lib.llama_token_get_score(ctx, token)
1192+
# LLAMA_API float llama_token_get_score(const struct llama_model * model, llama_token token);
1193+
def llama_token_get_score(model: llama_model_p, token: llama_token) -> float:
1194+
return _lib.llama_token_get_score(model, token)
11951195

11961196

1197-
_lib.llama_token_get_score.argtypes = [llama_context_p, llama_token]
1197+
_lib.llama_token_get_score.argtypes = [llama_model_p, llama_token]
11981198
_lib.llama_token_get_score.restype = c_float
11991199

12001200

1201-
# LLAMA_API enum llama_token_type llama_token_get_type(const struct llama_context * ctx, llama_token token);
1202-
def llama_token_get_type(ctx: llama_context_p, token: llama_token) -> int:
1203-
return _lib.llama_token_get_type(ctx, token)
1201+
# LLAMA_API enum llama_token_type llama_token_get_type(const struct llama_model * model, llama_token token);
1202+
def llama_token_get_type(model: llama_model_p, token: llama_token) -> int:
1203+
return _lib.llama_token_get_type(model, token)
12041204

12051205

1206-
_lib.llama_token_get_type.argtypes = [llama_context_p, llama_token]
1206+
_lib.llama_token_get_type.argtypes = [llama_model_p, llama_token]
12071207
_lib.llama_token_get_type.restype = ctypes.c_int
12081208

12091209

12101210
# // Special tokens
12111211

12121212

1213-
# LLAMA_API llama_token llama_token_bos(const struct llama_context * ctx); // beginning-of-sentence
1214-
def llama_token_bos(ctx: llama_context_p) -> int:
1215-
return _lib.llama_token_bos(ctx)
1213+
# LLAMA_API llama_token llama_token_bos(const struct llama_model * model); // beginning-of-sentence
1214+
def llama_token_bos(model: llama_model_p) -> int:
1215+
return _lib.llama_token_bos(model)
12161216

12171217

1218-
_lib.llama_token_bos.argtypes = [llama_context_p]
1218+
_lib.llama_token_bos.argtypes = [llama_model_p]
12191219
_lib.llama_token_bos.restype = llama_token
12201220

12211221

1222-
# LLAMA_API llama_token llama_token_eos(const struct llama_context * ctx); // end-of-sentence
1223-
def llama_token_eos(ctx: llama_context_p) -> int:
1224-
return _lib.llama_token_eos(ctx)
1222+
# LLAMA_API llama_token llama_token_eos(const struct llama_model * model); // end-of-sentence
1223+
def llama_token_eos(model: llama_model_p) -> int:
1224+
return _lib.llama_token_eos(model)
12251225

12261226

1227-
_lib.llama_token_eos.argtypes = [llama_context_p]
1227+
_lib.llama_token_eos.argtypes = [llama_model_p]
12281228
_lib.llama_token_eos.restype = llama_token
12291229

12301230

1231-
# LLAMA_API llama_token llama_token_nl (const struct llama_context * ctx); // next-line
1232-
def llama_token_nl(ctx: llama_context_p) -> int:
1233-
return _lib.llama_token_nl(ctx)
1231+
# LLAMA_API llama_token llama_token_nl (const struct llama_model * model); // next-line
1232+
def llama_token_nl(model: llama_model_p) -> int:
1233+
return _lib.llama_token_nl(model)
12341234

12351235

1236-
_lib.llama_token_nl.argtypes = [llama_context_p]
1236+
_lib.llama_token_nl.argtypes = [llama_model_p]
12371237
_lib.llama_token_nl.restype = llama_token
12381238

12391239

12401240
# // codellama infill tokens
1241-
# LLAMA_API llama_token llama_token_prefix(const struct llama_context * ctx); // Beginning of infill prefix
1242-
def llama_token_prefix(ctx: llama_context_p) -> int:
1243-
return _lib.llama_token_prefix(ctx)
1241+
# LLAMA_API llama_token llama_token_prefix(const struct llama_model * model); // Beginning of infill prefix
1242+
def llama_token_prefix(model: llama_model_p) -> int:
1243+
return _lib.llama_token_prefix(model)
12441244

12451245

1246-
_lib.llama_token_prefix.argtypes = [llama_context_p]
1246+
_lib.llama_token_prefix.argtypes = [llama_model_p]
12471247
_lib.llama_token_prefix.restype = llama_token
12481248

12491249

1250-
# LLAMA_API llama_token llama_token_middle(const struct llama_context * ctx); // Beginning of infill middle
1251-
def llama_token_middle(ctx: llama_context_p) -> int:
1252-
return _lib.llama_token_middle(ctx)
1250+
# LLAMA_API llama_token llama_token_middle(const struct llama_model * model); // Beginning of infill middle
1251+
def llama_token_middle(model: llama_model_p) -> int:
1252+
return _lib.llama_token_middle(model)
12531253

12541254

1255-
_lib.llama_token_middle.argtypes = [llama_context_p]
1255+
_lib.llama_token_middle.argtypes = [llama_model_p]
12561256
_lib.llama_token_middle.restype = llama_token
12571257

12581258

1259-
# LLAMA_API llama_token llama_token_suffix(const struct llama_context * ctx); // Beginning of infill suffix
1260-
def llama_token_suffix(ctx: llama_context_p) -> int:
1261-
return _lib.llama_token_suffix(ctx)
1259+
# LLAMA_API llama_token llama_token_suffix(const struct llama_model * model); // Beginning of infill suffix
1260+
def llama_token_suffix(model: llama_model_p) -> int:
1261+
return _lib.llama_token_suffix(model)
12621262

12631263

1264-
_lib.llama_token_suffix.argtypes = [llama_context_p]
1264+
_lib.llama_token_suffix.argtypes = [llama_model_p]
12651265
_lib.llama_token_suffix.restype = llama_token
12661266

12671267

1268-
# LLAMA_API llama_token llama_token_eot (const struct llama_context * ctx); // End of infill middle
1269-
def llama_token_eot(ctx: llama_context_p) -> int:
1270-
return _lib.llama_token_eot(ctx)
1268+
# LLAMA_API llama_token llama_token_eot (const struct llama_model * model); // End of infill middle
1269+
def llama_token_eot(model: llama_model_p) -> int:
1270+
return _lib.llama_token_eot(model)
12711271

12721272

1273-
_lib.llama_token_eot.argtypes = [llama_context_p]
1273+
_lib.llama_token_eot.argtypes = [llama_model_p]
12741274
_lib.llama_token_eot.restype = llama_token
12751275

12761276

@@ -1431,70 +1431,46 @@ def llama_set_rng_seed(ctx: llama_context_p, seed: Union[c_uint32, int]):
14311431
_lib.llama_set_rng_seed.restype = None
14321432

14331433

1434-
# @details Repetition penalty described in CTRL academic paper https://arxiv.org/abs/1909.05858, with negative logit fix.
1435-
# LLAMA_API void llama_sample_repetition_penalty(
1434+
# /// @details Repetition penalty described in CTRL academic paper https://arxiv.org/abs/1909.05858, with negative logit fix.
1435+
# /// @details Frequency and presence penalties described in OpenAI API https://platform.openai.com/docs/api-reference/parameter-details.
1436+
# LLAMA_API void llama_sample_repetition_penalties(
14361437
# struct llama_context * ctx,
14371438
# llama_token_data_array * candidates,
14381439
# const llama_token * last_tokens,
1439-
# size_t last_tokens_size,
1440-
# float penalty);
1441-
def llama_sample_repetition_penalty(
1440+
# size_t penalty_last_n,
1441+
# float penalty_repeat,
1442+
# float penalty_freq,
1443+
# float penalty_present);
1444+
def llama_sample_repetition_penalties(
14421445
ctx: llama_context_p,
14431446
candidates, # type: _Pointer[llama_token_data_array]
14441447
last_tokens_data, # type: Array[llama_token]
1445-
last_tokens_size: Union[c_int, int],
1446-
penalty: Union[c_float, float],
1448+
penalty_last_n: Union[c_size_t, int],
1449+
penalty_repeat: Union[c_float, float],
1450+
penalty_freq: Union[c_float, float],
1451+
penalty_present: Union[c_float, float],
14471452
):
1448-
return _lib.llama_sample_repetition_penalty(
1449-
ctx, candidates, last_tokens_data, last_tokens_size, penalty
1450-
)
1451-
1452-
1453-
_lib.llama_sample_repetition_penalty.argtypes = [
1454-
llama_context_p,
1455-
llama_token_data_array_p,
1456-
llama_token_p,
1457-
c_int,
1458-
c_float,
1459-
]
1460-
_lib.llama_sample_repetition_penalty.restype = None
1461-
1462-
1463-
# @details Frequency and presence penalties described in OpenAI API https://platform.openai.com/docs/api-reference/parameter-details.
1464-
# LLAMA_API void llama_sample_frequency_and_presence_penalties(
1465-
# struct llama_context * ctx,
1466-
# llama_token_data_array * candidates,
1467-
# const llama_token * last_tokens,
1468-
# size_t last_tokens_size,
1469-
# float alpha_frequency,
1470-
# float alpha_presence);
1471-
def llama_sample_frequency_and_presence_penalties(
1472-
ctx: llama_context_p,
1473-
candidates, # type: _Pointer[llama_token_data_array]
1474-
last_tokens_data, # type: Array[llama_token]
1475-
last_tokens_size: Union[c_int, int],
1476-
alpha_frequency: Union[c_float, float],
1477-
alpha_presence: Union[c_float, float],
1478-
):
1479-
return _lib.llama_sample_frequency_and_presence_penalties(
1453+
return _lib.llama_sample_repetition_penalties(
14801454
ctx,
14811455
candidates,
14821456
last_tokens_data,
1483-
last_tokens_size,
1484-
alpha_frequency,
1485-
alpha_presence,
1457+
penalty_last_n,
1458+
penalty_repeat,
1459+
penalty_freq,
1460+
penalty_present,
14861461
)
14871462

14881463

1489-
_lib.llama_sample_frequency_and_presence_penalties.argtypes = [
1464+
_lib.llama_sample_repetition_penalties.argtypes = [
14901465
llama_context_p,
14911466
llama_token_data_array_p,
14921467
llama_token_p,
1493-
c_int,
1468+
c_size_t,
1469+
c_float,
14941470
c_float,
14951471
c_float,
14961472
]
1497-
_lib.llama_sample_frequency_and_presence_penalties.restype = None
1473+
_lib.llama_sample_repetition_penalties.restype = None
14981474

14991475

15001476
# /// @details Apply classifier-free guidance to the logits as described in academic paper "Stay on topic with Classifier-Free Guidance" https://arxiv.org/abs/2306.17806

‎vendor/llama.cpp

Copy file name to clipboard

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.