@@ -110,39 +110,43 @@ std::string llama_vocab::type_name() const{
110110 }
111111}
112112
113- bool llama_vocab::is_normal_token (llama_token id) const {
113+ bool llama_vocab::is_normal (llama_token id) const {
114114 GGML_ASSERT (type != LLAMA_VOCAB_TYPE_NONE);
115115 return id_to_token[id].attr & LLAMA_TOKEN_ATTR_NORMAL;
116116}
117117
118- bool llama_vocab::is_unknown_token (llama_token id) const {
118+ bool llama_vocab::is_unknown (llama_token id) const {
119119 GGML_ASSERT (type != LLAMA_VOCAB_TYPE_NONE);
120120 return id_to_token[id].attr & LLAMA_TOKEN_ATTR_UNKNOWN;
121121}
122122
123- bool llama_vocab::is_control_token (llama_token id) const {
123+ bool llama_vocab::is_control (llama_token id) const {
124124 GGML_ASSERT (type != LLAMA_VOCAB_TYPE_NONE);
125125 return id_to_token[id].attr & LLAMA_TOKEN_ATTR_CONTROL;
126126}
127127
128- bool llama_vocab::is_byte_token (llama_token id) const {
128+ bool llama_vocab::is_byte (llama_token id) const {
129129 GGML_ASSERT (type != LLAMA_VOCAB_TYPE_NONE);
130130 return id_to_token[id].attr & LLAMA_TOKEN_ATTR_BYTE;
131131}
132132
133- bool llama_vocab::is_user_defined_token (llama_token id) const {
133+ bool llama_vocab::is_user_defined (llama_token id) const {
134134 GGML_ASSERT (type != LLAMA_VOCAB_TYPE_NONE);
135135 return id_to_token[id].attr & LLAMA_TOKEN_ATTR_USER_DEFINED;
136136}
137137
138- bool llama_vocab::is_unused_token (llama_token id) const {
138+ bool llama_vocab::is_unused (llama_token id) const {
139139 GGML_ASSERT (type != LLAMA_VOCAB_TYPE_NONE);
140140 return id_to_token[id].attr & LLAMA_TOKEN_ATTR_UNUSED;
141141}
142142
143+ bool llama_vocab::is_eog (llama_token id) const {
144+ return id != LLAMA_TOKEN_NULL && special_eog_ids.count (id) > 0 ;
145+ }
146+
143147uint8_t llama_vocab::token_to_byte (llama_token id) const {
144148 GGML_ASSERT (get_type () != LLAMA_VOCAB_TYPE_NONE);
145- GGML_ASSERT (is_byte_token (id));
149+ GGML_ASSERT (is_byte (id));
146150 const auto & token_data = id_to_token.at (id);
147151 switch (get_type ()) {
148152 case LLAMA_VOCAB_TYPE_SPM:
@@ -832,18 +836,18 @@ struct llm_tokenizer_ugm : llm_tokenizer {
832836 for (unsigned int id = 0 ; id < vocab.id_to_token .size (); ++id) {
833837 const auto &token_data = vocab.id_to_token [id];
834838
835- if (vocab.is_normal_token (id)) {
839+ if (vocab.is_normal (id)) {
836840 min_score = std::min<float >(min_score, token_data.score );
837841 max_score = std::max<float >(max_score, token_data.score );
838842 }
839843
840- if (vocab.is_normal_token (id) ||
841- vocab.is_user_defined_token (id) ||
842- vocab.is_unused_token (id)) {
844+ if (vocab.is_normal (id) ||
845+ vocab.is_user_defined (id) ||
846+ vocab.is_unused (id)) {
843847 token_matcher.insert (token_data.text .data (), token_data.text .size (), id);
844848 }
845849
846- if (vocab.is_user_defined_token (id)) {
850+ if (vocab.is_user_defined (id)) {
847851 user_defined_token_matcher.insert (token_data.text .data (), token_data.text .size ());
848852 }
849853 }
@@ -928,7 +932,7 @@ struct llm_tokenizer_ugm_session {
928932 // (normal token scores are log probabilities, so they are negative)
929933 // score type is double here to make tokenization results exactly
930934 // the same as in the HF tokenizer using SentencePiece
931- const double token_score = vocab.is_user_defined_token (token_id) ? 0.0 : token_data.score ;
935+ const double token_score = vocab.is_user_defined (token_id) ? 0.0 : token_data.score ;
932936 const double challenger_score = current_best.score_sum + token_score;
933937 struct best_tokenization & current_champ = tokenization_results[prefix_offset];
934938 if (challenger_score > current_champ.score_sum ) {
@@ -1466,27 +1470,19 @@ llama_token llama_vocab::byte_to_token(uint8_t ch) const {
14661470 }
14671471}
14681472
1469- const char * llama_vocab::token_get_text (llama_token token ) const {
1473+ const char * llama_vocab::token_get_text (llama_token id ) const {
14701474 GGML_ASSERT (type != LLAMA_VOCAB_TYPE_NONE);
1471- return id_to_token[token ].text .c_str ();
1475+ return id_to_token[id ].text .c_str ();
14721476}
14731477
1474- float llama_vocab::token_get_score (llama_token token ) const {
1478+ float llama_vocab::token_get_score (llama_token id ) const {
14751479 GGML_ASSERT (type != LLAMA_VOCAB_TYPE_NONE);
1476- return id_to_token[token ].score ;
1480+ return id_to_token[id ].score ;
14771481}
14781482
1479- llama_token_attr llama_vocab::token_get_attr (llama_token token ) const {
1483+ llama_token_attr llama_vocab::token_get_attr (llama_token id ) const {
14801484 GGML_ASSERT (type != LLAMA_VOCAB_TYPE_NONE);
1481- return id_to_token[token].attr ;
1482- }
1483-
1484- bool llama_vocab::token_is_eog (llama_token token) const {
1485- return token != LLAMA_TOKEN_NULL && special_eog_ids.count (token) > 0 ;
1486- }
1487-
1488- bool llama_vocab::token_is_control (llama_token token) const {
1489- return is_control_token (token);
1485+ return id_to_token[id].attr ;
14901486}
14911487
14921488llama_token llama_vocab::token_bos () const {
0 commit comments