You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems that xgrammar does not support some structured output. The test code is:
class Animals(BaseModel):
location: str
activity: str
animals_seen: conint(ge=1, le=5) # type: ignore # Constrained integer type
animals: list[str]
user_input = "I saw a puppy, a cat and a raccoon during my bike ride in the park"
messages = [
{
"role": "system",
"content": "You are a helpful which converts user input to JSON object. Respond in JSON format.",
},
{
"role": "user",
"content": f"convert to JSON according to provided schema: '{user_input}'",
},
]
logger.info(f"Sending Chat API request to {model_name}")
completion = client.client.chat.completions.create(
model=model_name,
messages=messages,
temperature=0.1,
max_tokens=250,
extra_body=dict(guided_json=json.dumps(Animals.model_json_schema()), guided_decoding_backend="lm-format-enforcer"),
)
assert completion is not None
logger.warning(f"{completion=}")
# check that output JSON has keys according to the schema, assert for values is too brittle (e.g. "park" vs "the park")
assert set(json.loads(completion.choices[0].message.content).keys()) == set(
Animals.model_fields.keys()
)
I set guided_decoding_backend as outlines or lm-format-enforcer, it works fine. However, if I set it as xgrammar, it can not pass the test. The completion is:
Make sure you already searched for relevant issues, and asked the chatbot living at the bottom right corner of the documentation page, which can answer lots of frequently asked questions.
The text was updated successfully, but these errors were encountered:
hustxiayang
changed the title
[Bug]: structured output bug (or just support less) using xgrammar
[Bug]: another example of structured output xgrammar does not support
Jan 14, 2025
For vllm, this should be fixed as of #12210. It will fall back to outlines in this scenario. Please feel free to reopen if you try this fix and have trouble.
Your current environment
The output of `python collect_env.py`
Model Input Dumps
No response
🐛 Describe the bug
It seems that xgrammar does not support some structured output. The test code is:
I set
guided_decoding_backend
asoutlines
orlm-format-enforcer
, it works fine. However, if I set it asxgrammar
, it can not pass the test. The completion is:I tested with llama3.1-8b-instruct, quantized using gpt-w8a8 using llm-compressor. The deployment arguments are:
Thanks a lot!
Before submitting a new issue...
The text was updated successfully, but these errors were encountered: