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

Function llama_token_to_byte

llama.cpp:7036–7051  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7034}
7035
7036static 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
7053static llama_token llama_byte_to_token(const llama_vocab & vocab, uint8_t ch) {
7054 static const char * hex = "0123456789ABCDEF";

Callers 1

llama_token_to_pieceFunction · 0.85

Calls 5

llama_is_byte_tokenFunction · 0.85
llama_vocab_get_typeFunction · 0.85
unicode_to_bytes_bpeFunction · 0.85
substrMethod · 0.80
c_strMethod · 0.45

Tested by

no test coverage detected