Skip to content

Commit 7d2b818

Browse files
committed
use public model APIs, not vocab
1 parent 9d474f2 commit 7d2b818

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

src/llama-sampling.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2347,7 +2347,7 @@ void llama_perf_sampler_reset(struct llama_sampler * chain) {
23472347
#include "llguidance.h"
23482348

23492349
struct llama_sampler_llg {
2350-
const struct llama_vocab * vocab;
2350+
const struct llama_model * model;
23512351
std::string grammar_kind;
23522352
std::string grammar_data;
23532353
LlgConstraint *grammar;
@@ -2364,6 +2364,7 @@ static LlgConstraint *llama_sampler_llg_new(const char * grammar_kind, const cha
23642364
llg_free_constraint(c);
23652365
return nullptr;
23662366
}
2367+
return c;
23672368
}
23682369

23692370
static const char * llama_sampler_llg_name(const struct llama_sampler * /*smpl*/) {
@@ -2394,7 +2395,7 @@ static void llama_sampler_llg_apply(struct llama_sampler * smpl, llama_token_dat
23942395
if (ctx->has_llg_res) {
23952396
if (ctx->llg_res.is_stop) {
23962397
for (size_t i = 0; i < cur_p->size; ++i) {
2397-
if (!llama_token_is_eog_impl(*ctx->vocab, cur_p->data[i].id)) {
2398+
if (!llama_token_is_eog(ctx->model, cur_p->data[i].id)) {
23982399
cur_p->data[i].logit = -INFINITY;
23992400
}
24002401
}
@@ -2426,7 +2427,7 @@ static void llama_sampler_llg_reset(struct llama_sampler * smpl) {
24262427
static struct llama_sampler * llama_sampler_llg_clone(const struct llama_sampler * smpl) {
24272428
const auto * ctx = (const llama_sampler_llg *) smpl->ctx;
24282429

2429-
auto * result = llama_sampler_init_llg_impl(*ctx->vocab, nullptr, nullptr);
2430+
auto * result = llama_sampler_init_llg(ctx->model, nullptr, nullptr);
24302431

24312432
// copy the state
24322433
{
@@ -2461,15 +2462,13 @@ static struct llama_sampler_i llama_sampler_llg_i = {
24612462
/* .free = */ llama_sampler_llg_free,
24622463
};
24632464

2464-
struct llama_sampler * llama_sampler_init_llg_impl(const struct llama_vocab & vocab, const char * grammar_kind, const char * grammar_data) {
2465+
struct llama_sampler * llama_sampler_init_llg(const struct llama_model * model,
2466+
const char * grammar_kind, const char * grammar_data) {
24652467
auto * ctx = new llama_sampler_llg;
24662468

24672469
if (grammar_kind != nullptr && grammar_kind[0] != '\0') {
2468-
auto d = vocab.id_to_token[94776].text;
2469-
LLAMA_LOG_INFO("llg: %s %d\n", d.c_str(), d.size());
2470-
24712470
*ctx = {
2472-
/* .vocab = */ &vocab,
2471+
/* .model = */ model,
24732472
/* .grammar_kind = */ grammar_kind,
24742473
/* .grammar_data = */ grammar_data,
24752474
/* .grammar = */ llama_sampler_llg_new(grammar_kind, grammar_data),
@@ -2478,7 +2477,7 @@ struct llama_sampler * llama_sampler_init_llg_impl(const struct llama_vocab & vo
24782477
};
24792478
} else {
24802479
*ctx = {
2481-
/* .vocab = */ &vocab,
2480+
/* .model = */ model,
24822481
/* .grammar_kind = */ {},
24832482
/* .grammar_data = */ {},
24842483
/* .grammar = */ nullptr,

src/llama-sampling.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ struct llama_sampler * llama_sampler_init_grammar_impl(
2525
const struct llama_vocab & vocab,
2626
const char * grammar_str,
2727
const char * grammar_root);
28-
struct llama_sampler * llama_sampler_init_llg_impl(
29-
const struct llama_vocab & vocab,
30-
const char * grammar_type,
31-
const char * grammar_data);
3228

3329

3430
struct llama_sampler * llama_sampler_init_infill_impl(

src/llama.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21866,12 +21866,6 @@ struct llama_sampler * llama_sampler_init_grammar(const struct llama_model * mod
2186621866
return llama_sampler_init_grammar_impl(model->vocab, grammar_str, grammar_root);
2186721867
}
2186821868

21869-
#ifdef GGML_LLGUIDANCE
21870-
struct llama_sampler * llama_sampler_init_llg(const struct llama_model * model, const char * grammar_type, const char * grammar_data) {
21871-
return llama_sampler_init_llg_impl(model->vocab, grammar_type, grammar_data);
21872-
}
21873-
#endif
21874-
2187521869
struct llama_sampler * llama_sampler_init_infill(const struct llama_model * model) {
2187621870
return llama_sampler_init_infill_impl(model->vocab);
2187721871
}

0 commit comments

Comments
 (0)