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
183df472
Unverified
Commit
183df472
authored
May 01, 2024
by
ZhouXingg
Committed by
GitHub
Apr 30, 2024
Browse files
SamplingParams add "spaces_between_special_tokens" argument (#392)
parent
5c5aba59
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
15 additions
and
1 deletion
+15
-1
python/sglang/backend/runtime_endpoint.py
python/sglang/backend/runtime_endpoint.py
+4
-0
python/sglang/global_config.py
python/sglang/global_config.py
+1
-0
python/sglang/srt/managers/detokenizer_manager.py
python/sglang/srt/managers/detokenizer_manager.py
+2
-1
python/sglang/srt/managers/io_struct.py
python/sglang/srt/managers/io_struct.py
+1
-0
python/sglang/srt/managers/router/model_rpc.py
python/sglang/srt/managers/router/model_rpc.py
+5
-0
python/sglang/srt/sampling_params.py
python/sglang/srt/sampling_params.py
+2
-0
No files found.
python/sglang/backend/runtime_endpoint.py
View file @
183df472
...
@@ -107,6 +107,7 @@ class RuntimeEndpoint(BaseBackend):
...
@@ -107,6 +107,7 @@ class RuntimeEndpoint(BaseBackend):
"text"
:
s
.
text_
,
"text"
:
s
.
text_
,
"sampling_params"
:
{
"sampling_params"
:
{
"skip_special_tokens"
:
global_config
.
skip_special_tokens_in_output
,
"skip_special_tokens"
:
global_config
.
skip_special_tokens_in_output
,
"spaces_between_special_tokens"
:
global_config
.
spaces_between_special_tokens_in_out
,
**
sampling_params
.
to_srt_kwargs
(),
**
sampling_params
.
to_srt_kwargs
(),
},
},
}
}
...
@@ -115,6 +116,7 @@ class RuntimeEndpoint(BaseBackend):
...
@@ -115,6 +116,7 @@ class RuntimeEndpoint(BaseBackend):
"text"
:
s
.
text_
,
"text"
:
s
.
text_
,
"sampling_params"
:
{
"sampling_params"
:
{
"skip_special_tokens"
:
global_config
.
skip_special_tokens_in_output
,
"skip_special_tokens"
:
global_config
.
skip_special_tokens_in_output
,
"spaces_between_special_tokens"
:
global_config
.
spaces_between_special_tokens_in_out
,
"dtype"
:
"int"
,
"dtype"
:
"int"
,
**
sampling_params
.
to_srt_kwargs
(),
**
sampling_params
.
to_srt_kwargs
(),
},
},
...
@@ -145,6 +147,7 @@ class RuntimeEndpoint(BaseBackend):
...
@@ -145,6 +147,7 @@ class RuntimeEndpoint(BaseBackend):
"text"
:
s
.
text_
,
"text"
:
s
.
text_
,
"sampling_params"
:
{
"sampling_params"
:
{
"skip_special_tokens"
:
global_config
.
skip_special_tokens_in_output
,
"skip_special_tokens"
:
global_config
.
skip_special_tokens_in_output
,
"spaces_between_special_tokens"
:
global_config
.
spaces_between_special_tokens_in_out
,
**
sampling_params
.
to_srt_kwargs
(),
**
sampling_params
.
to_srt_kwargs
(),
},
},
}
}
...
@@ -153,6 +156,7 @@ class RuntimeEndpoint(BaseBackend):
...
@@ -153,6 +156,7 @@ class RuntimeEndpoint(BaseBackend):
"text"
:
s
.
text_
,
"text"
:
s
.
text_
,
"sampling_params"
:
{
"sampling_params"
:
{
"skip_special_tokens"
:
global_config
.
skip_special_tokens_in_output
,
"skip_special_tokens"
:
global_config
.
skip_special_tokens_in_output
,
"spaces_between_special_tokens"
:
global_config
.
spaces_between_special_tokens_in_out
,
"dtype"
:
"int"
,
"dtype"
:
"int"
,
**
sampling_params
.
to_srt_kwargs
(),
**
sampling_params
.
to_srt_kwargs
(),
},
},
...
...
python/sglang/global_config.py
View file @
183df472
...
@@ -12,6 +12,7 @@ class GlobalConfig:
...
@@ -12,6 +12,7 @@ class GlobalConfig:
# Output configs
# Output configs
self
.
skip_special_tokens_in_output
=
True
self
.
skip_special_tokens_in_output
=
True
self
.
spaces_between_special_tokens_in_out
=
True
# Optimization configs
# Optimization configs
self
.
eager_fill_image
=
False
self
.
eager_fill_image
=
False
...
...
python/sglang/srt/managers/detokenizer_manager.py
View file @
183df472
...
@@ -38,10 +38,11 @@ class DetokenizerManager:
...
@@ -38,10 +38,11 @@ class DetokenizerManager:
if
isinstance
(
recv_obj
,
BatchTokenIDOut
):
if
isinstance
(
recv_obj
,
BatchTokenIDOut
):
output_tokens
=
recv_obj
.
output_tokens
output_tokens
=
recv_obj
.
output_tokens
# TODO(lmzheng): handle skip_special_tokens per request
# TODO(lmzheng): handle skip_special_tokens
/spaces_between_special_tokens
per request
output_strs
=
self
.
tokenizer
.
batch_decode
(
output_strs
=
self
.
tokenizer
.
batch_decode
(
output_tokens
,
output_tokens
,
skip_special_tokens
=
recv_obj
.
skip_special_tokens
[
0
],
skip_special_tokens
=
recv_obj
.
skip_special_tokens
[
0
],
spaces_between_special_tokens
=
recv_obj
.
spaces_between_special_tokens
[
0
],
)
)
# Trim stop str
# Trim stop str
...
...
python/sglang/srt/managers/io_struct.py
View file @
183df472
...
@@ -97,6 +97,7 @@ class BatchTokenIDOut:
...
@@ -97,6 +97,7 @@ class BatchTokenIDOut:
output_and_jump_forward_strs
:
List
[
str
]
output_and_jump_forward_strs
:
List
[
str
]
hit_stop_str
:
List
[
Optional
[
str
]]
hit_stop_str
:
List
[
Optional
[
str
]]
skip_special_tokens
:
List
[
bool
]
skip_special_tokens
:
List
[
bool
]
spaces_between_special_tokens
:
List
[
bool
]
meta_info
:
List
[
Dict
]
meta_info
:
List
[
Dict
]
finished
:
List
[
bool
]
finished
:
List
[
bool
]
...
...
python/sglang/srt/managers/router/model_rpc.py
View file @
183df472
...
@@ -549,6 +549,7 @@ class ModelRpcServer:
...
@@ -549,6 +549,7 @@ class ModelRpcServer:
output_and_jump_forward_strs
=
[]
output_and_jump_forward_strs
=
[]
output_hit_stop_str
=
[]
output_hit_stop_str
=
[]
output_skip_special_tokens
=
[]
output_skip_special_tokens
=
[]
output_spaces_between_special_tokens
=
[]
output_meta_info
=
[]
output_meta_info
=
[]
output_finished
=
[]
output_finished
=
[]
finished_indices
=
[]
finished_indices
=
[]
...
@@ -575,6 +576,9 @@ class ModelRpcServer:
...
@@ -575,6 +576,9 @@ class ModelRpcServer:
output_skip_special_tokens
.
append
(
output_skip_special_tokens
.
append
(
req
.
sampling_params
.
skip_special_tokens
req
.
sampling_params
.
skip_special_tokens
)
)
output_spaces_between_special_tokens
.
append
(
req
.
sampling_params
.
spaces_between_special_tokens
)
meta_info
=
{
meta_info
=
{
"prompt_tokens"
:
req
.
prompt_tokens
,
"prompt_tokens"
:
req
.
prompt_tokens
,
...
@@ -609,6 +613,7 @@ class ModelRpcServer:
...
@@ -609,6 +613,7 @@ class ModelRpcServer:
output_and_jump_forward_strs
,
output_and_jump_forward_strs
,
output_hit_stop_str
,
output_hit_stop_str
,
output_skip_special_tokens
,
output_skip_special_tokens
,
output_spaces_between_special_tokens
,
output_meta_info
,
output_meta_info
,
output_finished
,
output_finished
,
)
)
...
...
python/sglang/srt/sampling_params.py
View file @
183df472
...
@@ -17,6 +17,7 @@ class SamplingParams:
...
@@ -17,6 +17,7 @@ class SamplingParams:
presence_penalty
:
float
=
0.0
,
presence_penalty
:
float
=
0.0
,
ignore_eos
:
bool
=
False
,
ignore_eos
:
bool
=
False
,
skip_special_tokens
:
bool
=
True
,
skip_special_tokens
:
bool
=
True
,
spaces_between_special_tokens
:
bool
=
True
,
dtype
:
Optional
[
str
]
=
None
,
dtype
:
Optional
[
str
]
=
None
,
regex
:
Optional
[
str
]
=
None
,
regex
:
Optional
[
str
]
=
None
,
)
->
None
:
)
->
None
:
...
@@ -29,6 +30,7 @@ class SamplingParams:
...
@@ -29,6 +30,7 @@ class SamplingParams:
self
.
max_new_tokens
=
max_new_tokens
self
.
max_new_tokens
=
max_new_tokens
self
.
ignore_eos
=
ignore_eos
self
.
ignore_eos
=
ignore_eos
self
.
skip_special_tokens
=
skip_special_tokens
self
.
skip_special_tokens
=
skip_special_tokens
self
.
spaces_between_special_tokens
=
spaces_between_special_tokens
self
.
dtype
=
dtype
self
.
dtype
=
dtype
self
.
regex
=
regex
self
.
regex
=
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