We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c088a2b commit b6747f7Copy full SHA for b6747f7
llama_cpp/llama.py
@@ -638,7 +638,7 @@ def _create_completion(
638
for token in all_tokens
639
]
640
all_logprobs = [
641
- [Llama.logit_to_logprob(logit) for logit in row]
+ Llama._logits_to_logprobs(row)
642
for row in self.eval_logits
643
644
for token, token_str, logprobs_token in zip(
@@ -980,5 +980,7 @@ def token_bos() -> llama_cpp.llama_token:
980
return llama_cpp.llama_token_bos()
981
982
@staticmethod
983
- def logit_to_logprob(x: float) -> float:
984
- return math.log(1.0 + math.exp(x))
+ def logits_to_logprobs(logits: List[llama_cpp.c_float]) -> List[llama_cpp.c_float]:
+ 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]
0 commit comments