Skip to content

Commit d561b7f

Browse files
authored
llama.cpp : fix the fix of bpe tokenizer
1 parent a95ae75 commit d561b7f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

llama.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2839,6 +2839,13 @@ static bool llama_is_pad_token(const llama_vocab & vocab, llama_token id ) {
28392839
}
28402840

28412841
static uint8_t llama_token_to_byte(const llama_vocab & vocab, llama_token id) {
2842+
GGML_ASSERT(llama_is_byte_token(vocab, id));
2843+
const auto& token_data = vocab.id_to_token.at(id);
2844+
auto buf = token_data.text.substr(3, 2);
2845+
return strtol(buf.c_str(), NULL, 16);
2846+
}
2847+
2848+
static llama_token llama_byte_to_token(const llama_vocab & vocab, uint8_t ch) {
28422849
if (vocab.type == LLAMA_VOCAB_TYPE_SPM) {
28432850
char buf[7];
28442851
int result = snprintf(buf, sizeof(buf), "<0x%02X>", ch);
@@ -2849,13 +2856,6 @@ static uint8_t llama_token_to_byte(const llama_vocab & vocab, llama_token id) {
28492856
return vocab.token_to_id.at(std::string(1, ch));
28502857
}
28512858

2852-
static llama_token llama_byte_to_token(const llama_vocab & vocab, uint8_t ch) {
2853-
char buf[7];
2854-
int result = snprintf(buf, sizeof(buf), "<0x%02X>", ch);
2855-
GGML_ASSERT(0 <= result && result < 7);
2856-
return vocab.token_to_id.at(buf);
2857-
}
2858-
28592859
static std::string llama_escape_whitespace(const std::string& text) {
28602860
std::string result;
28612861
bool escaping = false;

0 commit comments

Comments
 (0)