[Fix] Treat an empty grammar constraint as unset in SamplingParams (#33328)
This commit is contained in:
@@ -189,6 +189,21 @@ class TestProcessReqWithGrammar(unittest.TestCase):
|
||||
("structural_tag", '{"structures": [], "triggers": []}'),
|
||||
)
|
||||
|
||||
def test_falsy_structural_tag_still_resolves_a_key(self):
|
||||
"""The selection chain must cover every value the entry condition admits.
|
||||
A falsy-but-set constraint used to match no branch and hit the key lookup
|
||||
with nothing assigned.
|
||||
"""
|
||||
mgr = self._make_mgr()
|
||||
future = Future()
|
||||
mgr.grammar_backend.get_cached_or_future_value.return_value = (future, False)
|
||||
|
||||
req = _make_req(structural_tag="")
|
||||
result = mgr.process_req_with_grammar(req)
|
||||
|
||||
self.assertTrue(result)
|
||||
self.assertEqual(req.grammar_key, ("structural_tag", ""))
|
||||
|
||||
def test_cache_hit_returns_false(self):
|
||||
"""Cache hit should NOT add to grammar queue."""
|
||||
mgr = self._make_mgr()
|
||||
|
||||
@@ -73,6 +73,16 @@ class TestSamplingParamsInit(CustomTestCase):
|
||||
sp = SamplingParams(stop_token_ids=[])
|
||||
self.assertIsNone(sp.stop_token_ids)
|
||||
|
||||
def test_empty_grammar_constraint_becomes_none(self):
|
||||
"""An empty grammar string means "unset", not "constrain to nothing".
|
||||
Left as "" it reads as set to the is-not-None checks downstream while
|
||||
the constraint selection skips it.
|
||||
"""
|
||||
for field in ("json_schema", "regex", "ebnf", "structural_tag"):
|
||||
with self.subTest(field=field):
|
||||
sp = SamplingParams(**{field: ""})
|
||||
self.assertIsNone(getattr(sp, field))
|
||||
|
||||
|
||||
class TestSamplingParamsVerify(CustomTestCase):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user