Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Logprobs incorrectly computed from logits #134

Copy link
Copy link
Closed
@alex-lew

Description

@alex-lew
Issue body actions

Hi, thanks for these very useful bindings! It's made playing with llama.cpp much easier :-)

I noticed that the current implementation of the logprobs option in the completion API uses Llama.logit_to_logprob to convert the logits reported by llama.cpp into logprobs. This sends each logit $x$ to $\log(e^{x} + 1)$.

def logit_to_logprob(x: float) -> float:
    return math.log(1.0 + math.exp(x))

However, because the logits produced by LLaMA parameterize a Categorical distribution, I believe we must take their softmax to get the correct logprob: we should map each logit $x_i$ to $\log(\frac{e^x_i}{\sum_{j \in {1, \dots, V}} e^{x_j}})$. That is, we should take the elementwise exp of the entire vector of logprobs, and then renormalize so they sum to 1, before taking their elementwise log.

abetlen

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.