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
fbd6b94d
Unverified
Commit
fbd6b94d
authored
Aug 02, 2024
by
Ying Sheng
Committed by
GitHub
Aug 02, 2024
Browse files
Fix the double BOS problem in the HF chat template (#888)
parent
4c8093c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
6 deletions
+7
-6
python/sglang/srt/openai_api/adapter.py
python/sglang/srt/openai_api/adapter.py
+7
-6
No files found.
python/sglang/srt/openai_api/adapter.py
View file @
fbd6b94d
...
...
@@ -594,7 +594,7 @@ async def v1_completions(tokenizer_manager, raw_request: Request):
def
v1_chat_generate_request
(
all_requests
,
tokenizer_manager
):
text
s
=
[]
input_id
s
=
[]
sampling_params_list
=
[]
image_data_list
=
[]
return_logprobs
=
[]
...
...
@@ -608,8 +608,8 @@ def v1_chat_generate_request(all_requests, tokenizer_manager):
if
not
isinstance
(
request
.
messages
,
str
):
# Apply chat template and its stop strings.
if
chat_template_name
is
None
:
prompt
=
tokenizer_manager
.
tokenizer
.
apply_chat_template
(
request
.
messages
,
tokenize
=
Fals
e
,
add_generation_prompt
=
True
prompt
_ids
=
tokenizer_manager
.
tokenizer
.
apply_chat_template
(
request
.
messages
,
tokenize
=
Tru
e
,
add_generation_prompt
=
True
)
stop
=
request
.
stop
image_data
=
None
...
...
@@ -623,12 +623,13 @@ def v1_chat_generate_request(all_requests, tokenizer_manager):
stop
.
append
(
request
.
stop
)
else
:
stop
.
extend
(
request
.
stop
)
prompt_ids
=
tokenizer_manager
.
tokenizer
.
encode
(
prompt
)
else
:
# Use the raw prompt and stop strings if the messages is already a string.
prompt
=
request
.
messages
stop
=
request
.
stop
image_data
=
None
text
s
.
append
(
prompt
)
input_id
s
.
append
(
prompt
_ids
)
return_logprobs
.
append
(
request
.
logprobs
)
top_logprobs_nums
.
append
(
request
.
top_logprobs
)
sampling_params_list
.
append
(
...
...
@@ -645,13 +646,13 @@ def v1_chat_generate_request(all_requests, tokenizer_manager):
)
image_data_list
.
append
(
image_data
)
if
len
(
all_requests
)
==
1
:
texts
=
text
s
[
0
]
input_ids
=
input_id
s
[
0
]
sampling_params_list
=
sampling_params_list
[
0
]
image_data
=
image_data_list
[
0
]
return_logprobs
=
return_logprobs
[
0
]
top_logprobs_nums
=
top_logprobs_nums
[
0
]
adapted_request
=
GenerateReqInput
(
text
=
text
s
,
input_ids
=
input_id
s
,
image_data
=
image_data
,
sampling_params
=
sampling_params_list
,
return_logprob
=
return_logprobs
,
...
...
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