Add option to disable any_whitespace for xgrammar and llguidance backends. (#8919)

Co-authored-by: Chang Su <chang.s.su@oracle.com>
This commit is contained in:
Lorenzo Lu
2025-10-11 22:24:58 +08:00
committed by GitHub
co-authored by Chang Su
parent 5061b8fd3e
commit b5dcfd4154
5 changed files with 21 additions and 4 deletions
@@ -224,13 +224,17 @@ def create_grammar_backend(
eos_list = list(eos_token_ids) if eos_token_ids else None
grammar_backend = XGrammarGrammarBackend(
tokenizer, vocab_size=vocab_size, model_eos_token_ids=eos_list
tokenizer,
vocab_size=vocab_size,
model_eos_token_ids=eos_list,
any_whitespace=not server_args.constrained_json_disable_any_whitespace,
)
elif name == "llguidance":
from sglang.srt.constrained.llguidance_backend import GuidanceBackend
grammar_backend = GuidanceBackend(
tokenizer=tokenizer,
any_whitespace=not server_args.constrained_json_disable_any_whitespace,
whitespace_pattern=server_args.constrained_json_whitespace_pattern,
)
elif name == "none":