|
|
@@ -1477,6 +1477,7 @@ static struct llama_sampler * llama_sampler_grammar_clone(const struct llama_sam
|
|
|
const auto * ctx = (const llama_sampler_grammar *) smpl->ctx;
|
|
|
|
|
|
auto * result = llama_sampler_init_grammar_impl(ctx->vocab, nullptr, nullptr, false, nullptr, 0, nullptr, 0, nullptr, 0);
|
|
|
+ GGML_ASSERT(result);
|
|
|
|
|
|
// copy the state
|
|
|
{
|
|
|
@@ -1548,6 +1549,10 @@ static struct llama_sampler * llama_sampler_init_grammar_impl(
|
|
|
/* .grammar_root = */ grammar_root,
|
|
|
/* .grammar = */ llama_grammar_init_impl(vocab, grammar_str, grammar_root, lazy, trigger_patterns, num_trigger_patterns, trigger_tokens, num_trigger_tokens),
|
|
|
};
|
|
|
+ if (!ctx->grammar) {
|
|
|
+ delete ctx;
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
} else {
|
|
|
*ctx = {
|
|
|
/* .vocab = */ vocab,
|