Skip to content

Commit

Permalink
patch-error-on-invalid-grammar (huggingface#2282)
Browse files Browse the repository at this point in the history
* quick fix

* allow silent failure

* explicit todo that this is only short term
  • Loading branch information
ErikKaum authored and yuanwu2017 committed Sep 25, 2024
1 parent a574381 commit b1d1d26
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion server/text_generation_server/utils/logits_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,13 @@ def _advance(next_token_id, fsm_grammar_state, fsm):
def _cached_compile_fsm(grammar_type, schema, tokenizer):
start_time = time.time()
if grammar_type == GrammarType.GRAMMAR_TYPE_JSON:
schema = build_regex_from_schema(schema)
try:
schema = build_regex_from_schema(schema)
# TODO: this is only here short term to avoid crashing the python server, mid term we want this in the rust/router layer
except Exception as e:
logger.error(f"Error compiling FSM, grammar won't be enforced \n{e}")
# allows everything
schema = "(.*?)"
elif grammar_type == GrammarType.GRAMMAR_TYPE_REGEX:
pass # schema is already a regex just here for clarity
fsm = RegexFSM(schema, tokenizer)
Expand Down

0 comments on commit b1d1d26

Please sign in to comment.