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
8048c28c
Unverified
Commit
8048c28c
authored
Nov 21, 2024
by
Jake Poznanski
Committed by
GitHub
Nov 21, 2024
Browse files
Fix #2037 - Context length check does not take into out pad tokens for visual models (#2106)
parent
30af7dfb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
67 additions
and
0 deletions
+67
-0
python/sglang/srt/managers/scheduler.py
python/sglang/srt/managers/scheduler.py
+9
-0
test/srt/test_vision_openai_server.py
test/srt/test_vision_openai_server.py
+58
-0
No files found.
python/sglang/srt/managers/scheduler.py
View file @
8048c28c
...
...
@@ -557,6 +557,15 @@ class Scheduler:
req
.
origin_input_ids_unpadded
,
req
.
image_inputs
)
if
len
(
req
.
origin_input_ids
)
>
self
.
max_req_input_len
:
req
.
finished_reason
=
FINISH_ABORT
(
"Image request length is longer than the KV cache pool size or "
"the max context length aborting because you cannot truncate the image embeds"
)
req
.
sampling_params
.
max_new_tokens
=
0
self
.
waiting_queue
.
append
(
req
)
return
req
.
return_logprob
=
recv_req
.
return_logprob
req
.
top_logprobs_num
=
recv_req
.
top_logprobs_num
req
.
stream
=
recv_req
.
stream
...
...
test/srt/test_vision_openai_server.py
View file @
8048c28c
...
...
@@ -364,6 +364,64 @@ class TestQWen2VLServer(TestOpenAIVisionServer):
cls
.
base_url
+=
"/v1"
class
TestQWen2VLServerContextLengthIssue
(
unittest
.
TestCase
):
@
classmethod
def
setUpClass
(
cls
):
cls
.
model
=
"Qwen/Qwen2-VL-7B-Instruct"
cls
.
base_url
=
DEFAULT_URL_FOR_TEST
cls
.
api_key
=
"sk-123456"
cls
.
process
=
popen_launch_server
(
cls
.
model
,
cls
.
base_url
,
timeout
=
DEFAULT_TIMEOUT_FOR_SERVER_LAUNCH
,
api_key
=
cls
.
api_key
,
other_args
=
[
"--chat-template"
,
"qwen2-vl"
,
"--context-length"
,
"300"
,
"--mem-fraction-static=0.80"
,
],
)
cls
.
base_url
+=
"/v1"
@
classmethod
def
tearDownClass
(
cls
):
kill_child_process
(
cls
.
process
.
pid
,
include_self
=
True
)
def
test_chat_completion
(
self
):
client
=
openai
.
Client
(
api_key
=
self
.
api_key
,
base_url
=
self
.
base_url
)
response
=
client
.
chat
.
completions
.
create
(
model
=
"default"
,
messages
=
[
{
"role"
:
"user"
,
"content"
:
[
{
"type"
:
"image_url"
,
"image_url"
:
{
"url"
:
"https://github.com/sgl-project/sglang/blob/main/test/lang/example_image.png?raw=true"
},
},
{
"type"
:
"text"
,
"text"
:
"Give a lengthy description of this picture"
,
},
],
},
],
temperature
=
0
,
)
assert
response
.
choices
[
0
].
finish_reason
==
"abort"
assert
response
.
id
assert
response
.
created
assert
response
.
usage
.
prompt_tokens
>
0
assert
response
.
usage
.
completion_tokens
>
0
assert
response
.
usage
.
total_tokens
>
0
class
TestMllamaServer
(
TestOpenAIVisionServer
):
@
classmethod
def
setUpClass
(
cls
):
...
...
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