| 7034 | } |
| 7035 | |
| 7036 | static uint8_t llama_token_to_byte(const llama_vocab& vocab, llama_token id) { |
| 7037 | GGML_ASSERT(llama_is_byte_token(vocab, id)); |
| 7038 | const auto& token_data = vocab.id_to_token.at(id); |
| 7039 | switch (llama_vocab_get_type(vocab)) { |
| 7040 | case LLAMA_VOCAB_TYPE_SPM: { |
| 7041 | auto buf = token_data.text.substr(3, 2); |
| 7042 | return strtol(buf.c_str(), NULL, 16); |
| 7043 | } |
| 7044 | case LLAMA_VOCAB_TYPE_BPE: { |
| 7045 | GGML_ASSERT(false); |
| 7046 | return unicode_to_bytes_bpe(token_data.text); |
| 7047 | } |
| 7048 | default: |
| 7049 | GGML_ASSERT(false); |
| 7050 | } |
| 7051 | } |
| 7052 | |
| 7053 | static llama_token llama_byte_to_token(const llama_vocab & vocab, uint8_t ch) { |
| 7054 | static const char * hex = "0123456789ABCDEF"; |
no test coverage detected