| 657 | |
| 658 | template <typename C, typename B> |
| 659 | inline std::string LOG_BATCH_TOSTR_PRETTY(const C & ctx, const B & batch) |
| 660 | { |
| 661 | std::stringstream buf; |
| 662 | buf << "[ "; |
| 663 | |
| 664 | bool first = true; |
| 665 | for (int i = 0; i < batch.n_tokens; ++i) |
| 666 | { |
| 667 | if (!first) { |
| 668 | buf << ", "; |
| 669 | } else { |
| 670 | first = false; |
| 671 | } |
| 672 | |
| 673 | auto detokenized = llama_token_to_piece(ctx, batch.token[i]); |
| 674 | |
| 675 | detokenized.erase( |
| 676 | std::remove_if( |
| 677 | detokenized.begin(), |
| 678 | detokenized.end(), |
| 679 | [](const unsigned char c) { return !std::isprint(c); }), |
| 680 | detokenized.end()); |
| 681 | |
| 682 | buf |
| 683 | << "\n" << std::to_string(i) |
| 684 | << ":token '" << detokenized << "'" |
| 685 | << ":pos " << std::to_string(batch.pos[i]) |
| 686 | << ":n_seq_id " << std::to_string(batch.n_seq_id[i]) |
| 687 | << ":seq_id " << std::to_string(batch.seq_id[i][0]) |
| 688 | << ":logits " << std::to_string(batch.logits[i]); |
| 689 | } |
| 690 | buf << " ]"; |
| 691 | |
| 692 | return buf.str(); |
| 693 | } |
| 694 | |
| 695 | #ifdef LOG_DISABLE_LOGS |
| 696 |
nothing calls this directly
no test coverage detected