@@ -2358,7 +2358,12 @@ struct llama_sampler_llg {
23582358static LlgConstraint *llama_sampler_llg_new (const char * grammar_kind, const char * grammar_data) {
23592359 LlgConstraintInit cinit;
23602360 llg_constraint_init_set_defaults (&cinit, nullptr );
2361- return llg_new_constraint_any (&cinit, grammar_kind, grammar_data);
2361+ auto c = llg_new_constraint_any (&cinit, grammar_kind, grammar_data);
2362+ if (llg_get_error (c)) {
2363+ LLAMA_LOG_ERROR (" llg error: %s\n " , llg_get_error (c));
2364+ llg_free_constraint (c);
2365+ return nullptr ;
2366+ }
23622367}
23632368
23642369static const char * llama_sampler_llg_name (const struct llama_sampler * /* smpl*/ ) {
@@ -2382,6 +2387,8 @@ static void llama_sampler_llg_apply(struct llama_sampler * smpl, llama_token_dat
23822387 ctx->has_llg_res = true ;
23832388 } else {
23842389 LLAMA_LOG_ERROR (" llg error: %s\n " , llg_get_error (ctx->grammar ));
2390+ llg_free_constraint (ctx->grammar );
2391+ ctx->grammar = nullptr ;
23852392 }
23862393 }
23872394 if (ctx->has_llg_res ) {
@@ -2458,6 +2465,9 @@ struct llama_sampler * llama_sampler_init_llg_impl(const struct llama_vocab & vo
24582465 auto * ctx = new llama_sampler_llg;
24592466
24602467 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+
24612471 *ctx = {
24622472 /* .vocab = */ &vocab,
24632473 /* .grammar_kind = */ grammar_kind,
0 commit comments