Skip to content
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

[Bug]: Close feature gaps when using xgrammar for structured output #12131

Open
5 tasks
russellb opened this issue Jan 16, 2025 · 1 comment
Open
5 tasks

[Bug]: Close feature gaps when using xgrammar for structured output #12131

russellb opened this issue Jan 16, 2025 · 1 comment
Labels
bug Something isn't working structured-output

Comments

@russellb
Copy link
Member

russellb commented Jan 16, 2025

🐛 Describe the bug

As of v0.6.5, we use xgrammar as the default backend for structured output. However, not all ways of expressing output requirements are supported. This issue is for tracking the list of known cases needed to be resolved for making xgrammar the default in all cases.

Fallback cases can be found here:

if guided_params.backend == "xgrammar":
# xgrammar only has x86 wheels for linux, fallback to outlines
from vllm.platforms import current_platform
if current_platform.get_cpu_architecture() is not CpuArchEnum.X86:
logger.warning("xgrammar is only supported on x86 CPUs. "
"Falling back to use outlines instead.")
guided_params.backend = "outlines"
# xgrammar doesn't support regex or choice, fallback to outlines
if guided_params.regex is not None or guided_params.choice is not None:
logger.warning(
"xgrammar only supports json or grammar guided decoding. "
"Falling back to use outlines instead.")
guided_params.backend = "outlines"
# xgrammar doesn't support some JSON schema features
elif (guided_params.json is not None
and has_xgrammar_unsupported_json_features(guided_params.json)):
logger.warning(
"xgrammar does not support advanced JSON schema features like "
"patterns or numeric ranges. "
"Falling back to use outlines instead.")
guided_params.backend = "outlines"
# xgrammar only supports GBNF grammars, so we must convert Lark.
# We must check if the grammar is likely Lark and if that
# grammar is convertible to GBNF
elif (guided_params.grammar is not None
and grammar_is_likely_lark(guided_params.grammar)):
try:
convert_lark_to_gbnf(guided_params.grammar)
except Exception:
logger.warning(
"xgrammar does not support Lark grammars and the "
"grammar failed to convert to GBNF. "
"Falling back to use outlines instead.")
guided_params.backend = "outlines"

@Ubospica
Copy link

Hi @russellb , thanks for raising the issue. XGrammar has a project to enhance the quality of the json schema converter and plan to support most of the features. We will track this issue and enhance it accordingly.

russellb added a commit to russellb/vllm that referenced this issue Jan 31, 2025
This commit adds support for using xgrammar with a set of choices.
This can be converted to an EBNF grammar pretty easily, which xgrammar
can work from. This drops a case where we were falling back to outlines.

Part of issue vllm-project#12131

Signed-off-by: Russell Bryant <rbryant@redhat.com>
russellb added a commit to russellb/vllm that referenced this issue Feb 13, 2025
This commit adds support for using xgrammar with a set of choices.
This can be converted to an EBNF grammar pretty easily, which xgrammar
can work from. This drops a case where we were falling back to outlines.

Part of issue vllm-project#12131

Signed-off-by: Russell Bryant <rbryant@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working structured-output
Projects
None yet
Development

No branches or pull requests

2 participants