Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
14e53ed1
Unverified
Commit
14e53ed1
authored
Apr 02, 2025
by
Russell Bryant
Committed by
GitHub
Apr 02, 2025
Browse files
[V1] Fix json_object support with xgrammar (#15488)
Signed-off-by:
Russell Bryant
<
rbryant@redhat.com
>
parent
ddb94c26
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
10 additions
and
19 deletions
+10
-19
requirements/common.txt
requirements/common.txt
+1
-1
tests/v1/entrypoints/llm/test_struct_output_generate.py
tests/v1/entrypoints/llm/test_struct_output_generate.py
+2
-10
vllm/model_executor/guided_decoding/__init__.py
vllm/model_executor/guided_decoding/__init__.py
+0
-6
vllm/model_executor/guided_decoding/xgrammar_decoding.py
vllm/model_executor/guided_decoding/xgrammar_decoding.py
+4
-1
vllm/v1/structured_output/backend_xgrammar.py
vllm/v1/structured_output/backend_xgrammar.py
+3
-1
No files found.
requirements/common.txt
View file @
14e53ed1
...
@@ -21,7 +21,7 @@ lm-format-enforcer >= 0.10.11, < 0.11
...
@@ -21,7 +21,7 @@ lm-format-enforcer >= 0.10.11, < 0.11
llguidance >= 0.7.9, < 0.8.0; platform_machine == "x86_64" or platform_machine == "arm64" or platform_machine == "aarch64"
llguidance >= 0.7.9, < 0.8.0; platform_machine == "x86_64" or platform_machine == "arm64" or platform_machine == "aarch64"
outlines == 0.1.11
outlines == 0.1.11
lark == 1.2.2
lark == 1.2.2
xgrammar == 0.1.1
6
; platform_machine == "x86_64" or platform_machine == "aarch64"
xgrammar == 0.1.1
7
; platform_machine == "x86_64" or platform_machine == "aarch64"
typing_extensions >= 4.10
typing_extensions >= 4.10
filelock >= 3.16.1 # need to contain https://github.com/tox-dev/filelock/pull/317
filelock >= 3.16.1 # need to contain https://github.com/tox-dev/filelock/pull/317
partial-json-parser # used for parsing partial JSON outputs
partial-json-parser # used for parsing partial JSON outputs
...
...
tests/v1/entrypoints/llm/test_struct_output_generate.py
View file @
14e53ed1
...
@@ -125,17 +125,9 @@ def test_structured_output(
...
@@ -125,17 +125,9 @@ def test_structured_output(
print
(
generated_text
)
print
(
generated_text
)
assert
generated_text
is
not
None
assert
generated_text
is
not
None
# Parse to verify it is valid JSON
# Parse to verify it is
a
valid JSON
object
parsed_json
=
json
.
loads
(
generated_text
)
parsed_json
=
json
.
loads
(
generated_text
)
allowed_types
:
tuple
[
type
,
...]
=
(
dict
,
)
assert
isinstance
(
parsed_json
,
dict
)
if
guided_decoding_backend
.
startswith
(
"xgrammar"
):
# TODO - we are currently too permissive with xgrammar and
# allow # any valid json (typically comes back as a list or
# object). We can fix this by specifying a jsonschema of
# {"type": "object"}, # but we need this fix in a release
# first: https://github.com/mlc-ai/xgrammar/pull/264
allowed_types
=
(
dict
,
list
)
assert
isinstance
(
parsed_json
,
allowed_types
)
#
#
# Test 3: test a jsonschema incompatible with xgrammar
# Test 3: test a jsonschema incompatible with xgrammar
...
...
vllm/model_executor/guided_decoding/__init__.py
View file @
14e53ed1
...
@@ -79,12 +79,6 @@ def maybe_backend_fallback(
...
@@ -79,12 +79,6 @@ def maybe_backend_fallback(
"xgrammar does not support Lark grammars and the "
"xgrammar does not support Lark grammars and the "
"grammar failed to convert to GBNF."
,
"outlines"
)
"grammar failed to convert to GBNF."
,
"outlines"
)
elif
guided_params
.
json_object
:
# https://github.com/mlc-ai/xgrammar/issues/256
fallback_or_error
(
guided_params
,
"xgrammar does not support json_object."
,
"guidance"
)
# If the xgrammar module cannot be imported successfully,
# If the xgrammar module cannot be imported successfully,
# we should still allow users to use guided decoding with a fallback.
# we should still allow users to use guided decoding with a fallback.
elif
not
xgr_installed
:
elif
not
xgr_installed
:
...
...
vllm/model_executor/guided_decoding/xgrammar_decoding.py
View file @
14e53ed1
...
@@ -320,7 +320,10 @@ class XGrammarLogitsProcessor:
...
@@ -320,7 +320,10 @@ class XGrammarLogitsProcessor:
elif
self
.
config
.
grammar_str
is
not
None
:
elif
self
.
config
.
grammar_str
is
not
None
:
self
.
ctx
=
compiler
.
compile_grammar
(
self
.
config
.
grammar_str
)
self
.
ctx
=
compiler
.
compile_grammar
(
self
.
config
.
grammar_str
)
elif
self
.
config
.
json_object
:
elif
self
.
config
.
json_object
:
self
.
ctx
=
compiler
.
compile_builtin_json_grammar
()
any_whitespace
=
self
.
config
.
any_whitespace
self
.
ctx
=
compiler
\
.
compile_json_schema
(
'{"type": "object"}'
,
any_whitespace
=
any_whitespace
)
else
:
else
:
raise
ValueError
(
raise
ValueError
(
"Invalid configuration for xgrammar logits processor"
)
"Invalid configuration for xgrammar logits processor"
)
...
...
vllm/v1/structured_output/backend_xgrammar.py
View file @
14e53ed1
...
@@ -84,7 +84,9 @@ class XgrammarBackend(StructuredOutputBackend):
...
@@ -84,7 +84,9 @@ class XgrammarBackend(StructuredOutputBackend):
ctx
=
self
.
compiler
.
compile_json_schema
(
ctx
=
self
.
compiler
.
compile_json_schema
(
grammar_spec
,
any_whitespace
=
not
self
.
disable_any_whitespace
)
grammar_spec
,
any_whitespace
=
not
self
.
disable_any_whitespace
)
elif
request_type
==
StructuredOutputOptions
.
JSON_OBJECT
:
elif
request_type
==
StructuredOutputOptions
.
JSON_OBJECT
:
ctx
=
self
.
compiler
.
compile_builtin_json_grammar
()
ctx
=
self
.
compiler
.
compile_json_schema
(
'{"type": "object"}'
,
any_whitespace
=
not
self
.
disable_any_whitespace
)
elif
request_type
==
StructuredOutputOptions
.
GRAMMAR
:
elif
request_type
==
StructuredOutputOptions
.
GRAMMAR
:
ctx
=
self
.
compiler
.
compile_grammar
(
grammar_spec
)
ctx
=
self
.
compiler
.
compile_grammar
(
grammar_spec
)
elif
request_type
==
StructuredOutputOptions
.
REGEX
:
elif
request_type
==
StructuredOutputOptions
.
REGEX
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment