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
489796c7
Commit
489796c7
authored
Jan 24, 2024
by
Ying Sheng
Browse files
minor performance fix
parent
fa7a696d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
5 deletions
+6
-5
python/sglang/srt/managers/tokenizer_manager.py
python/sglang/srt/managers/tokenizer_manager.py
+6
-5
No files found.
python/sglang/srt/managers/tokenizer_manager.py
View file @
489796c7
...
@@ -50,8 +50,7 @@ def init_global_processor(server_args: ServerArgs):
...
@@ -50,8 +50,7 @@ def init_global_processor(server_args: ServerArgs):
)
)
def
get_pixel_values
(
image_data
,
model_cfg
,
processor
=
None
):
def
get_pixel_values
(
image_data
,
image_aspect_ratio
=
None
,
image_grid_pinpoints
=
None
,
processor
=
None
):
image_aspect_ratio
=
getattr
(
model_cfg
,
"image_aspect_ratio"
,
None
)
try
:
try
:
processor
=
processor
or
global_processor
processor
=
processor
or
global_processor
image
=
load_image
(
image_data
)
image
=
load_image
(
image_data
)
...
@@ -63,7 +62,7 @@ def get_pixel_values(image_data, model_cfg, processor=None):
...
@@ -63,7 +62,7 @@ def get_pixel_values(image_data, model_cfg, processor=None):
pixel_values
=
processor
.
image_processor
(
image
)[
"pixel_values"
][
0
]
pixel_values
=
processor
.
image_processor
(
image
)[
"pixel_values"
][
0
]
elif
image_aspect_ratio
==
"anyres"
:
elif
image_aspect_ratio
==
"anyres"
:
pixel_values
=
process_anyres_image
(
pixel_values
=
process_anyres_image
(
image
,
processor
.
image_processor
,
model_cfg
.
image_grid_pinpoints
image
,
processor
.
image_processor
,
image_grid_pinpoints
)
)
else
:
else
:
pixel_values
=
processor
.
image_processor
(
image
)[
"pixel_values"
][
0
]
pixel_values
=
processor
.
image_processor
(
image
)[
"pixel_values"
][
0
]
...
@@ -117,13 +116,15 @@ class TokenizerManager:
...
@@ -117,13 +116,15 @@ class TokenizerManager:
self
.
rid_to_state
=
{}
# Dict[str -> ReqState]
self
.
rid_to_state
=
{}
# Dict[str -> ReqState]
async
def
get_pixel_values
(
self
,
image_data
):
async
def
get_pixel_values
(
self
,
image_data
):
aspect_ratio
=
getattr
(
self
.
hf_config
,
"image_aspect_ratio"
,
None
)
grid_pinpoints
=
self
.
hf_config
.
image_grid_pinpoints
if
aspect_ratio
==
"anyres"
else
None
if
self
.
executor
is
not
None
:
if
self
.
executor
is
not
None
:
loop
=
asyncio
.
get_event_loop
()
loop
=
asyncio
.
get_event_loop
()
return
await
loop
.
run_in_executor
(
return
await
loop
.
run_in_executor
(
self
.
executor
,
get_pixel_values
,
image_data
,
self
.
hf_config
self
.
executor
,
get_pixel_values
,
image_data
,
aspect_ratio
,
grid_pinpoints
)
)
else
:
else
:
return
get_pixel_values
(
image_data
,
self
.
hf_config
,
self
.
processor
)
return
get_pixel_values
(
image_data
,
aspect_ratio
,
grid_pinpoints
,
self
.
processor
)
async
def
generate_request
(
self
,
obj
:
GenerateReqInput
):
async
def
generate_request
(
self
,
obj
:
GenerateReqInput
):
if
self
.
to_create_loop
:
if
self
.
to_create_loop
:
...
...
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