summaryrefslogtreecommitdiff
path: root/common/sampling.cpp
diff options
context:
space:
mode:
authorClint Herron <hanclinto@gmail.com>2024-03-13 14:10:40 -0400
committerGitHub <noreply@github.com>2024-03-13 20:10:40 +0200
commit463628372d5fe3a0c1e5864aa5fc57deb7387039 (patch)
treec12ed73809a49ddd74d1c826ff69d70c05969587 /common/sampling.cpp
parentf30ea47a87ed4446ad55adb265755dc9102956a2 (diff)
grammar : handle missing "root" node (#6004)
Diffstat (limited to 'common/sampling.cpp')
-rw-r--r--common/sampling.cpp7
1 files changed, 7 insertions, 0 deletions
diff --git a/common/sampling.cpp b/common/sampling.cpp
index 823031fe..5a545098 100644
--- a/common/sampling.cpp
+++ b/common/sampling.cpp
@@ -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(