grammar : fix reset call

ggml-ci
This commit is contained in:
Georgi Gerganov 2024-09-04 14:26:23 +03:00
parent fdb52aa657
commit ca5d21c17a
No known key found for this signature in database
GPG key ID: 449E073F9DC10735
2 changed files with 7 additions and 9 deletions

View file

@ -51,9 +51,6 @@ defer {
} }
var sparams = llama_sampler_params() var sparams = llama_sampler_params()
sparams.top_k = 40
sparams.top_p = 0.9
sparams.temp = 0.4
let smpl = llama_sampler_init(model, sparams) let smpl = llama_sampler_init(model, sparams)
guard smpl != nil else { guard smpl != nil else {

View file

@ -724,17 +724,18 @@ static struct llama_constraint_i llama_constraint_grammar_i = {
}, },
/* .reset = */ [](struct llama_constraint * cnstr) { /* .reset = */ [](struct llama_constraint * cnstr) {
auto * ctx = (llama_constraint_context_grammar *) cnstr->ctx; auto * ctx = (llama_constraint_context_grammar *) cnstr->ctx;
if (ctx->grammar) { if (!ctx->grammar) {
llama_grammar_free_impl(ctx->grammar); return;
ctx->grammar = nullptr;
} }
if (!ctx->grammar_str.empty()) { auto * grammar_new = llama_grammar_init_impl(ctx->grammar->vocab, ctx->grammar_str.c_str(), ctx->grammar_root.c_str());
ctx->grammar = llama_grammar_init_impl(nullptr, ctx->grammar_str.c_str(), ctx->grammar_root.c_str());
} llama_grammar_free_impl(ctx->grammar);
ctx->grammar = grammar_new;
}, },
/* .copy = */ [](const struct llama_constraint * cnstr) { /* .copy = */ [](const struct llama_constraint * cnstr) {
const auto * ctx_src = (const llama_constraint_context_grammar *) cnstr->ctx; const auto * ctx_src = (const llama_constraint_context_grammar *) cnstr->ctx;
auto * result = llama_constraint_init_grammar_impl(*ctx_src->grammar->vocab, nullptr, nullptr); auto * result = llama_constraint_init_grammar_impl(*ctx_src->grammar->vocab, nullptr, nullptr);
auto * ctx_dst = (llama_constraint_context_grammar *) result->ctx; auto * ctx_dst = (llama_constraint_context_grammar *) result->ctx;