8000 Add support for batch size to `--perplexity` by glinscott · Pull Request #407 · ggml-org/llama.cpp · GitHub
[go: up one dir, main page]

Skip to content

Add support for batch size to --perplexity #407

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

Merged
merged 10 commits into from
Apr 13, 2023
Prev Previous commit
Next Next commit
Merge branch 'master' into batch_perplexity
  • Loading branch information
glinscott committed Apr 3, 2023
commit a17e745b6e2169daa394613bf2dbad1cee79a2bf
3 changes: 2 additions & 1 deletion examples/perplexity/perplexity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ void perplexity(llama_context * ctx, const gpt_params & params) {
int seq_count = tokens.size() / params.n_ctx;
int n_vocab = llama_n_vocab(ctx);

double nll = 0.0;
fprintf(stderr, "%s : calculating perplexity over %d chunks, batch_size=%d\n", __func__, seq_count, params.n_batch);

for (int i = 0; i < seq_count; ++i) {
Expand Down Expand Up @@ -71,7 +72,7 @@ void perplexity(llama_context * ctx, const gpt_params & params) {
std::vector<float> tok_logits(
logits.begin() + j * n_vocab,
logits.begin() + (j + 1) * n_vocab);
double prob = softmax(tok_logits)[tokens[start + j + 1]];
float prob = softmax(tok_logits)[tokens[start + j + 1]];
nll += -std::log(prob);
++count;
}
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0