server : return 400 when grammar and ignore_eos are on (#32377)

* sampling : fix crash when both ignore_eos and grammar are on

* server : rework, throw 400 when grammar and ignore_eos are on

* sampling : move the check into the sampler (review suggestion)

* tests : remove redundant tests
This commit is contained in:
eddiechen authored and GitHub committed 2026-11-17 17:03:21 +01:00
1 parent 10152bc4a0
commit 955c4e8ee5
4 files changed
+41

No files matched your search

+7
View File
@@ -203,6 +203,13 @@ struct common_sampler * common_sampler_init(
throw std::invalid_argument("penalty_present must be finite");
}
const llama_vocab * vocab = llama_model_get_vocab(model);
if (!common_grammar_value(params.grammar).empty()) {
for (const auto & b : params.logit_bias) {
if (b.bias == -INFINITY && llama_vocab_is_eog(vocab, b.token)) {
throw std::invalid_argument("EOG tokens cannot be banned when a grammar is set");
}
}
}
llama_sampler_chain_params lparams = llama_sampler_chain_default_params();
lparams.no_perf = params.no_perf;