From d746484521c527f64b66264bc9d3ecc22b7461c2 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Wed, 23 Jul 2025 11:52:51 -0700 Subject: [PATCH] Handle both int and str types in grammar char processing --- modules/grammar/grammar_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/grammar/grammar_utils.py b/modules/grammar/grammar_utils.py index 7f09ff82..af78f6b9 100644 --- a/modules/grammar/grammar_utils.py +++ b/modules/grammar/grammar_utils.py @@ -463,7 +463,7 @@ class IncrementalGrammarConstraint(GrammarConstraint): super().__init__(grammar_str, start_rule_name, tokenizer) def accept_char(self, char, stacks): - byte = ord(char) + byte = char if isinstance(char, int) else ord(char) new_stacks = [] for stack in stacks: # stack is empty @@ -549,7 +549,7 @@ class IncrementalGrammarConstraint(GrammarConstraint): # For each sub-rule in the grammar, cache whether each byte is accepted. @lru_cache(maxsize=None) def pos_char_acceptance(self, pos, char): - byte = ord(char) + byte = char if isinstance(char, int) else ord(char) num_chars = self.grammar_encoding[pos] pos += 1 for i in range(0, num_chars, 2):