@@ -146,60 +146,63 @@ class llama_vocab_type(enum.IntEnum):
146146# https://github.com/ggml-org/llama.cpp/blob/master/src/llama-vocab.h#L10
147147# // pre-tokenization types
148148# enum llama_vocab_pre_type {
149- # LLAMA_VOCAB_PRE_TYPE_DEFAULT = 0,
150- # LLAMA_VOCAB_PRE_TYPE_LLAMA3 = 1,
151- # LLAMA_VOCAB_PRE_TYPE_DEEPSEEK_LLM = 2,
152- # LLAMA_VOCAB_PRE_TYPE_DEEPSEEK_CODER = 3,
153- # LLAMA_VOCAB_PRE_TYPE_FALCON = 4,
154- # LLAMA_VOCAB_PRE_TYPE_MPT = 5,
155- # LLAMA_VOCAB_PRE_TYPE_STARCODER = 6,
156- # LLAMA_VOCAB_PRE_TYPE_GPT2 = 7,
157- # LLAMA_VOCAB_PRE_TYPE_REFACT = 8,
158- # LLAMA_VOCAB_PRE_TYPE_COMMAND_R = 9,
159- # LLAMA_VOCAB_PRE_TYPE_STABLELM2 = 10,
160- # LLAMA_VOCAB_PRE_TYPE_QWEN2 = 11,
161- # LLAMA_VOCAB_PRE_TYPE_OLMO = 12,
162- # LLAMA_VOCAB_PRE_TYPE_DBRX = 13,
163- # LLAMA_VOCAB_PRE_TYPE_SMAUG = 14,
164- # LLAMA_VOCAB_PRE_TYPE_PORO = 15,
165- # LLAMA_VOCAB_PRE_TYPE_CHATGLM3 = 16,
166- # LLAMA_VOCAB_PRE_TYPE_CHATGLM4 = 17,
167- # LLAMA_VOCAB_PRE_TYPE_VIKING = 18,
168- # LLAMA_VOCAB_PRE_TYPE_JAIS = 19,
169- # LLAMA_VOCAB_PRE_TYPE_TEKKEN = 20,
170- # LLAMA_VOCAB_PRE_TYPE_SMOLLM = 21,
171- # LLAMA_VOCAB_PRE_TYPE_CODESHELL = 22,
172- # LLAMA_VOCAB_PRE_TYPE_BLOOM = 23,
173- # LLAMA_VOCAB_PRE_TYPE_GPT3_FINNISH = 24,
174- # LLAMA_VOCAB_PRE_TYPE_EXAONE = 25,
175- # LLAMA_VOCAB_PRE_TYPE_CHAMELEON = 26,
176- # LLAMA_VOCAB_PRE_TYPE_MINERVA = 27,
177- # LLAMA_VOCAB_PRE_TYPE_DEEPSEEK3_LLM = 28,
178- # LLAMA_VOCAB_PRE_TYPE_GPT4O = 29,
179- # LLAMA_VOCAB_PRE_TYPE_SUPERBPE = 30,
180- # LLAMA_VOCAB_PRE_TYPE_TRILLION = 31,
181- # LLAMA_VOCAB_PRE_TYPE_BAILINGMOE = 32,
182- # LLAMA_VOCAB_PRE_TYPE_LLAMA4 = 33,
183- # LLAMA_VOCAB_PRE_TYPE_PIXTRAL = 34,
184- # LLAMA_VOCAB_PRE_TYPE_SEED_CODER = 35,
185- # LLAMA_VOCAB_PRE_TYPE_HUNYUAN = 36,
186- # LLAMA_VOCAB_PRE_TYPE_KIMI_K2 = 37,
187- # LLAMA_VOCAB_PRE_TYPE_HUNYUAN_DENSE = 38,
188- # LLAMA_VOCAB_PRE_TYPE_GROK_2 = 39,
189- # LLAMA_VOCAB_PRE_TYPE_GRANITE_DOCLING = 40,
190- # LLAMA_VOCAB_PRE_TYPE_MINIMAX_M2 = 41,
191- # LLAMA_VOCAB_PRE_TYPE_AFMOE = 42,
192- # LLAMA_VOCAB_PRE_TYPE_SOLAR_OPEN = 43,
193- # LLAMA_VOCAB_PRE_TYPE_YOUTU = 44,
194- # LLAMA_VOCAB_PRE_TYPE_EXAONE_MOE = 45,
195- # LLAMA_VOCAB_PRE_TYPE_QWEN35 = 46,
196- # LLAMA_VOCAB_PRE_TYPE_TINY_AYA = 47,
197- # LLAMA_VOCAB_PRE_TYPE_JOYAI_LLM = 48,
198- # LLAMA_VOCAB_PRE_TYPE_JAIS2 = 49,
199- # LLAMA_VOCAB_PRE_TYPE_GEMMA4 = 50,
200- # LLAMA_VOCAB_PRE_TYPE_SARVAM_MOE = 51,
201- # LLAMA_VOCAB_PRE_TYPE_MINICPM5 = 52,
202- # LLAMA_VOCAB_PRE_TYPE_WHITESPACE = 53,
149+ # LLAMA_VOCAB_PRE_TYPE_DEFAULT = 0,
150+ # LLAMA_VOCAB_PRE_TYPE_LLAMA3 = 1,
151+ # LLAMA_VOCAB_PRE_TYPE_DEEPSEEK_LLM = 2,
152+ # LLAMA_VOCAB_PRE_TYPE_DEEPSEEK_CODER = 3,
153+ # LLAMA_VOCAB_PRE_TYPE_FALCON = 4,
154+ # LLAMA_VOCAB_PRE_TYPE_MPT = 5,
155+ # LLAMA_VOCAB_PRE_TYPE_STARCODER = 6,
156+ # LLAMA_VOCAB_PRE_TYPE_GPT2 = 7,
157+ # LLAMA_VOCAB_PRE_TYPE_REFACT = 8,
158+ # LLAMA_VOCAB_PRE_TYPE_COMMAND_R = 9,
159+ # LLAMA_VOCAB_PRE_TYPE_STABLELM2 = 10,
160+ # LLAMA_VOCAB_PRE_TYPE_QWEN2 = 11,
161+ # LLAMA_VOCAB_PRE_TYPE_OLMO = 12,
162+ # LLAMA_VOCAB_PRE_TYPE_DBRX = 13,
163+ # LLAMA_VOCAB_PRE_TYPE_SMAUG = 14,
164+ # LLAMA_VOCAB_PRE_TYPE_PORO = 15,
165+ # LLAMA_VOCAB_PRE_TYPE_CHATGLM3 = 16,
166+ # LLAMA_VOCAB_PRE_TYPE_CHATGLM4 = 17,
167+ # LLAMA_VOCAB_PRE_TYPE_VIKING = 18,
168+ # LLAMA_VOCAB_PRE_TYPE_JAIS = 19,
169+ # LLAMA_VOCAB_PRE_TYPE_TEKKEN = 20,
170+ # LLAMA_VOCAB_PRE_TYPE_SMOLLM = 21,
171+ # LLAMA_VOCAB_PRE_TYPE_CODESHELL = 22,
172+ # LLAMA_VOCAB_PRE_TYPE_BLOOM = 23,
173+ # LLAMA_VOCAB_PRE_TYPE_GPT3_FINNISH = 24,
174+ # LLAMA_VOCAB_PRE_TYPE_EXAONE = 25,
175+ # LLAMA_VOCAB_PRE_TYPE_CHAMELEON = 26,
176+ # LLAMA_VOCAB_PRE_TYPE_MINERVA = 27,
177+ # LLAMA_VOCAB_PRE_TYPE_DEEPSEEK3_LLM = 28,
178+ # LLAMA_VOCAB_PRE_TYPE_GPT4O = 29,
179+ # LLAMA_VOCAB_PRE_TYPE_SUPERBPE = 30,
180+ # LLAMA_VOCAB_PRE_TYPE_TRILLION = 31,
181+ # LLAMA_VOCAB_PRE_TYPE_BAILINGMOE = 32,
182+ # LLAMA_VOCAB_PRE_TYPE_LLAMA4 = 33,
183+ # LLAMA_VOCAB_PRE_TYPE_PIXTRAL = 34,
184+ # LLAMA_VOCAB_PRE_TYPE_SEED_CODER = 35,
185+ # LLAMA_VOCAB_PRE_TYPE_HUNYUAN = 36,
186+ # LLAMA_VOCAB_PRE_TYPE_KIMI_K2 = 37,
187+ # LLAMA_VOCAB_PRE_TYPE_HUNYUAN_DENSE = 38,
188+ # LLAMA_VOCAB_PRE_TYPE_GROK_2 = 39,
189+ # LLAMA_VOCAB_PRE_TYPE_GRANITE_DOCLING = 40,
190+ # LLAMA_VOCAB_PRE_TYPE_MINIMAX_M2 = 41,
191+ # LLAMA_VOCAB_PRE_TYPE_AFMOE = 42,
192+ # LLAMA_VOCAB_PRE_TYPE_SOLAR_OPEN = 43,
193+ # LLAMA_VOCAB_PRE_TYPE_YOUTU = 44,
194+ # LLAMA_VOCAB_PRE_TYPE_EXAONE_MOE = 45,
195+ # LLAMA_VOCAB_PRE_TYPE_QWEN35 = 46,
196+ # LLAMA_VOCAB_PRE_TYPE_TINY_AYA = 47,
197+ # LLAMA_VOCAB_PRE_TYPE_JOYAI_LLM = 48,
198+ # LLAMA_VOCAB_PRE_TYPE_JAIS2 = 49,
199+ # LLAMA_VOCAB_PRE_TYPE_GEMMA4 = 50,
200+ # LLAMA_VOCAB_PRE_TYPE_SARVAM_MOE = 51,
201+ # LLAMA_VOCAB_PRE_TYPE_MINICPM5 = 52,
202+ # LLAMA_VOCAB_PRE_TYPE_WHITESPACE = 53,
203+ # LLAMA_VOCAB_PRE_TYPE_GRANITE_EMB_MULTI = 54,
204+ # LLAMA_VOCAB_PRE_TYPE_MELLUM2 = 55,
205+ # LLAMA_VOCAB_PRE_TYPE_LAGUNA = 56,
203206# };
204207class llama_vocab_pre_type (enum .IntEnum ):
205208 LLAMA_VOCAB_PRE_TYPE_DEFAULT = 0
@@ -256,6 +259,9 @@ class llama_vocab_pre_type(enum.IntEnum):
256259 LLAMA_VOCAB_PRE_TYPE_SARVAM_MOE = 51
257260 LLAMA_VOCAB_PRE_TYPE_MINICPM5 = 52
258261 LLAMA_VOCAB_PRE_TYPE_WHITESPACE = 53
262+ LLAMA_VOCAB_PRE_TYPE_GRANITE_EMB_MULTI = 54
263+ LLAMA_VOCAB_PRE_TYPE_MELLUM2 = 55
264+ LLAMA_VOCAB_PRE_TYPE_LAGUNA = 56
259265
260266
261267# // note: these values should be synchronized with ggml_rope
@@ -4130,22 +4136,19 @@ def llama_chat_builtin_templates(
41304136# struct ggml_tensor * probs;
41314137# struct ggml_tensor * sampled;
41324138# struct ggml_tensor * candidates;
4133- # int64_t n_vocab;
41344139# };
41354140class llama_sampler_data (ctypes .Structure ):
41364141 if TYPE_CHECKING :
41374142 logits : ctypes .c_void_p
41384143 probs : ctypes .c_void_p
41394144 sampled : ctypes .c_void_p
41404145 candidates : ctypes .c_void_p
4141- n_vocab : ctypes .c_int64
41424146
41434147 _fields_ = [
41444148 ("logits" , ctypes .c_void_p ),
41454149 ("probs" , ctypes .c_void_p ),
41464150 ("sampled" , ctypes .c_void_p ),
41474151 ("candidates" , ctypes .c_void_p ),
4148- ("n_vocab" , ctypes .c_int64 ),
41494152 ]
41504153
41514154
@@ -4656,16 +4659,24 @@ def llama_sampler_init_grammar_lazy_patterns(
46564659
46574660# /// NOTE: Avoid using on the full vocabulary as searching for repeated tokens can become slow. For example, apply top-k or top-p sampling first.
46584661# LLAMA_API struct llama_sampler * llama_sampler_init_penalties(
4662+ # int32_t n_vocab,
46594663# int32_t penalty_last_n, // last n tokens to penalize (0 = disable penalty, -1 = context size)
46604664# float penalty_repeat, // must be > 0.0, 1.0 = disabled
46614665# float penalty_freq, // must be finite, 0.0 = disabled
46624666# float penalty_present); // must be finite, 0.0 = disabled
46634667@ctypes_function (
46644668 "llama_sampler_init_penalties" ,
4665- [ctypes .c_int32 , ctypes .c_float , ctypes .c_float , ctypes .c_float ],
4669+ [
4670+ ctypes .c_int32 ,
4671+ ctypes .c_int32 ,
4672+ ctypes .c_float ,
4673+ ctypes .c_float ,
4674+ ctypes .c_float ,
4675+ ],
46664676 llama_sampler_p_ctypes ,
46674677)
46684678def llama_sampler_init_penalties (
4679+ n_vocab : int ,
46694680 penalty_last_n : int ,
46704681 penalty_repeat : float ,
46714682 penalty_freq : float ,
0 commit comments