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
e92d7085
Unverified
Commit
e92d7085
authored
Apr 12, 2025
by
leon-seidel
Committed by
GitHub
Apr 11, 2025
Browse files
[Feature][V1] Add xgrammar to support minLength, maxLength with test (#16516)
Signed-off-by:
Leon Seidel
<
leon.seidel@fau.de
>
parent
bd6028d6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
10 deletions
+48
-10
tests/v1/entrypoints/llm/test_struct_output_generate.py
tests/v1/entrypoints/llm/test_struct_output_generate.py
+39
-0
tests/v1/structured_output/test_utils.py
tests/v1/structured_output/test_utils.py
+8
-8
vllm/v1/structured_output/utils.py
vllm/v1/structured_output/utils.py
+1
-2
No files found.
tests/v1/entrypoints/llm/test_struct_output_generate.py
View file @
e92d7085
...
@@ -325,6 +325,45 @@ def test_structured_output(
...
@@ -325,6 +325,45 @@ def test_structured_output(
output_json
=
json
.
loads
(
generated_text
)
output_json
=
json
.
loads
(
generated_text
)
jsonschema
.
validate
(
instance
=
output_json
,
schema
=
json_schema
)
jsonschema
.
validate
(
instance
=
output_json
,
schema
=
json_schema
)
#
# Test 10: Generate structured with minLength and maxLength
#
min_length
=
50
max_length
=
50
json_schema
=
{
"type"
:
"object"
,
"properties"
:
{
"description"
:
{
"type"
:
"string"
,
"maxLength"
:
max_length
,
"minLength"
:
min_length
}
},
"required"
:
[
"description"
]
}
sampling_params
=
SamplingParams
(
temperature
=
1.0
,
max_tokens
=
1000
,
guided_decoding
=
GuidedDecodingParams
(
json
=
json_schema
))
outputs
=
llm
.
generate
(
prompts
=
"Generate a description of a frog using 50 characters."
,
sampling_params
=
sampling_params
,
use_tqdm
=
True
)
assert
outputs
is
not
None
for
output
in
outputs
:
assert
output
is
not
None
assert
isinstance
(
output
,
RequestOutput
)
prompt
=
output
.
prompt
generated_text
=
output
.
outputs
[
0
].
text
assert
generated_text
is
not
None
print
(
f
"Prompt:
{
prompt
!
r
}
, Generated text:
{
generated_text
!
r
}
"
)
output_json
=
json
.
loads
(
generated_text
)
jsonschema
.
validate
(
instance
=
output_json
,
schema
=
json_schema
)
@
pytest
.
mark
.
skip_global_cleanup
@
pytest
.
mark
.
skip_global_cleanup
@
pytest
.
mark
.
parametrize
(
"model_name, tokenizer_mode"
,
@
pytest
.
mark
.
parametrize
(
"model_name, tokenizer_mode"
,
...
...
tests/v1/structured_output/test_utils.py
View file @
e92d7085
...
@@ -13,14 +13,6 @@ def unsupported_string_schemas():
...
@@ -13,14 +13,6 @@ def unsupported_string_schemas():
"type"
:
"string"
,
"type"
:
"string"
,
"pattern"
:
"^[a-zA-Z]+$"
"pattern"
:
"^[a-zA-Z]+$"
},
},
{
"type"
:
"string"
,
"minLength"
:
1
},
{
"type"
:
"string"
,
"maxLength"
:
100
},
{
{
"type"
:
"string"
,
"type"
:
"string"
,
"format"
:
"email"
"format"
:
"email"
...
@@ -164,6 +156,14 @@ def supported_schema():
...
@@ -164,6 +156,14 @@ def supported_schema():
"type"
:
"string"
,
"type"
:
"string"
,
"enum"
:
[
"sedan"
,
"suv"
,
"truck"
]
"enum"
:
[
"sedan"
,
"suv"
,
"truck"
]
},
},
"short_description"
:
{
"type"
:
"string"
,
"maxLength"
:
50
},
"long_description"
:
{
"type"
:
"string"
,
"minLength"
:
50
},
"address"
:
{
"address"
:
{
"type"
:
"object"
,
"type"
:
"object"
,
"properties"
:
{
"properties"
:
{
...
...
vllm/v1/structured_output/utils.py
View file @
e92d7085
...
@@ -41,8 +41,7 @@ def has_xgrammar_unsupported_json_features(schema: dict[str, Any]) -> bool:
...
@@ -41,8 +41,7 @@ def has_xgrammar_unsupported_json_features(schema: dict[str, Any]) -> bool:
return
True
return
True
# Unsupported keywords for strings
# Unsupported keywords for strings
if
obj
.
get
(
"type"
)
==
"string"
and
any
(
if
obj
.
get
(
"type"
)
==
"string"
and
"format"
in
obj
:
key
in
obj
for
key
in
(
"minLength"
,
"maxLength"
,
"format"
)):
return
True
return
True
# Unsupported keywords for objects
# Unsupported keywords for objects
...
...
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