[Feature] Support llguidance for constrained decoding (#3298)

This commit is contained in:
JC1DA
2025-02-26 10:41:49 -08:00
committed by GitHub
parent 44a2c4bd56
commit 7551498a69
8 changed files with 201 additions and 9 deletions

View File

@@ -1,6 +1,8 @@
"""
python3 -m unittest test_ebnf_constrained.TestEBNFConstrained.test_ebnf_generate_email
python3 -m unittest test_ebnf_constrained.TestEBNFConstrained.test_ebnf_generate_greeting
python3 -m unittest test_ebnf_constrained.TestEBNFConstrainedLLGuidance.test_ebnf_generate_email
python3 -m unittest test_ebnf_constrained.TestEBNFConstrainedLLGuidance.test_ebnf_generate_greeting
"""
import json
@@ -17,7 +19,7 @@ from sglang.test.test_utils import (
)
def setup_class(cls, disable_overlap: bool):
def setup_class(cls, backend: str, disable_overlap: bool):
cls.model = DEFAULT_SMALL_MODEL_NAME_FOR_TEST
cls.base_url = DEFAULT_URL_FOR_TEST
cls.ebnf_grammar = 'root ::= "test"' # Default grammar
@@ -26,7 +28,7 @@ def setup_class(cls, disable_overlap: bool):
"--max-running-requests",
"10",
"--grammar-backend",
"xgrammar",
backend,
]
if disable_overlap:
@@ -43,7 +45,7 @@ def setup_class(cls, disable_overlap: bool):
class TestEBNFConstrained(unittest.TestCase):
@classmethod
def setUpClass(cls):
setup_class(cls, disable_overlap=False)
setup_class(cls, "xgrammar", disable_overlap=False)
cls.check_jump_forward = False
@classmethod
@@ -236,5 +238,12 @@ class TestEBNFConstrained(unittest.TestCase):
)
class TestEBNFConstrainedLLGuidance(TestEBNFConstrained):
@classmethod
def setUpClass(cls):
setup_class(cls, "llguidance", disable_overlap=False)
cls.check_jump_forward = False
if __name__ == "__main__":
unittest.main()