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
8234e663
"git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "6e099e2c8ce4c4f5c7318e970a8c093dc5c7046e"
Unverified
Commit
8234e663
authored
Sep 12, 2024
by
Kaichen Zhang - NTU
Committed by
GitHub
Sep 12, 2024
Browse files
[Minor Fix] Fix llava modalities issue for single-image (#1402)
parent
debbdb51
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
2 deletions
+20
-2
python/sglang/srt/models/llava.py
python/sglang/srt/models/llava.py
+20
-2
No files found.
python/sglang/srt/models/llava.py
View file @
8234e663
...
@@ -185,11 +185,14 @@ class LlavaBaseForCausalLM(nn.Module):
...
@@ -185,11 +185,14 @@ class LlavaBaseForCausalLM(nn.Module):
new_image_features
=
[]
new_image_features
=
[]
height
=
width
=
self
.
num_patches_per_side
height
=
width
=
self
.
num_patches_per_side
for
image_idx
,
image_feature
in
enumerate
(
image_features
):
for
image_idx
,
image_feature
in
enumerate
(
image_features
):
if
modalities_list
[
image_idx
]
==
1
:
if
modalities_list
[
image_idx
]
==
"image"
:
image_aspect_ratio
=
(
image_aspect_ratio
=
(
self
.
config
.
image_aspect_ratio
self
.
config
.
image_aspect_ratio
)
# single image
)
# single image
else
:
elif
(
modalities_list
[
image_idx
]
==
"multi-images"
or
modalities_list
[
image_idx
]
==
"video"
):
image_aspect_ratio
=
"pad"
# multi image
image_aspect_ratio
=
"pad"
# multi image
# image_aspect_ratio = (
# image_aspect_ratio = (
# "anyres" if len(image_sizes[image_idx]) == 1 else "pad"
# "anyres" if len(image_sizes[image_idx]) == 1 else "pad"
...
@@ -319,6 +322,21 @@ class LlavaBaseForCausalLM(nn.Module):
...
@@ -319,6 +322,21 @@ class LlavaBaseForCausalLM(nn.Module):
.
transpose
(
1
,
2
)
.
transpose
(
1
,
2
)
.
contiguous
()
.
contiguous
()
)
# N, C, H*W
)
# N, C, H*W
if
"unpad"
in
self
.
mm_patch_merge_type
:
image_feature
=
torch
.
cat
(
(
image_feature
,
# Expand to (bs, 1, hidden_dim) and concat at the end of the image tokens
self
.
language_model
.
model
.
image_newline
[
None
,
None
].
expand
(
image_feature
.
shape
[
0
],
1
,
image_feature
.
shape
[
-
1
],
),
),
dim
=
1
,
)
new_image_features
.
append
(
image_feature
)
new_image_features
.
append
(
image_feature
)
image_features
=
new_image_features
image_features
=
new_image_features
...
...
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