File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -638,7 +638,7 @@ def _create_completion(
638638 for token in all_tokens
639639 ]
640640 all_logprobs = [
641- [ Llama .logit_to_logprob ( logit ) for logit in row ]
641+ Llama ._logits_to_logprobs ( row )
642642 for row in self .eval_logits
643643 ]
644644 for token , token_str , logprobs_token in zip (
@@ -980,5 +980,7 @@ def token_bos() -> llama_cpp.llama_token:
980980 return llama_cpp .llama_token_bos ()
981981
982982 @staticmethod
983- def logit_to_logprob (x : float ) -> float :
984- return math .log (1.0 + math .exp (x ))
983+ def logits_to_logprobs (logits : List [llama_cpp .c_float ]) -> List [llama_cpp .c_float ]:
984+ exps = [math .exp (float (x )) for x in logits ]
985+ sum_exps = sum (exps )
986+ return [llama_cpp .c_float (math .log (x / sum_exps )) for x in exps ]
You can’t perform that action at this time.
0 commit comments