From 9e6b0e9419eb9738af12c8425d979831704c0d4b Mon Sep 17 00:00:00 2001 From: Francis Couture-Harpin Date: Mon, 9 Sep 2024 22:00:37 -0400 Subject: [PATCH] perplexity : revert changes --- examples/perplexity/perplexity.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/perplexity/perplexity.cpp b/examples/perplexity/perplexity.cpp index ab5c51352..570ee8aeb 100644 --- a/examples/perplexity/perplexity.cpp +++ b/examples/perplexity/perplexity.cpp @@ -583,9 +583,7 @@ static results_perplexity perplexity(llama_context * ctx, const gpt_params & par int n_outputs = 0; - // clear the batch - llama_batch_clear(batch); - + batch.n_tokens = 0; for (int seq = 0; seq < n_seq_batch; seq++) { int seq_start = batch_start + seq*n_ctx; @@ -598,10 +596,16 @@ static results_perplexity perplexity(llama_context * ctx, const gpt_params & par } for (int k = 0; k < batch_size; ++k) { - llama_pos pos = j*n_batch + k; - llama_batch_add(batch, tokens[seq_start + k], pos, { seq }, pos >= first); - n_outputs += (int) (pos >= first); + const int idx = seq*n_ctx + k; + batch.token [idx] = tokens[seq_start + k]; + batch.pos [idx] = j*n_batch + k; + batch.n_seq_id[idx] = 1; + batch.seq_id [idx][0] = seq; + batch.logits [idx] = batch.pos[idx] >= first ? 1 : 0; + + n_outputs += batch.logits[idx] != 0; } + batch.n_tokens += batch_size; // restore the original token in case it was set to BOS tokens[seq_start] = token_org;