format file

This commit is contained in:
Michal Moskal 2025-01-26 10:11:39 -08:00
parent 44e1973af0
commit c9e9853e6c

View file

@ -17,8 +17,8 @@ struct llama_sampler_llg {
bool has_llg_res; bool has_llg_res;
}; };
static LlgConstraint *llama_sampler_llg_new(LlgTokenizer *tokenizer, static LlgConstraint * llama_sampler_llg_new(LlgTokenizer * tokenizer, const char * grammar_kind,
const char * grammar_kind, const char * grammar_data) { const char * grammar_data) {
LlgConstraintInit cinit; LlgConstraintInit cinit;
llg_constraint_init_set_defaults(&cinit, tokenizer); llg_constraint_init_set_defaults(&cinit, tokenizer);
// cinit.log_stderr_level = 2; // cinit.log_stderr_level = 2;
@ -128,23 +128,19 @@ static llama_sampler_i llama_sampler_llg_i = {
/* .free = */ llama_sampler_llg_free, /* .free = */ llama_sampler_llg_free,
}; };
static size_t llama_sampler_llg_tokenize_fn(const void * user_data, const uint8_t * bytes, size_t bytes_len,
static size_t llama_sampler_llg_tokenize_fn(const void *user_data, uint32_t * output_tokens, size_t output_tokens_len) {
const uint8_t *bytes,
size_t bytes_len,
uint32_t *output_tokens,
size_t output_tokens_len)
{
const llama_vocab * vocab = (const llama_vocab *) user_data; const llama_vocab * vocab = (const llama_vocab *) user_data;
int r = 0; int r = 0;
try { try {
r = llama_tokenize(vocab, (const char *) bytes, bytes_len, r = llama_tokenize(vocab, (const char *) bytes, bytes_len, (int32_t *) output_tokens, output_tokens_len, false,
(int32_t*)output_tokens, output_tokens_len, false, true); true);
} catch (const std::exception & e) { } catch (const std::exception & e) {
GGML_ABORT("llama_tokenize failed: %s\n", e.what()); GGML_ABORT("llama_tokenize failed: %s\n", e.what());
} }
if (r < 0) if (r < 0) {
return -r; return -r;
}
return r; return r;
} }
@ -158,8 +154,9 @@ static LlgTokenizer *llama_sampler_llg_new_tokenizer(const llama_vocab * vocab)
} }
auto tok_eos = llama_vocab_eot(vocab); auto tok_eos = llama_vocab_eot(vocab);
if (tok_eos == LLAMA_TOKEN_NULL) if (tok_eos == LLAMA_TOKEN_NULL) {
tok_eos = llama_vocab_eos(vocab); tok_eos = llama_vocab_eos(vocab);
}
size_t vocab_size = llama_vocab_n_tokens(vocab); size_t vocab_size = llama_vocab_n_tokens(vocab);
@ -196,7 +193,6 @@ static LlgTokenizer *llama_sampler_llg_new_tokenizer(const llama_vocab * vocab)
offset += size; offset += size;
} }
LlgTokenizerInit tinit = { LlgTokenizerInit tinit = {
/* .vocab_size = */ (uint32_t) vocab_size, /* .vocab_size = */ (uint32_t) vocab_size,
/* .tok_eos = */ (uint32_t) tok_eos, /* .tok_eos = */ (uint32_t) tok_eos,
@ -229,8 +225,8 @@ static LlgTokenizer *llama_sampler_llg_new_tokenizer(const llama_vocab * vocab)
return llg_clone_tokenizer(tokenizer_cache); return llg_clone_tokenizer(tokenizer_cache);
} }
llama_sampler * llama_sampler_init_llg(const llama_vocab * vocab, llama_sampler * llama_sampler_init_llg(const llama_vocab * vocab, const char * grammar_kind,
const char * grammar_kind, const char * grammar_data) { const char * grammar_data) {
auto * ctx = new llama_sampler_llg; auto * ctx = new llama_sampler_llg;
if (grammar_kind != nullptr && grammar_kind[0] != '\0') { if (grammar_kind != nullptr && grammar_kind[0] != '\0') {