vllm.multimodal.parse
¶
Classes:
-
DictEmbeddingItems–Base class for data items that are expressed as a dictionary of tensors.
-
EmbeddingItems–Base class for data items that are expressed as a batched embedding tensor,
-
ModalityDataItems–Represents data items for a modality in
-
MultiModalDataItems–A normalized
MultiModalDataDict -
MultiModalDataParser–Parses
MultiModalDataDict -
ProcessorBatchItems–Base class for data items that are arranged in a list.
-
VisionChunkProcessorItems–Processor items for vision chunks (unified image and video chunks).
Functions:
-
validate_embedding_ndim–Validate tensor ndim for multimodal embeddings.
Attributes:
-
EmbeddingFieldRole(TypeAlias) –What a field of a pre-computed-embedding input carries.
-
MultiModalUUIDItems(TypeAlias) –A normalized
MultiModalUUIDDict
EmbeddingFieldRole = Literal['values', 'metadata']
module-attribute
¶
What a field of a pre-computed-embedding input carries.
"values" is the embedding tensor itself; "metadata" is a key that sizes the
prompt's placeholder range. The distinction is what lets one declaration serve
both an ordinary request (everything present) and an EC consumer (embeddings
arrive through the connector, metadata still in the request).
MultiModalUUIDItems = dict[str, Sequence[str | None]]
module-attribute
¶
A normalized MultiModalUUIDDict
such that each entry corresponds to a list.
DictEmbeddingItems
¶
Bases: ModalityDataItems[Mapping[str, Tensor], Mapping[str, Tensor]]
Base class for data items that are expressed as a dictionary of tensors.
Usually, the dictionary keys correspond to the outputs of HF processor.
Methods:
-
__init__–Args:
__init__(data, modality, required_fields, fields_factory, optional_fields=frozenset())
¶
Args:
data: The dictionary of tensors for this modality.
modality: The modality these items belong to.
required_fields: Fields data must contain.
fields_factory: Builds the field config from the data.
optional_fields: Fields data may omit. Which fields these are is
the caller's decision -- see
MultiModalDataParser.embedding_field_sets, where a deployment
that receives embeddings through an EC connector makes the
embeddings optional. They still need a field config, since they
are used whenever they are supplied.
EmbeddingItems
¶
Bases: ModalityDataItems[Tensor | list[Tensor], Tensor]
Base class for data items that are expressed as a batched embedding tensor, or a list of embedding tensors (one per item).
_unwrap(item)
¶
Extract media from wrapper if present.
_validate_hidden_size(expected_hidden_size)
¶
Validate that embedding hidden dimension matches expected size.
This validates hidden dimensions to prevent vulnerabilities: Embeddings with correct ndim but wrong hidden dimension could bypass initial checks and cause crashes during model inference when dimensions don't match.
_validate_ndim()
¶
Validate that embedding tensors have correct ndim (2D or 3D).
ModalityDataItems
¶
Represents data items for a modality in
MultiModalDataItems.
Methods:
-
get–Get a data item by its index.
-
get_all–Get all data items.
-
get_count–Get the number of data items.
-
get_passthrough_data–Get the data to pass directly to the model.
-
get_processor_data–Get the data to pass to the HF processor.
get(index)
abstractmethod
¶
Get a data item by its index.
get_all()
¶
Get all data items.
get_count()
abstractmethod
¶
Get the number of data items.
get_passthrough_data()
abstractmethod
¶
Get the data to pass directly to the model.
get_processor_data()
abstractmethod
¶
Get the data to pass to the HF processor.
MultiModalDataItems
¶
Bases: UserDict[str, ModalityDataItems[Any, Any]]
A normalized MultiModalDataDict
such that each entry corresponds to a list.
Methods:
-
get_all_counts–Get the number of items belonging to each modality.
-
get_count–Get the number of data items belonging to a modality.
-
get_items–Get the data items belonging to a modality,
-
select–Construct a new
MultiModalDataItemsinstance containing only the
get_all_counts()
¶
Get the number of items belonging to each modality.
get_count(modality, *, strict=True)
¶
Get the number of data items belonging to a modality.
If strict=False, return 0 instead of raising KeyError
even if the modality is not found.
get_items(modality, typ)
¶
Get the data items belonging to a modality, requiring that they belong to a certain type.
select(modalities)
¶
Construct a new MultiModalDataItems instance containing only the
selected modalities.
MultiModalDataParser
¶
Parses MultiModalDataDict
into MultiModalDataItems.
Parameters:
-
(target_sr¶float, default:None) –Enables automatic resampling of audio items to the model's expected sampling rate.
-
(audio_resample_method¶str, default:'torchaudio') –Backend used for the resampling above. Defaults to torchaudio; models with specific needs may override (e.g. phi4mm uses scipy).
-
(target_channels¶int, default:None) –Target number of audio channels. If provided, normalizes audio to this many channels (e.g., 1 for mono). If None, audio channels are passed through unchanged.
-
(expected_hidden_size¶int, default:None) –Expected hidden dimension for embedding inputs. If provided, validates that user-supplied embeddings have the correct hidden size to prevent crashes during model inference.
-
(allow_missing_mm_embeddings¶bool, default:False) –Whether pre-computed embedding tensors may be absent from the request on a disaggregated consumer. Derived by
BaseProcessingInfo.allow_missing_mm_embeddings.
Methods:
-
embedding_field_sets–modality's (required, optional) fields for this deployment. -
placeholder_metadata_fields–The keys that size
modality's placeholder range.
Attributes:
-
embedding_fields(Mapping[str, Mapping[str, EmbeddingFieldRole]]) –Per-modality field roles for pre-computed-embedding inputs.
embedding_fields = {}
class-attribute
instance-attribute
¶
Per-modality field roles for pre-computed-embedding inputs.
Declared here rather than inside _parse_*_data so an EC producer can read
it too: on a producer the request carries real media, so the branch that
builds DictEmbeddingItems never runs, yet the producer still has to know
which processed keys to publish. One declaration, both sides, no drift.
A modality absent from this mapping can only be sent whole in the request.
_parse_vision_chunk_data(data)
¶
Parse vision chunk data (unified image and video chunks).
embedding_field_sets(modality)
¶
modality's (required, optional) fields for this deployment.
Resolves the static roles in embedding_fields against where the
embeddings actually come from: on an EC consumer they arrive through the
connector, so the request may omit them; anywhere else a request that
claims to carry pre-computed embeddings has to actually carry them.
placeholder_metadata_fields(modality)
classmethod
¶
The keys that size modality's placeholder range.
What an EC producer publishes alongside the embedding, and what a consumer keeps requiring once the embedding itself is gone.
ProcessorBatchItems
¶
Bases: ModalityDataItems[Sequence[_T], _T]
Base class for data items that are arranged in a list.
_unwrap(item)
¶
Extract media from wrapper if present.
VisionChunkProcessorItems
¶
_convert_pil_frames(frames)
¶
Convert PIL video frames to RGB, as is done for PIL images.
validate_embedding_ndim(tensor, modality, index=None)
¶
Validate tensor ndim for multimodal embeddings.
Single embeddings should be 2D (seq_len, hidden_size). Batched embeddings should be 3D (batch, seq_len, hidden_size).
Parameters: