llama: various bug fixes (#26051)

This commit is contained in:
Xuan-Son Nguyen
2026-07-24 18:56:42 +02:00
committed by GitHub
parent fa72aeccb2
commit 298219f985
7 changed files with 46 additions and 3 deletions
+12
View File
@@ -1139,6 +1139,18 @@ struct llama_grammar * llama_grammar_init_impl(
vec_rules[i].push_back({LLAMA_GRETYPE_END, 0});
}
// Validate that all rule references point to valid rules
for (size_t i = 0; i < n_rules; i++) {
for (const auto & elem : vec_rules[i]) {
if (elem.type == LLAMA_GRETYPE_RULE_REF) {
if (elem.value >= n_rules || vec_rules[elem.value].empty()) {
LLAMA_LOG_ERROR("invalid grammar: rule %zu references undefined rule %u\n", i, elem.value);
return nullptr;
}
}
}
}
// Check for left recursion
std::vector<bool> rules_visited(n_rules);
std::vector<bool> rules_in_progress(n_rules);