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

Function llama_byte_to_token

llama.cpp:7053–7066  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7051}
7052
7053static llama_token llama_byte_to_token(const llama_vocab & vocab, uint8_t ch) {
7054 static const char * hex = "0123456789ABCDEF";
7055 switch (llama_vocab_get_type(vocab)) {
7056 case LLAMA_VOCAB_TYPE_SPM: {
7057 const char buf[7] = { '<', '0', 'x', hex[ch >> 4], hex[ch & 15], '>', 0 };
7058 return vocab.token_to_id.at(buf);
7059 }
7060 case LLAMA_VOCAB_TYPE_BPE: {
7061 return vocab.token_to_id.at(bytes_to_unicode_bpe(ch));
7062 }
7063 default:
7064 GGML_ASSERT(false);
7065 }
7066}
7067
7068static void llama_escape_whitespace(std::string & text) {
7069 replace_all(text, " ", "\xe2\x96\x81");

Callers 2

llm_load_vocabFunction · 0.85
resegmentMethod · 0.85

Calls 2

llama_vocab_get_typeFunction · 0.85
bytes_to_unicode_bpeFunction · 0.85

Tested by

no test coverage detected