Skip to content

Commit

Permalink
llama : handle unknown utf8 bytes (ggerganov#7588)
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgi Gerganov authored May 28, 2024
1 parent 271ff3f commit 8b99e2a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion llama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17940,7 +17940,16 @@ static std::string llama_decode_text(const std::string & text) {

const auto cpts = unicode_cpts_from_utf8(text);
for (const auto cpt : cpts) {
decoded_text += unicode_utf8_to_byte(unicode_cpt_to_utf8(cpt));
const auto utf8 = unicode_cpt_to_utf8(cpt);
try {
decoded_text += unicode_utf8_to_byte(utf8);
} catch (const std::out_of_range & e) {
decoded_text += "[UNK_BYTE_0x";
for (const auto c : utf8) {
decoded_text += format("%02x", (uint8_t) c);
}
decoded_text += text + "]";
}
}

return decoded_text;
Expand Down

0 comments on commit 8b99e2a

Please sign in to comment.