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
9085aabd
Unverified
Commit
9085aabd
authored
Mar 08, 2025
by
Russell Bryant
Committed by
GitHub
Mar 08, 2025
Browse files
[benchmarks] Add option to use unique jsonschema for each request (#14457)
Signed-off-by:
Russell Bryant
<
rbryant@redhat.com
>
parent
8d5aa466
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
17 deletions
+41
-17
benchmarks/benchmark_serving_structured_output.py
benchmarks/benchmark_serving_structured_output.py
+41
-17
No files found.
benchmarks/benchmark_serving_structured_output.py
View file @
9085aabd
...
@@ -24,11 +24,13 @@ On the client side, run:
...
@@ -24,11 +24,13 @@ On the client side, run:
"""
"""
import
argparse
import
argparse
import
asyncio
import
asyncio
import
copy
import
dataclasses
import
dataclasses
import
json
import
json
import
os
import
os
import
random
import
random
import
time
import
time
import
uuid
import
warnings
import
warnings
from
collections.abc
import
AsyncGenerator
from
collections.abc
import
AsyncGenerator
from
dataclasses
import
dataclass
from
dataclasses
import
dataclass
...
@@ -109,24 +111,43 @@ class SampleRequest:
...
@@ -109,24 +111,43 @@ class SampleRequest:
def
sample_requests
(
tokenizer
:
PreTrainedTokenizerBase
,
def
sample_requests
(
tokenizer
:
PreTrainedTokenizerBase
,
args
:
argparse
.
Namespace
)
->
list
[
SampleRequest
]:
args
:
argparse
.
Namespace
)
->
list
[
SampleRequest
]:
if
args
.
dataset
==
'json'
:
if
args
.
dataset
==
'json'
or
args
.
dataset
==
'json-unique'
:
if
args
.
json_schema_path
is
None
:
if
args
.
json_schema_path
is
None
:
dir_path
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
dir_path
=
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
))
args
.
json_schema_path
=
os
.
path
.
join
(
dir_path
,
args
.
json_schema_path
=
os
.
path
.
join
(
dir_path
,
"structured_schemas"
,
"structured_schemas"
,
"structured_schema_1.json"
)
"structured_schema_1.json"
)
json_schemas
=
[]
with
open
(
args
.
json_schema_path
)
as
f
:
with
open
(
args
.
json_schema_path
)
as
f
:
schema
=
json
.
load
(
f
)
schema
=
json
.
load
(
f
)
prompt
=
f
"Generate an example of a user profile given the following schema:
{
json
.
dumps
(
schema
)
}
"
# noqa: E501
input_len
=
len
(
tokenizer
(
prompt
).
input_ids
)
if
args
.
dataset
==
'json-unique'
:
print
(
f
"Input length of the prompt:
{
input_len
}
tokens"
)
json_schemas
=
[
copy
.
deepcopy
(
schema
)
for
_
in
range
(
args
.
num_prompts
)
]
for
i
in
range
(
len
(
json_schemas
)):
json_schemas
[
i
][
"properties"
][
f
"__optional_field_
{
uuid
.
uuid4
()
}
"
]
=
{
"type"
:
"string"
,
"description"
:
"An unique optional field to avoid cached schemas"
}
def
gen_prompt
(
index
:
int
):
schema
=
json_schemas
[
index
%
len
(
json_schemas
)]
return
f
"Generate an example of a user profile given the following schema:
{
json
.
dumps
(
schema
)
}
"
# noqa: E501
def
get_schema
(
index
:
int
):
return
json_schemas
[
index
%
len
(
json_schemas
)]
requests
=
[
requests
=
[
SampleRequest
(
prompt
=
prompt
,
SampleRequest
(
prompt
=
gen_
prompt
(
i
)
,
prompt_len
=
input_
len
,
prompt_len
=
len
(
tokenizer
(
gen_prompt
(
i
)).
input_
ids
)
,
expected_output_len
=
args
.
output_len
,
expected_output_len
=
args
.
output_len
,
schema
=
schema
,
schema
=
get_
schema
(
i
)
,
structure_type
=
args
.
structure_type
)
structure_type
=
args
.
structure_type
)
for
_
in
range
(
args
.
num_prompts
)
for
i
in
range
(
args
.
num_prompts
)
]
]
elif
args
.
dataset
==
"grammar"
:
elif
args
.
dataset
==
"grammar"
:
...
@@ -821,10 +842,12 @@ if __name__ == "__main__":
...
@@ -821,10 +842,12 @@ if __name__ == "__main__":
default
=
"/v1/completions"
,
default
=
"/v1/completions"
,
help
=
"API endpoint."
,
help
=
"API endpoint."
,
)
)
parser
.
add_argument
(
parser
.
add_argument
(
"--dataset"
,
"--dataset"
,
default
=
'json'
,
default
=
'json'
,
choices
=
[
choices
=
[
'json'
,
'grammar'
,
'regex'
,
'choice'
,
'xgrammar_bench'
])
'json'
,
'json-unique'
,
'grammar'
,
'regex'
,
'choice'
,
'xgrammar_bench'
])
parser
.
add_argument
(
"--json_schema_path"
,
parser
.
add_argument
(
"--json_schema_path"
,
type
=
str
,
type
=
str
,
default
=
None
,
default
=
None
,
...
@@ -966,11 +989,12 @@ if __name__ == "__main__":
...
@@ -966,11 +989,12 @@ if __name__ == "__main__":
type
=
float
,
type
=
float
,
default
=
1.0
,
default
=
1.0
,
help
=
"Ratio of Structured Outputs requests"
)
help
=
"Ratio of Structured Outputs requests"
)
parser
.
add_argument
(
"--structured-output-backend"
,
parser
.
add_argument
(
type
=
str
,
"--structured-output-backend"
,
choices
=
[
"outlines"
,
"lm-format-enforcer"
,
"xgrammar"
],
type
=
str
,
default
=
"xgrammar"
,
choices
=
[
"outlines"
,
"lm-format-enforcer"
,
"xgrammar"
,
"json-unique"
],
help
=
"Backend to use for structured outputs"
)
default
=
"xgrammar"
,
help
=
"Backend to use for structured outputs"
)
args
=
parser
.
parse_args
()
args
=
parser
.
parse_args
()
main
(
args
)
main
(
args
)
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