fix grammar for Kimi-K2 (#1103)

* Update key-value separator and value end format

* Sample grammar first if resampling

---------

Co-authored-by: firecoperana <firecoperana>
This commit is contained in:
hksdpc255
2026-01-05 16:57:25 +11:00
committed by GitHub
parent 5a206e3cef
commit 3afd0600a1
2 changed files with 8 additions and 2 deletions

View File

@@ -429,6 +429,12 @@ static llama_token llama_sampling_sample_impl(
GGML_ASSERT(!original_logits.empty());
}
llama_token id = 0;
// Sample grammar first for resampling
if (ctx_sampling->grammar != NULL && is_resampling) {
float* logits = llama_get_logits_ith(ctx_main, idx);
// Apply grammar constraints to all candidates
llama_grammar_sample(ctx_sampling->grammar, ctx_main, &cur_p);
}
if (temp < 0.0) {
// greedy sampling, with probs