oobabooga/textgen · error · Exception
At least one of the stack should be empty when EOS is reache
Error message
At least one of the stack should be empty when EOS is reached. However, the stacks are {stacks} What it means
Error "At least one of the stack should be empty when EOS is reached. However, the stacks are {stacks}" thrown in oobabooga/textgen.
Source
Thrown at modules/grammar/grammar_utils.py:505
continue
pos += num_chars
new_stack = stack[:-1]
if self.grammar_encoding[pos]:
new_stack.append(pos)
new_stacks.extend(self.advance_stack(tuple(new_stack)))
return new_stacks
def accept_string(self, string: str, stacks: List[List[int]]):
for char in string:
stacks = self.accept_char(char, stacks)
return stacks
def accept_token_id(self, token_id: int, stacks: List[List[int]]):
if token_id == self.eos_token_id:
if stacks and all(len(stack) != 0 for stack in stacks):
raise Exception(
f"At least one of the stack should be empty when EOS is reached. However, "
f"the stacks are {stacks}"
)
return []
for byte in self.token_trie.id2str(token_id):
stacks = self.accept_char(byte, stacks)
# check updated stacks
# TODO, I commented this out because it will fail when the stack is empty
# empty stack means the end of the grammar
# assert stacks != []
return stacks
def accept_token_ids(self, token_ids: List[int], stacks: List[List[int]], as_string=True):
if as_string:
string = self.tokenizer.decode(token_ids)
stacks = self.accept_string(string, stacks)View on GitHub (pinned to ed888c71f2)
Solutions
- Ensure the grammar accepts the full input so all parse stacks are empty at EOS.
- Simplify or correct the grammar rules so parsing terminates cleanly before the end-of-stream token.
When it happens
Trigger: Raised by the grammar FSM when end-of-sequence is reached but at least one grammar stack is non-empty. Triggers when generation stops (EOS) while the GBNF grammar still expects more symbols, typically because the model emitted EOS before completing a grammar-required structure, or because the grammar itself cannot terminate for the produced input.
Common situations: See trigger scenarios.
AI-assisted analysis of oobabooga/textgen@ed888c71f2 (2026-08-15).
Data as JSON: /api/errors/dc7f90bedf8c0e91.
Report an issue: GitHub.