| 710 | } |
| 711 | |
| 712 | float * llama_context::get_logits_ith(int32_t i) { |
| 713 | int64_t j = -1; |
| 714 | |
| 715 | output_reorder(); |
| 716 | |
| 717 | try { |
| 718 | if (logits == nullptr) { |
| 719 | throw std::runtime_error("no logits"); |
| 720 | } |
| 721 | |
| 722 | // TODO: use output_resolve_row() |
| 723 | if (i < 0) { |
| 724 | j = n_outputs + i; |
| 725 | if (j < 0) { |
| 726 | throw std::runtime_error(format("negative index out of range [0, %d)", n_outputs)); |
| 727 | } |
| 728 | } else if ((size_t) i >= output_ids.size()) { |
| 729 | throw std::runtime_error(format("out of range [0, %zu)", output_ids.size())); |
| 730 | } else { |
| 731 | j = output_ids[i]; |
| 732 | } |
| 733 | |
| 734 | if (j < 0) { |
| 735 | throw std::runtime_error(format("batch.logits[%d] != true", i)); |
| 736 | } |
| 737 | if (j >= n_outputs) { |
| 738 | // This should not happen |
| 739 | throw std::runtime_error(format("corrupt output buffer (j=%" PRId64 ", n_outputs=%d)", j, n_outputs)); |
| 740 | } |
| 741 | |
| 742 | return logits + j*model.vocab.n_tokens(); |
| 743 | } catch (const std::exception & err) { |
| 744 | LLAMA_LOG_ERROR("%s: invalid logits id %d, reason: %s\n", __func__, i, err.what()); |
| 745 | #ifndef NDEBUG |
| 746 | GGML_ABORT("fatal error"); |
| 747 | #else |
| 748 | return nullptr; |
| 749 | #endif |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | float * llama_context::get_embeddings() { |
| 754 | output_reorder(); |
no test coverage detected