okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
b2de2641f
main
1#pragma once 2 3#include "llama.h" 4 5#include <string> 6#include <vector> 7#include <memory> 8 9// pre-tokenization types 10enum llama_vocab_pre_type { 11LLAMA_VOCAB_PRE_TYPE_DEFAULT = 0 , 12LLAMA_VOCAB_PRE_TYPE_LLAMA3 = 1 , 13LLAMA_VOCAB_PRE_TYPE_DEEPSEEK_LLM = 2 , 14LLAMA_VOCAB_PRE_TYPE_DEEPSEEK_CODER = 3 , 15LLAMA_VOCAB_PRE_TYPE_FALCON = 4 , 16LLAMA_VOCAB_PRE_TYPE_MPT = 5 , 17LLAMA_VOCAB_PRE_TYPE_STARCODER = 6 , 18LLAMA_VOCAB_PRE_TYPE_GPT2 = 7 , 19LLAMA_VOCAB_PRE_TYPE_REFACT = 8 , 20LLAMA_VOCAB_PRE_TYPE_COMMAND_R = 9 , 21LLAMA_VOCAB_PRE_TYPE_STABLELM2 = 10 , 22LLAMA_VOCAB_PRE_TYPE_QWEN2 = 11 , 23LLAMA_VOCAB_PRE_TYPE_OLMO = 12 , 24LLAMA_VOCAB_PRE_TYPE_DBRX = 13 , 25LLAMA_VOCAB_PRE_TYPE_SMAUG = 14 , 26LLAMA_VOCAB_PRE_TYPE_PORO = 15 , 27LLAMA_VOCAB_PRE_TYPE_CHATGLM3 = 16 , 28LLAMA_VOCAB_PRE_TYPE_CHATGLM4 = 17 , 29LLAMA_VOCAB_PRE_TYPE_VIKING = 18 , 30LLAMA_VOCAB_PRE_TYPE_JAIS = 19 , 31LLAMA_VOCAB_PRE_TYPE_TEKKEN = 20 , 32LLAMA_VOCAB_PRE_TYPE_SMOLLM = 21 , 33LLAMA_VOCAB_PRE_TYPE_CODESHELL = 22 , 34LLAMA_VOCAB_PRE_TYPE_BLOOM = 23 , 35LLAMA_VOCAB_PRE_TYPE_GPT3_FINNISH = 24 , 36LLAMA_VOCAB_PRE_TYPE_EXAONE = 25 , 37LLAMA_VOCAB_PRE_TYPE_CHAMELEON = 26 , 38LLAMA_VOCAB_PRE_TYPE_MINERVA = 27 , 39LLAMA_VOCAB_PRE_TYPE_DEEPSEEK3_LLM = 28 , 40LLAMA_VOCAB_PRE_TYPE_GPT4O = 29 , 41LLAMA_VOCAB_PRE_TYPE_SUPERBPE = 30 , 42LLAMA_VOCAB_PRE_TYPE_TRILLION = 31 , 43LLAMA_VOCAB_PRE_TYPE_BAILINGMOE = 32 , 44LLAMA_VOCAB_PRE_TYPE_LLAMA4 = 33 , 45LLAMA_VOCAB_PRE_TYPE_PIXTRAL = 34 , 46LLAMA_VOCAB_PRE_TYPE_SEED_CODER = 35 , 47LLAMA_VOCAB_PRE_TYPE_HUNYUAN = 36 , 48LLAMA_VOCAB_PRE_TYPE_KIMI_K2 = 37 , 49LLAMA_VOCAB_PRE_TYPE_HUNYUAN_DENSE = 38 , 50LLAMA_VOCAB_PRE_TYPE_GROK_2 = 39 , 51LLAMA_VOCAB_PRE_TYPE_GRANITE_DOCLING = 40 , 52LLAMA_VOCAB_PRE_TYPE_MINIMAX_M2 = 41 , 53LLAMA_VOCAB_PRE_TYPE_AFMOE = 42 , 54LLAMA_VOCAB_PRE_TYPE_SOLAR_OPEN = 43 , 55LLAMA_VOCAB_PRE_TYPE_YOUTU = 44 , 56LLAMA_VOCAB_PRE_TYPE_EXAONE_MOE = 45 , 57LLAMA_VOCAB_PRE_TYPE_QWEN35 = 46 , 58LLAMA_VOCAB_PRE_TYPE_TINY_AYA = 47 , 59LLAMA_VOCAB_PRE_TYPE_JOYAI_LLM = 48 , 60LLAMA_VOCAB_PRE_TYPE_JAIS2 = 49 , 61LLAMA_VOCAB_PRE_TYPE_GEMMA4 = 50 , 62LLAMA_VOCAB_PRE_TYPE_SARVAM_MOE = 51 , 63LLAMA_VOCAB_PRE_TYPE_MINICPM5 = 52 , 64LLAMA_VOCAB_PRE_TYPE_WHITESPACE = 53 , 65LLAMA_VOCAB_PRE_TYPE_GRANITE_EMB_MULTI = 54 , 66LLAMA_VOCAB_PRE_TYPE_MELLUM2 = 55 , 67LLAMA_VOCAB_PRE_TYPE_LAGUNA = 56 , 68LLAMA_VOCAB_PRE_TYPE_HY_V4 = 57 , 69LLAMA_VOCAB_PRE_TYPE_SPARK2_5 = 58 , 70LLAMA_VOCAB_PRE_TYPE_UFAKZEKA = 59 , 71}; 72 73struct LLM_KV ; 74struct llama_model_loader ; 75 76struct llama_vocab { 77struct token_data { 78std ::string text ; 79float score ; 80llama_token_attr attr ; 81 }; 82 83struct normalizer_options { 84bool lowercase = true; 85bool strip_accents = true; 86// TODO: clean_text, handle_chinese_chars 87 }; 88 89llama_vocab (); 90~ llama_vocab (); 91 92void load (llama_model_loader & ml , const LLM_KV & kv ); 93 94std:: string get_tokenizer_model () const ; 95std:: string get_tokenizer_pre () const ; 96 97enum llama_vocab_type get_type () const ; 98enum llama_vocab_pre_type get_pre_type () const ; 99 100uint32_t n_tokens () const ; 101uint32_t n_token_types () const ; 102 103std:: string type_name () const ; 104 105bool is_normal (llama_token id ) const ; 106bool is_unknown (llama_token id ) const ; 107bool is_control (llama_token id ) const ; 108bool is_byte (llama_token id ) const ; 109bool is_user_defined (llama_token id ) const ; 110bool is_unused (llama_token id ) const ; 111bool is_eog (llama_token id ) const ; 112 113uint8_t token_to_byte (llama_token id ) const ; 114llama_token byte_to_token (uint8_t ch ) const ; 115 116llama_token text_to_token ( const std:: string & text ) const ; 117 118const token_data & get_token_data (llama_token id ) const ; 119 120const char * token_get_text (llama_token id ) const ; 121float token_get_score (llama_token id ) const ; 122llama_token_attr token_get_attr (llama_token id ) const ; 123 124llama_token token_bos () const ; 125llama_token token_eos () const ; 126llama_token token_eot () const ; 127llama_token token_eom () const ; 128llama_token token_unk () const ; 129llama_token token_sep () const ; 130llama_token token_nl () const ; 131llama_token token_pad () const ; 132llama_token token_mask () const ; 133 134llama_token token_prefix () const ; 135llama_token token_middle () const ; 136llama_token token_suffix () const ; 137 138llama_token token_fim_pre () const ; 139llama_token token_fim_suf () const ; 140llama_token token_fim_mid () const ; 141llama_token token_fim_pad () const ; 142llama_token token_fim_rep () const ; 143llama_token token_fim_sep () const ; 144 145bool get_add_space_prefix () const ; 146bool get_add_bos () const ; 147bool get_add_eos () const ; 148bool get_add_sep () const ; 149bool get_ignore_merges () const ; 150bool get_clean_spaces () const ; 151bool get_remove_extra_whitespaces () const ; 152bool get_escape_whitespaces () const ; 153bool get_treat_whitespace_as_suffix () const ; 154const normalizer_options & get_normalizer_opts () const ; 155 156const std:: vector < llama_token > & get_suppress_tokens () const ; 157 158int max_token_len () const ; 159 160int find_bpe_rank ( const std:: string & token_left , const std :: string & token_right ) const ; 161std:: vector < std :: string > get_bpe_merges () const ; 162 163std:: vector < char > get_precompiled_charsmap () const ; 164 165int32_t tokenize ( 166const char * text , 167int32_t text_len , 168llama_token * tokens , 169int32_t n_tokens_max , 170bool add_special , 171bool parse_special ) const ; 172 173std:: vector < llama_token > tokenize ( 174const std:: string & raw_text , 175bool add_special , 176bool parse_special = false) const ; 177 178// does not write null-terminator to buf 179int32_t token_to_piece ( 180llama_token token , 181char * buf , 182int32_t length , 183int32_t lstrip , 184bool special ) const ; 185 186// use cached data 187const std:: string & token_to_piece (llama_token token ) const ; 188 189int32_t detokenize ( 190const llama_token * tokens , 191int32_t n_tokens , 192char * text , 193int32_t text_len_max , 194bool remove_special , 195bool unparse_special ) const ; 196 197std:: string detokenize ( 198const std:: vector < llama_token > & tokens , 199bool special ) const ; 200 201void print_info () const ; 202 203private: 204struct impl; 205std:: unique_ptr < impl > pimpl ; 206};