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
OpenDAS
Lmdeploy
Commits
16b4b823
Unverified
Commit
16b4b823
authored
Dec 12, 2023
by
AllentDan
Committed by
GitHub
Dec 12, 2023
Browse files
fix `finish_reason` (#816)
parent
a5b67b95
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
4 deletions
+9
-4
lmdeploy/serve/async_engine.py
lmdeploy/serve/async_engine.py
+7
-4
lmdeploy/serve/openai/api_server.py
lmdeploy/serve/openai/api_server.py
+2
-0
No files found.
lmdeploy/serve/async_engine.py
View file @
16b4b823
...
@@ -204,7 +204,7 @@ class AsyncEngine:
...
@@ -204,7 +204,7 @@ class AsyncEngine:
if
do_preprocess
:
if
do_preprocess
:
prompt
=
self
.
model
.
messages2prompt
(
prompt
,
sequence_start
)
prompt
=
self
.
model
.
messages2prompt
(
prompt
,
sequence_start
)
input_ids
=
self
.
tokenizer
.
encode
(
prompt
,
add_bos
=
sequence_start
)
input_ids
=
self
.
tokenizer
.
encode
(
prompt
,
add_bos
=
sequence_start
)
finish_reason
=
'stop'
if
stop
else
None
finish_reason
=
None
if
self
.
id2step
[
str
(
session_id
)]
+
len
(
if
self
.
id2step
[
str
(
session_id
)]
+
len
(
input_ids
)
+
request_output_len
>=
self
.
tm_model
.
session_len
:
input_ids
)
+
request_output_len
>=
self
.
tm_model
.
session_len
:
finish_reason
=
'length'
finish_reason
=
'length'
...
@@ -247,9 +247,12 @@ class AsyncEngine:
...
@@ -247,9 +247,12 @@ class AsyncEngine:
len
(
input_ids
),
tokens
,
finish_reason
)
len
(
input_ids
),
tokens
,
finish_reason
)
response_size
=
tokens
response_size
=
tokens
finish_reason
=
'length'
\
if
tokens
>=
request_output_len
else
'stop'
# `response_size` might be note updated since
# `response_size` might be note updated since
# ` if response.endswith('�')`
# ` if response.endswith('�')`
if
response_size
!=
tokens
:
if
response_size
==
tokens
:
response
=
''
# avaid returning the last response twice
yield
GenOut
(
response
,
self
.
id2step
[
str
(
session_id
)],
yield
GenOut
(
response
,
self
.
id2step
[
str
(
session_id
)],
len
(
input_ids
),
tokens
,
finish_reason
)
len
(
input_ids
),
tokens
,
finish_reason
)
# update step
# update step
...
...
lmdeploy/serve/openai/api_server.py
View file @
16b4b823
...
@@ -179,6 +179,7 @@ async def chat_completions_v1(request: ChatCompletionRequest,
...
@@ -179,6 +179,7 @@ async def chat_completions_v1(request: ChatCompletionRequest,
response_json
=
create_stream_response_json
(
response_json
=
create_stream_response_json
(
index
=
0
,
index
=
0
,
text
=
res
.
response
,
text
=
res
.
response
,
finish_reason
=
res
.
finish_reason
,
)
)
yield
f
'data:
{
response_json
}
\n\n
'
yield
f
'data:
{
response_json
}
\n\n
'
yield
'data: [DONE]
\n\n
'
yield
'data: [DONE]
\n\n
'
...
@@ -329,6 +330,7 @@ async def completions_v1(request: CompletionRequest,
...
@@ -329,6 +330,7 @@ async def completions_v1(request: CompletionRequest,
response_json
=
create_stream_response_json
(
response_json
=
create_stream_response_json
(
index
=
0
,
index
=
0
,
text
=
res
.
response
,
text
=
res
.
response
,
finish_reason
=
res
.
finish_reason
,
)
)
yield
f
'data:
{
response_json
}
\n\n
'
yield
f
'data:
{
response_json
}
\n\n
'
yield
'data: [DONE]
\n\n
'
yield
'data: [DONE]
\n\n
'
...
...
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