Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 62aad61

Browse files
ymikhailovymikhaylovabetlen
authored
fix: last tokens passing to sample_repetition_penalties function (abetlen#1295)
Co-authored-by: ymikhaylov <[email protected]> Co-authored-by: Andrei <[email protected]>
1 parent 45bf5ae commit 62aad61

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

llama_cpp/_internals.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -730,12 +730,14 @@ def sample(
730730
if len(self.prev) > 0:
731731
nl_token = ctx_main.model.token_nl()
732732
nl_logit = logits_array[nl_token]
733-
if self.params.penalty_last_n > 0:
733+
last_tokens = self.prev[-self.params.penalty_last_n:]
734+
last_tokens_size = min(len(last_tokens), self.params.penalty_last_n)
735+
if last_tokens_size > 0:
736+
last_tokens_p = (llama_cpp.llama_token * len(last_tokens))(*last_tokens)
734737
ctx_main.sample_repetition_penalties(
735738
token_data_array,
736-
# TODO: Only create this once
737-
(llama_cpp.llama_token * len(self.prev))(*self.prev),
738-
self.params.penalty_last_n,
739+
last_tokens_p,
740+
last_tokens_size,
739741
self.params.penalty_repeat,
740742
self.params.penalty_freq,
741743
self.params.penalty_present,

0 commit comments

Comments
 (0)