8000 fix: Remove deprecated cfg sampling functions · coderonion/llama-cpp-python@8c71725 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8c71725

Browse files
committed
fix: Remove deprecated cfg sampling functions
1 parent 727d60c commit 8c71725

File tree

2 files changed

+1
-50
lines changed

2 files changed

+1
-50
lines changed

llama_cpp/_internals.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -357,21 +357,6 @@ def sample_repetition_penalties(
357357
penalty_present,
358358
)
359359

360-
def sample_classifier_free_guidance(
361-
self,
362-
candidates: "_LlamaTokenDataArray",
363-
guidance_ctx: "_LlamaContext",
364-
scale: float,
365-
):
366-
assert self.ctx is not None
367-
assert guidance_ctx.ctx is not None
368-
llama_cpp.llama_sample_classifier_free_guidance(
369-
self.ctx,
370-
llama_cpp.byref(candidates.candidates),
371-
guidance_ctx.ctx,
372-
scale,
373-
)
374-
375360
def sample_softmax(self, candidates: "_LlamaTokenDataArray"):
376361
assert self.ctx is not None
377362
llama_cpp.llama_sample_softmax(
@@ -720,7 +705,7 @@ def prev_str(self, ctx_main: _LlamaContext, n: int) -> str:
720705
return ctx_main.model.detokenize(self.prev[-n:]).decode("utf-8")
721706

722707
def sample(
723-
self, ctx_main: _LlamaContext, ctx_cfg: Optional[_LlamaContext] = None, idx: int = 0, logits_array: Optional[npt.NDArray[np.single]] = None
708+
self, ctx_main: _LlamaContext, idx: int = 0, logits_array: Optional[npt.NDArray[np.single]] = None
724709
):
725710
n_vocab = ctx_main.model.n_vocab()
726711
id: int = 0
@@ -741,11 +726,6 @@ def sample(
741726
) # TODO: Only create this once
742727
token_data_array.copy_logits(logits_array)
743728

744-
if ctx_cfg is not None:
745-
ctx_main.sample_classifier_free_guidance(
746-
token_data_array, ctx_cfg, self.params.cfg_scale
747-
)
748-
749729
# apply penalties
750730
if len(self.prev) > 0:
751731
nl_token = ctx_main.model.token_nl()

llama_cpp/llama_cpp.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,35 +2129,6 @@ def llama_sample_apply_guidance(
21292129
...
21302130

21312131

2132-
# LLAMA_API DEPRECATED(void llama_sample_classifier_free_guidance(
2133-
# struct llama_context * ctx,
2134-
# llama_token_data_array * candidates,
2135-
# struct llama_context * guidance_ctx,
2136-
# float scale),
2137-
# "use llama_sample_apply_guidance() instead");
2138-
@ctypes_function(
2139-
"llama_sample_classifier_free_guidance",
2140-
[
2141-
llama_context_p_ctypes,
2142-
llama_token_data_array_p,
2143-
llama_context_p_ctypes,
2144-
ctypes.c_float,
2145-
],
2146-
None,
2147-
)
2148-
def llama_sample_classifier_free_guidance(
2149-
ctx: llama_context_p,
2150-
candidates: Union[
2151-
CtypesArray[llama_token_data_array], CtypesPointerOrRef[llama_token_data_array]
2152-
],
2153-
guidance_ctx: llama_context_p,
2154-
scale: Union[ctypes.c_float, float],
2155-
/,
2156-
):
2157-
"""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"""
2158-
...
2159-
2160-
21612132
# /// @details Sorts candidate tokens by their logits in descending order and calculate probabilities based on logits.
21622133
# LLAMA_API void llama_sample_softmax(
21632134
# struct llama_context * ctx,

0 commit comments

Comments
 (0)
0