vocab : validate plamo2 byte tokens (#26511)
* validate plamo2 byte tokens * --typo
This commit is contained in:
+12
-7
@@ -1373,8 +1373,10 @@ struct llm_tokenizer_plamo2 : llm_tokenizer {
|
|||||||
if (vocab.is_byte(token_id)) {
|
if (vocab.is_byte(token_id)) {
|
||||||
if (entry.text.length() == 6 && entry.text.substr(0, 3) == "<0x" && entry.text.back() == '>') {
|
if (entry.text.length() == 6 && entry.text.substr(0, 3) == "<0x" && entry.text.back() == '>') {
|
||||||
std::string hex_str = entry.text.substr(3, 2);
|
std::string hex_str = entry.text.substr(3, 2);
|
||||||
int byte_val = std::stoi(hex_str, nullptr, 16);
|
if (std::isxdigit(static_cast<unsigned char>(hex_str[0])) && std::isxdigit(static_cast<unsigned char>(hex_str[1]))) {
|
||||||
bytes_[byte_val] = static_cast<llama_token>(token_id);
|
int byte_val = std::stoi(hex_str, nullptr, 16);
|
||||||
|
bytes_[byte_val] = static_cast<llama_token>(token_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -3625,12 +3627,15 @@ int32_t llama_vocab::impl::token_to_piece(llama_token token, char * buf, int32_t
|
|||||||
if (vocab.is_byte(token)) {
|
if (vocab.is_byte(token)) {
|
||||||
// Handle byte tokens like <0xXX>
|
// Handle byte tokens like <0xXX>
|
||||||
if (token_text.length() == 6 && token_text.substr(0, 3) == "<0x" && token_text.back() == '>') {
|
if (token_text.length() == 6 && token_text.substr(0, 3) == "<0x" && token_text.back() == '>') {
|
||||||
int hex_val = std::stoi(token_text.substr(3, 2), nullptr, 16);
|
std::string hex_str = token_text.substr(3, 2);
|
||||||
if (length < 1) {
|
if (std::isxdigit(static_cast<unsigned char>(hex_str[0])) && std::isxdigit(static_cast<unsigned char>(hex_str[1]))) {
|
||||||
return -1;
|
int hex_val = std::stoi(hex_str, nullptr, 16);
|
||||||
|
if (length < 1) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
buf[0] = static_cast<char>(hex_val);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
buf[0] = static_cast<char>(hex_val);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user