| 422 | } |
| 423 | |
| 424 | static 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 | |
| 446 | static void hellaswag_score(llama_context * ctx, const gpt_params & params) { |
| 447 | // Calculates hellaswag score (acc_norm) from prompt |
no test coverage detected