Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
a7527728
Unverified
Commit
a7527728
authored
Aug 23, 2025
by
Benji Beck
Committed by
GitHub
Aug 24, 2025
Browse files
Migrate Paligemma inputs to TensorSchema (#23470)
Signed-off-by:
Benji Beck
<
benjibeck@meta.com
>
parent
9dc30b70
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
36 deletions
+27
-36
vllm/model_executor/models/paligemma.py
vllm/model_executor/models/paligemma.py
+27
-36
No files found.
vllm/model_executor/models/paligemma.py
View file @
a7527728
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from
collections.abc
import
Iterable
,
Mapping
,
Sequence
from
collections.abc
import
Iterable
,
Mapping
,
Sequence
from
typing
import
Literal
,
Optional
,
TypedDict
,
Union
from
typing
import
Annotated
,
Literal
,
Optional
,
Union
import
torch
import
torch
from
torch
import
nn
from
torch
import
nn
...
@@ -21,6 +21,7 @@ from vllm.multimodal.processing import (BaseMultiModalProcessor,
...
@@ -21,6 +21,7 @@ from vllm.multimodal.processing import (BaseMultiModalProcessor,
PromptUpdateDetails
)
PromptUpdateDetails
)
from
vllm.multimodal.profiling
import
BaseDummyInputsBuilder
from
vllm.multimodal.profiling
import
BaseDummyInputsBuilder
from
vllm.sequence
import
IntermediateTensors
from
vllm.sequence
import
IntermediateTensors
from
vllm.utils.tensor_schema
import
TensorSchema
,
TensorShape
from
.interfaces
import
MultiModalEmbeddings
,
SupportsMultiModal
,
SupportsPP
from
.interfaces
import
MultiModalEmbeddings
,
SupportsMultiModal
,
SupportsPP
from
.siglip
import
SiglipVisionModel
from
.siglip
import
SiglipVisionModel
...
@@ -32,19 +33,27 @@ from .vision import get_vision_encoder_info
...
@@ -32,19 +33,27 @@ from .vision import get_vision_encoder_info
logger
=
init_logger
(
__name__
)
logger
=
init_logger
(
__name__
)
class
PaliGemmaImagePixelInputs
(
TypedDict
):
class
PaliGemmaImagePixelInputs
(
TensorSchema
):
type
:
Literal
[
"pixel_values"
]
"""
data
:
torch
.
Tensor
Dimensions:
"""Shape: `(batch_size * num_images, num_channels, height, width)`"""
- bn: Batch size * number of images
- c: Number of channels (3)
- h: Height
- w: Width
"""
type
:
Literal
[
"pixel_values"
]
=
"pixel_values"
data
:
Annotated
[
torch
.
Tensor
,
TensorShape
(
"bn"
,
3
,
"h"
,
"w"
)]
class
PaliGemmaImageEmbeddingInputs
(
TypedDict
):
type
:
Literal
[
"image_embeds"
]
data
:
torch
.
Tensor
"""Shape: `(batch_size * num_images, image_feature_size, hidden_size)`
`hidden_size` must match the hidden size of language model backbone.
class
PaliGemmaImageEmbeddingInputs
(
TensorSchema
):
"""
"""
Dimensions:
- bn: Batch size * number of images
- ifs: Image feature size
- hs: Hidden size (must match language model backbone)
"""
type
:
Literal
[
"image_embeds"
]
=
"image_embeds"
data
:
Annotated
[
torch
.
Tensor
,
TensorShape
(
"bn"
,
"ifs"
,
"hs"
)]
PaliGemmaImageInputs
=
Union
[
PaliGemmaImagePixelInputs
,
PaliGemmaImageInputs
=
Union
[
PaliGemmaImagePixelInputs
,
...
@@ -279,19 +288,6 @@ class PaliGemmaForConditionalGeneration(nn.Module, SupportsMultiModal,
...
@@ -279,19 +288,6 @@ class PaliGemmaForConditionalGeneration(nn.Module, SupportsMultiModal,
self
.
make_empty_intermediate_tensors
=
(
self
.
make_empty_intermediate_tensors
=
(
self
.
language_model
.
make_empty_intermediate_tensors
)
self
.
language_model
.
make_empty_intermediate_tensors
)
def
_validate_pixel_values
(
self
,
data
:
torch
.
Tensor
)
->
torch
.
Tensor
:
h
=
w
=
self
.
config
.
vision_config
.
image_size
expected_dims
=
(
3
,
h
,
w
)
actual_dims
=
tuple
(
data
.
shape
[
1
:])
if
actual_dims
!=
expected_dims
:
expected_expr
=
(
"batch_size"
,
*
map
(
str
,
expected_dims
))
raise
ValueError
(
f
"The expected shape of pixel values is
{
expected_expr
}
. "
f
"You supplied
{
tuple
(
data
.
shape
)
}
."
)
return
data
def
_parse_and_validate_image_input
(
def
_parse_and_validate_image_input
(
self
,
**
kwargs
:
object
)
->
Optional
[
PaliGemmaImageInputs
]:
self
,
**
kwargs
:
object
)
->
Optional
[
PaliGemmaImageInputs
]:
pixel_values
=
kwargs
.
pop
(
"pixel_values"
,
None
)
pixel_values
=
kwargs
.
pop
(
"pixel_values"
,
None
)
...
@@ -301,22 +297,17 @@ class PaliGemmaForConditionalGeneration(nn.Module, SupportsMultiModal,
...
@@ -301,22 +297,17 @@ class PaliGemmaForConditionalGeneration(nn.Module, SupportsMultiModal,
return
None
return
None
if
pixel_values
is
not
None
:
if
pixel_values
is
not
None
:
if
not
isinstance
(
pixel_values
,
(
torch
.
Tensor
,
list
)):
raise
ValueError
(
"Incorrect type of pixel values. "
f
"Got type:
{
type
(
pixel_values
)
}
"
)
pixel_values
=
flatten_bn
(
pixel_values
,
concat
=
True
)
pixel_values
=
flatten_bn
(
pixel_values
,
concat
=
True
)
return
PaliGemmaImagePixelInputs
(
h
=
w
=
self
.
config
.
vision_config
.
image_size
type
=
"pixel_values"
,
return
PaliGemmaImagePixelInputs
(
type
=
"pixel_values"
,
data
=
self
.
_validate_pixel_values
(
pixel_values
),
data
=
pixel_values
,
)
resolve_bindings
=
{
"h"
:
h
,
"w"
:
w
})
if
image_embeds
is
not
None
:
if
image_embeds
is
not
None
:
if
not
isinstance
(
image_embeds
,
torch
.
Tensor
):
raise
ValueError
(
"Incorrect type of image embeddings. "
f
"Got type:
{
type
(
image_embeds
)
}
"
)
image_embeds
=
flatten_bn
(
image_embeds
,
concat
=
True
)
image_embeds
=
flatten_bn
(
image_embeds
,
concat
=
True
)
return
PaliGemmaImageEmbeddingInputs
(
return
PaliGemmaImageEmbeddingInputs
(
...
...
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