@@ -2147,14 +2147,16 @@ struct llama_control_vector {
2147
2147
};
2148
2148
2149
2149
struct llama_vocab {
2150
- using id = int32_t;
2151
- using token = std::string;
2152
- using ttype = llama_token_type;
2150
+ using id = int32_t;
2151
+ using token = std::string;
2152
+ using ttype = llama_token_type;
2153
+ using tattrib = llama_token_attrib;
2153
2154
2154
2155
struct token_data {
2155
- token text;
2156
- float score;
2157
- ttype type;
2156
+ token text;
2157
+ float score;
2158
+ ttype type;
2159
+ tattrib attribs;
2158
2160
};
2159
2161
2160
2162
enum llama_vocab_type type = LLAMA_VOCAB_TYPE_SPM;
@@ -4865,6 +4867,24 @@ static void llm_load_vocab(
4865
4867
4866
4868
LLAMA_LOG_INFO("%s: token to piece cache size = %.4f MB\n", __func__, size_cache / 1024.0 / 1024.0);
4867
4869
}
4870
+
4871
+ // Handle per token attributes
4872
+ //NOTE: Each model customizes per token attributes.
4873
+ //NOTE: Per token attributes are missing from the GGUF file.
4874
+ //TODO: Merge llama_token_type and llama_token_attrib.
4875
+ {
4876
+ // convert token type as an attribute
4877
+ for (auto data : vocab.id_to_token) {
4878
+ uint32_t attrib = LLAMA_TOKEN_ATTRIB_UNDEFINED;
4879
+ attrib |= LLAMA_TOKEN_ATTRIB_UNKNOWN * (data.type == LLAMA_TOKEN_TYPE_UNKNOWN);
4880
+ attrib |= LLAMA_TOKEN_ATTRIB_UNUSED * (data.type == LLAMA_TOKEN_TYPE_UNUSED);
4881
+ attrib |= LLAMA_TOKEN_ATTRIB_NORMAL * (data.type == LLAMA_TOKEN_TYPE_NORMAL);
4882
+ attrib |= LLAMA_TOKEN_ATTRIB_CONTROL * (data.type == LLAMA_TOKEN_TYPE_CONTROL);
4883
+ attrib |= LLAMA_TOKEN_ATTRIB_USER_DEFINED * (data.type == LLAMA_TOKEN_TYPE_USER_DEFINED);
4884
+ attrib |= LLAMA_TOKEN_ATTRIB_BYTE * (data.type == LLAMA_TOKEN_TYPE_BYTE);
4885
+ data.attribs = (llama_token_attrib) attrib;
4886
+ }
4887
+ }
4868
4888
}
4869
4889
4870
4890
static void llm_load_print_meta(llama_model_loader & ml, llama_model & model) {
0 commit comments