File tree Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Expand file tree Collapse file tree 1 file changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -730,12 +730,14 @@ def sample(
730
730
if len (self .prev ) > 0 :
731
731
nl_token = ctx_main .model .token_nl ()
947F
code>
732
732
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 )
734
737
ctx_main .sample_repetition_penalties (
735
738
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 ,
739
741
self .params .penalty_repeat ,
740
742
self .params .penalty_freq ,
741
743
self .params .penalty_present ,
You can’t perform that action at this time.
0 commit comments