Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
change
sglang
Commits
93dffd69
Unverified
Commit
93dffd69
authored
Sep 16, 2024
by
zifeitong
Committed by
GitHub
Sep 16, 2024
Browse files
Add constrained_json_whitespace_pattern to ServerArgs (#1438)
parent
2abe4f1c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
7 deletions
+17
-7
python/sglang/srt/constrained/fsm_cache.py
python/sglang/srt/constrained/fsm_cache.py
+5
-1
python/sglang/srt/managers/tp_worker.py
python/sglang/srt/managers/tp_worker.py
+5
-6
python/sglang/srt/server_args.py
python/sglang/srt/server_args.py
+7
-0
No files found.
python/sglang/srt/constrained/fsm_cache.py
View file @
93dffd69
...
...
@@ -29,6 +29,7 @@ class FSMCache(BaseToolCache):
tokenizer_args_dict
,
enable
=
True
,
skip_tokenizer_init
=
False
,
constrained_json_whitespace_pattern
=
None
,
):
super
().
__init__
(
enable
=
enable
)
...
...
@@ -63,11 +64,14 @@ class FSMCache(BaseToolCache):
self
.
outlines_tokenizer
.
vocabulary
=
(
self
.
outlines_tokenizer
.
tokenizer
.
get_vocab
()
)
self
.
constrained_json_whitespace_pattern
=
constrained_json_whitespace_pattern
def
init_value
(
self
,
key
):
key_type
,
key_string
=
key
if
key_type
==
"json"
:
regex
=
build_regex_from_schema
(
key_string
,
whitespace_pattern
=
r
"[\n\t ]*"
)
regex
=
build_regex_from_schema
(
key_string
,
whitespace_pattern
=
self
.
constrained_json_whitespace_pattern
)
elif
key_type
==
"regex"
:
regex
=
key_string
else
:
...
...
python/sglang/srt/managers/tp_worker.py
View file @
93dffd69
...
...
@@ -198,6 +198,7 @@ class ModelTpServer:
"trust_remote_code"
:
server_args
.
trust_remote_code
,
},
skip_tokenizer_init
=
server_args
.
skip_tokenizer_init
,
constrained_json_whitespace_pattern
=
server_args
.
constrained_json_whitespace_pattern
,
)
self
.
jump_forward_cache
=
JumpForwardCache
()
...
...
@@ -807,12 +808,10 @@ class ModelTpServer:
unfinished_indices
.
append
(
i
)
if
req
.
finished
()
or
(
(
req
.
stream
and
(
self
.
decode_forward_ct
%
self
.
stream_interval
==
0
or
len
(
req
.
output_ids
)
==
1
)
req
.
stream
and
(
self
.
decode_forward_ct
%
self
.
stream_interval
==
0
or
len
(
req
.
output_ids
)
==
1
)
):
output_rids
.
append
(
req
.
rid
)
...
...
python/sglang/srt/server_args.py
View file @
93dffd69
...
...
@@ -70,6 +70,7 @@ class ServerArgs:
tp_size
:
int
=
1
stream_interval
:
int
=
1
random_seed
:
Optional
[
int
]
=
None
constrained_json_whitespace_pattern
:
Optional
[
str
]
=
None
# Logging
log_level
:
str
=
"info"
...
...
@@ -370,6 +371,12 @@ class ServerArgs:
default
=
ServerArgs
.
random_seed
,
help
=
"The random seed."
,
)
parser
.
add_argument
(
"--constrained-json-whitespace-pattern"
,
type
=
str
,
default
=
ServerArgs
.
constrained_json_whitespace_pattern
,
help
=
r
"Regex pattern for syntactic whitespaces allowed in JSON constrained output. For example, to allow the model generate consecutive whitespaces, set the pattern to [\n\t ]*"
,
)
parser
.
add_argument
(
"--log-level"
,
type
=
str
,
...
...
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