llama : move grammar code into llama-grammar

ggml-ci
This commit is contained in:
Georgi Gerganov 2024-07-16 16:09:08 +03:00
parent 0ddc8e361c
commit 675f305f31
No known key found for this signature in database
GPG key ID: 449E073F9DC10735
12 changed files with 742 additions and 672 deletions

View file

@ -330,7 +330,7 @@ static llama_token llama_sampling_sample_impl(
llama_token_data_array single_token_data_array = { &single_token_data, 1, false };
// Apply grammar constraints to the single token
llama_sample_grammar(ctx_main, &single_token_data_array, ctx_sampling->grammar);
llama_grammar_sample(ctx_main, &single_token_data_array, ctx_sampling->grammar);
// Check if the token is valid according to the grammar by seeing if its logit has been set to -INFINITY
bool is_valid = single_token_data_array.data[0].logit != -INFINITY;
@ -421,7 +421,7 @@ static llama_token_data_array llama_sampling_prepare_impl(
// apply grammar checks before sampling logic
if (apply_grammar && ctx_sampling->grammar != NULL) {
llama_sample_grammar(ctx_main, &cur_p, ctx_sampling->grammar);
llama_grammar_sample(ctx_main, &cur_p, ctx_sampling->grammar);
}
return cur_p;