File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -2839,6 +2839,13 @@ static bool llama_is_pad_token(const llama_vocab & vocab, llama_token id ) {
2839
2839
}
2840
2840
2841
2841
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) {
2842
2849
if (vocab.type == LLAMA_VOCAB_TYPE_SPM) {
2843
2850
char buf[7 ];
2844
2851
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) {
2849
2856
return vocab.token_to_id .at (std::string (1 , ch));
2850
2857
}
2851
2858
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
-
2859
2859
static std::string llama_escape_whitespace (const std::string& text) {
2860
2860
std::string result;
2861
2861
bool escaping = false ;
You can’t perform that action at this time.
0 commit comments