-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Bugfix][v1] xgrammar structured output supports Enum. #15594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: chaunceyjiang <[email protected]>
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add 🚀 |
Test whether xgrammar supports enum. import xgrammar as xgr
from xgrammar.testing import _is_grammar_accept_string
import json
# Guided decoding by JSON using Pydantic schema
class CarType(str, Enum): # test Enum
sedan = "sedan"
suv = "SUV"
truck = "Truck"
coupe = "Coupe"
class CarDescription(BaseModel):
brand: str
model: str
car_type: CarType
json_schema = CarDescription.model_json_schema()
instance = CarDescription(brand="Toyota", model="Corolla", car_type="sedan")
json_schema_grammar = xgr.Grammar.from_json_schema(json.dumps(json_schema))
# instance: pydantic model, json string, or any other object (dumped to json string)
if isinstance(instance, BaseModel):
instance = json.dumps(instance.model_dump(mode="json", round_trip=True))
assert _is_grammar_accept_string(json_schema_grammar, instance)
|
test vllm serve Qwen/Qwen2.5-3B-Instruct
# python test.py
[2025-03-27 03:24:41] INFO _client.py:1026: HTTP Request: POST http://localhost:8000/v1/chat/completions "HTTP/1.1 200 OK"
{
"brand": "Ford",
"model": "Mustang",
"car_type": "SUV"
} |
/cc @aarnphm @agm-eratosth @subnet-dev @DarkLight1337 PTAL. |
Much love |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test for this. Thanks.
Signed-off-by: chaunceyjiang <[email protected]>
Signed-off-by: chaunceyjiang <[email protected]>
Signed-off-by: chaunceyjiang <[email protected]>
Signed-off-by: chaunceyjiang <[email protected]>
@DarkLight1337 Hi, Can you help add a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the tests accordingly first.
Signed-off-by: chaunceyjiang <[email protected]>
Signed-off-by: chaunceyjiang <[email protected]>
Signed-off-by: chaunceyjiang <[email protected]>
Signed-off-by: chaunceyjiang <[email protected]>
Signed-off-by: chaunceyjiang <[email protected]>
Signed-off-by: chaunceyjiang <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving to unblock merge once the tests pass
Test passes |
It looks like full CI didn’t run on this PR for some reason before it was merged. It broke a structured output test for V1. See the failure in #15718 |
Oh, my bad. I saw the entrypoints tests pass but forgot about V1. |
@russellb Thanks~ |
Are you able to fix this quickly? |
Okay, I'll check it out right away. |
…15594) Signed-off-by: chaunceyjiang <[email protected]> Signed-off-by: xinyuxiao <[email protected]>
…15594) Signed-off-by: chaunceyjiang <[email protected]> Signed-off-by: Louis Ulmer <[email protected]>
…15594) Signed-off-by: chaunceyjiang <[email protected]>
…15594) Signed-off-by: chaunceyjiang <[email protected]>
…15594) Signed-off-by: chaunceyjiang <[email protected]> Signed-off-by: Mu Huai <[email protected]>
FIX #15236
Structured output supports Enum.