Skip to content

Commit

Permalink
Resolves ggerganov#3878 by enforcing existence of root node before re…
Browse files Browse the repository at this point in the history
…turning valid grammar structure. This is an alternate fix location to put the required root node in sampling.cpp instead of grammar-parser.cpp.
  • Loading branch information
HanClinto committed Mar 12, 2024
1 parent 8030da7 commit 10ac60b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions common/sampling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ struct llama_sampling_context * llama_sampling_init(const struct llama_sampling_
return nullptr;
}

// Ensure that there is a "root" node.
if (result->parsed_grammar.symbol_ids.find("root") == result->parsed_grammar.symbol_ids.end()) {
fprintf(stderr, "%s: grammar does not contain a 'root' symbol\n", __func__);
delete result;
return nullptr;
}

std::vector<const llama_grammar_element *> grammar_rules(result->parsed_grammar.c_rules());

result->grammar = llama_grammar_init(
Expand Down

0 comments on commit 10ac60b

Please sign in to comment.