mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2024-12-25 05:48:47 +01:00
Optimization: eliminate addition of redundant stacks when advancing grammar. (#6616)
This commit is contained in:
parent
f7001ccc5a
commit
04a5ac211e
@ -11861,7 +11861,9 @@ static void llama_grammar_advance_stack(
|
|||||||
std::vector<std::vector<const llama_grammar_element *>> & new_stacks) {
|
std::vector<std::vector<const llama_grammar_element *>> & new_stacks) {
|
||||||
|
|
||||||
if (stack.empty()) {
|
if (stack.empty()) {
|
||||||
new_stacks.emplace_back(stack);
|
if (std::find(new_stacks.begin(), new_stacks.end(), stack) == new_stacks.end()) {
|
||||||
|
new_stacks.emplace_back(stack);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -11898,7 +11900,10 @@ static void llama_grammar_advance_stack(
|
|||||||
}
|
}
|
||||||
case LLAMA_GRETYPE_CHAR:
|
case LLAMA_GRETYPE_CHAR:
|
||||||
case LLAMA_GRETYPE_CHAR_NOT:
|
case LLAMA_GRETYPE_CHAR_NOT:
|
||||||
new_stacks.emplace_back(stack);
|
if (std::find(new_stacks.begin(), new_stacks.end(), stack) == new_stacks.end()) {
|
||||||
|
// only add the stack if it's not a duplicate of one we already have
|
||||||
|
new_stacks.emplace_back(stack);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// end of alternate (LLAMA_GRETYPE_END, LLAMA_GRETYPE_ALT) or middle of char range
|
// end of alternate (LLAMA_GRETYPE_END, LLAMA_GRETYPE_ALT) or middle of char range
|
||||||
|
Loading…
Reference in New Issue
Block a user