Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions llama_cpp/llama.py
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,7 @@ def logit_bias_processor(
token_logprobs: List[Optional[float]] = []
tokens: List[str] = []
top_logprobs: List[Optional[Dict[str, float]]] = []
top_logprob_tokens: List[Optional[Dict[int, float]]] = []

if echo:
# Remove leading BOS token if exists
Expand Down Expand Up @@ -1777,8 +1778,13 @@ def logit_bias_processor(
): logprob
for logprob, i in sorted_logprobs[:logprobs]
}
top_logprob_token: Optional[Dict[int, float]] = {
i: logprob for logprob, i in sorted_logprobs[:logprobs]
}
top_logprob.update({token_str: logprobs_token[int(token)]})
top_logprob_token.update({token: logprobs_token[int(token)]})
top_logprobs.append(top_logprob)
top_logprob_tokens.append(top_logprob_token)
# Weird idosincracy of the OpenAI API where
# token_logprobs and top_logprobs are null for
# the first token.
Expand All @@ -1790,6 +1796,8 @@ def logit_bias_processor(
"text_offset": text_offsets,
"token_logprobs": token_logprobs,
"top_logprobs": top_logprobs,
"top_logprob_tokens": top_logprob_tokens,
"all_logprobs": all_logprobs,
}

yield {
Expand Down