fix bugs with empty token and EOS

This commit is contained in:
Evan Jones 2023-06-14 23:53:55 -04:00
parent 421c6e1ca1
commit b876d19cff

View file

@ -2295,7 +2295,9 @@ void llama_sample_grammar(struct llama_context * ctx, llama_token_data_array * c
// full matching prefix of the selected token // full matching prefix of the selected token
const bool valid = str[0] == ' ' const bool valid = str[0] == ' '
? llama_grammar_peek(stacks_after_space, str[1]) ? llama_grammar_peek(stacks_after_space, str[1])
: llama_grammar_peek(grammar->stacks, id == eos ? 0 : str[0]); : str[0] || id == eos
? llama_grammar_peek(grammar->stacks, id == eos ? 0 : str[0])
: false;
if (!valid) { if (!valid) {
candidates->data[i].logit = -INFINITY; candidates->data[i].logit = -INFINITY;
@ -2438,8 +2440,8 @@ llama_token llama_grammar_accept_token(struct llama_context * ctx, struct llama_
if (stack.empty()) { if (stack.empty()) {
return token; return token;
} }
LLAMA_ASSERT(false);
} }
LLAMA_ASSERT(false);
} }
const char * str = llama_token_to_str(ctx, token); const char * str = llama_token_to_str(ctx, token);