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
e7beff8a
Unverified
Commit
e7beff8a
authored
Apr 11, 2025
by
XinyuanTong
Committed by
GitHub
Apr 11, 2025
Browse files
fix: examples for token_in_token_out_vlm (#5193)
parent
4d2e3051
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
17 deletions
+16
-17
examples/runtime/token_in_token_out/token_in_token_out_vlm_engine.py
...ntime/token_in_token_out/token_in_token_out_vlm_engine.py
+8
-9
examples/runtime/token_in_token_out/token_in_token_out_vlm_server.py
...ntime/token_in_token_out/token_in_token_out_vlm_server.py
+8
-8
No files found.
examples/runtime/token_in_token_out/token_in_token_out_vlm_engine.py
View file @
e7beff8a
import
argparse
import
argparse
import
dataclasses
import
dataclasses
from
io
import
BytesIO
from
typing
import
Tuple
from
typing
import
Tuple
import
requests
from
PIL
import
Image
from
transformers
import
AutoProcessor
from
transformers
import
AutoProcessor
from
sglang
import
Engine
from
sglang
import
Engine
...
@@ -19,20 +16,22 @@ def get_input_ids(
...
@@ -19,20 +16,22 @@ def get_input_ids(
)
->
Tuple
[
list
[
int
],
list
]:
)
->
Tuple
[
list
[
int
],
list
]:
chat_template
=
get_chat_template_by_model_path
(
model_config
.
model_path
)
chat_template
=
get_chat_template_by_model_path
(
model_config
.
model_path
)
text
=
f
"
{
chat_template
.
image_token
}
What is in this picture?"
text
=
f
"
{
chat_template
.
image_token
}
What is in this picture?"
images
=
[
Image
.
open
(
BytesIO
(
requests
.
get
(
DEFAULT_IMAGE_URL
).
content
))]
image_data
=
[
DEFAULT_IMAGE_URL
]
image_data
=
[
DEFAULT_IMAGE_URL
]
processor
=
AutoProcessor
.
from_pretrained
(
processor
=
AutoProcessor
.
from_pretrained
(
model_config
.
model_path
,
trust_remote_code
=
server_args
.
trust_remote_code
model_config
.
model_path
,
trust_remote_code
=
server_args
.
trust_remote_code
)
)
inputs
=
processor
(
input_ids
=
(
text
=
[
text
],
processor
.
tokenizer
(
images
=
images
,
text
=
[
text
],
return_tensors
=
"pt"
,
return_tensors
=
"pt"
,
)
.
input_ids
[
0
]
.
tolist
()
)
)
return
input
s
.
input_ids
[
0
].
tolist
()
,
image_data
return
input
_ids
,
image_data
def
token_in_out_example
(
def
token_in_out_example
(
...
...
examples/runtime/token_in_token_out/token_in_token_out_vlm_server.py
View file @
e7beff8a
...
@@ -5,11 +5,9 @@ python token_in_token_out_vlm_server.py
...
@@ -5,11 +5,9 @@ python token_in_token_out_vlm_server.py
"""
"""
from
io
import
BytesIO
from
typing
import
Tuple
from
typing
import
Tuple
import
requests
import
requests
from
PIL
import
Image
from
transformers
import
AutoProcessor
from
transformers
import
AutoProcessor
from
sglang.lang.chat_template
import
get_chat_template_by_model_path
from
sglang.lang.chat_template
import
get_chat_template_by_model_path
...
@@ -28,18 +26,20 @@ MODEL_PATH = "Qwen/Qwen2-VL-2B"
...
@@ -28,18 +26,20 @@ MODEL_PATH = "Qwen/Qwen2-VL-2B"
def
get_input_ids
()
->
Tuple
[
list
[
int
],
list
]:
def
get_input_ids
()
->
Tuple
[
list
[
int
],
list
]:
chat_template
=
get_chat_template_by_model_path
(
MODEL_PATH
)
chat_template
=
get_chat_template_by_model_path
(
MODEL_PATH
)
text
=
f
"
{
chat_template
.
image_token
}
What is in this picture?"
text
=
f
"
{
chat_template
.
image_token
}
What is in this picture?"
images
=
[
Image
.
open
(
BytesIO
(
requests
.
get
(
DEFAULT_IMAGE_URL
).
content
))]
image_data
=
[
DEFAULT_IMAGE_URL
]
image_data
=
[
DEFAULT_IMAGE_URL
]
processor
=
AutoProcessor
.
from_pretrained
(
MODEL_PATH
)
processor
=
AutoProcessor
.
from_pretrained
(
MODEL_PATH
)
inputs
=
processor
(
input_ids
=
(
text
=
[
text
],
processor
.
tokenizer
(
images
=
images
,
text
=
[
text
],
return_tensors
=
"pt"
,
return_tensors
=
"pt"
,
)
.
input_ids
[
0
]
.
tolist
()
)
)
return
input
s
.
input_ids
[
0
].
tolist
()
,
image_data
return
input
_ids
,
image_data
def
main
():
def
main
():
...
...
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