MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / hellaswag_evaluate_tokens

Function hellaswag_evaluate_tokens

examples/perplexity/perplexity.cpp:424–444  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

422}
423
424static std::vector<float> hellaswag_evaluate_tokens(
425 llama_context * ctx, std::vector<int> & tokens, int n_past, int n_batch, int n_vocab
426) {
427 std::vector<float> result;
428 result.reserve(tokens.size() * n_vocab);
429 size_t n_chunk = (tokens.size() + n_batch - 1)/n_batch;
430 for (size_t i_chunk = 0; i_chunk < n_chunk; ++i_chunk) {
431 size_t n_tokens = tokens.size() - i_chunk * n_batch;
432 n_tokens = std::min(n_tokens, size_t(n_batch));
433 if (llama_decode(ctx, llama_batch_get_one(tokens.data() + i_chunk * n_batch, n_tokens, n_past, 0))) {
434 fprintf(stderr, "%s : failed to eval\n", __func__);
435 return {};
436 }
437
438 const auto logits = llama_get_logits(ctx);
439 result.insert(result.end(), logits, logits + n_tokens * n_vocab);
440
441 n_past += n_tokens;
442 }
443 return result;
444}
445
446static void hellaswag_score(llama_context * ctx, const gpt_params & params) {
447 // Calculates hellaswag score (acc_norm) from prompt

Callers 1

hellaswag_scoreFunction · 0.85

Calls 10

minFunction · 0.85
fprintfFunction · 0.85
reserveMethod · 0.80
llama_decodeFunction · 0.50
llama_batch_get_oneFunction · 0.50
llama_get_logitsFunction · 0.50
sizeMethod · 0.45
dataMethod · 0.45
insertMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected