Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add perplexity example #313

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

feat: add perplexity example #313

wants to merge 1 commit into from

Conversation

AlpinDale
Copy link
Member

This PR adds an example to calculate model perplexity, this approach performs it by using prompt_logprobs:

  • Generate text using a dataset and extract 1 prompt logprob per token.
  • Calculate the mean of the logprobs.
  • Calculate the exponent of the negative mean of the logprobs.
  • Divide the result by 2.

The last step should technically be unneeded, but to match the perplexity results from llama.cpp, we seem to need the division by two. It still seems unreliable, as Llama-2 7B shows a lower ppx than Mistral 7B, and FP8 KV Cache doesn't change ppx at all.

# Create a tokenizer.
tokenizer = AutoTokenizer.from_pretrained(model_id)

# Tokenize the prompts and discard or truncate any prompts longer than 2048 tokens.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

max_length is different below, maybe you meant 4096?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants