vllm.multimodal.processing.context
¶
Classes:
-
BaseProcessingInfo–Base class to provide the information necessary for data processing.
-
InputProcessingContext–Contains information about the model which may be used to
-
TimingContext–Helper class to record execution times during multi-modal processing.
Functions:
-
profiling_media–Exclude internally generated profiling inputs from request limits.
BaseProcessingInfo
¶
Base class to provide the information necessary for data processing.
Methods:
-
get_data_parser–Constructs a parser to preprocess multi-modal data items
-
get_default_tok_params–Construct the default parameters for tokenization.
-
get_hf_processor–Subclasses can override this method to handle
-
get_mm_max_tokens_per_item–Return the maximum number of tokens per item of for each modality.
-
get_supported_mm_limits–Return the maximum supported number of items for each modality.
-
get_supported_mm_processor_kwargs–Return supported kwarg names for each HF processor kwargs scope.
-
get_video_frame_limits–The
max_frames/min_framesof the HF video processor, which the -
parse_mm_data–Normalize
MultiModalDataDict -
validate_num_input_items–Validate a modality count with its input representation available.
-
validate_num_items–Raise
ValueErrorif the number of input items for the given modality
Attributes:
-
allow_missing_mm_embeddings(bool) –Whether pre-computed embedding tensors may be omitted.
-
allowed_mm_limits(Mapping[str, int]) –The maximum allowed number of items for each modality.
-
default_mm_limits(Mapping[str, int]) –Per-modality item caps applied when the operator sets no explicit count.
-
supported_mm_limits(Mapping[str, int | None]) –The maximum supported number of items for each modality.
-
supported_mm_processor_kwargs(dict[str, set[str]]) –Supported kwarg names for each HF processor kwargs scope.
allow_missing_mm_embeddings
property
¶
Whether pre-computed embedding tensors may be omitted.
allowed_mm_limits
cached
property
¶
The maximum allowed number of items for each modality.
default_mm_limits = {}
class-attribute
¶
Per-modality item caps applied when the operator sets no explicit count.
supported_mm_limits
cached
property
¶
The maximum supported number of items for each modality.
supported_mm_processor_kwargs
cached
property
¶
Supported kwarg names for each HF processor kwargs scope.
_get_expected_hidden_size()
¶
Get expected hidden size for embedding validation if mm_embeds are enabled.
This validates hidden dimensions to prevent a vulnerability where embeddings
with correct ndim but wrong shape could cause crashes at inference time.
_merge_and_resolve_mm_processor_kwargs(mm_kwargs)
¶
Merge configured and request mm_processor_kwargs.
Flat kwargs are routed into the HuggingFace processor kwarg scopes that support them after the configured/request merge. When a routed flat value conflicts with an existing scoped value, the scoped value takes precedence.
get_data_parser()
¶
Constructs a parser to preprocess multi-modal data items
before passing them to
_get_hf_mm_inputs.
You can support additional modalities by creating a subclass
of MultiModalDataParser
that has additional subparsers.
get_default_tok_params()
¶
Construct the default parameters for tokenization.
get_hf_processor(**kwargs)
¶
Subclasses can override this method to handle specific kwargs from model config or user inputs.
get_mm_max_tokens_per_item(seq_len, mm_counts)
¶
Return the maximum number of tokens per item of for each modality.
When None (the default) is returned, vLLM will generate dummy inputs
(images/videos) at maximum possible sizes and process them to determine
the maximum token count per modality.
This approach works but can be very slow for certain models (e.g., Qwen2.5-VL), leading to very long startup time. For better performance, each model can override this method to return pre-computed maximum token counts, avoiding the need for dummy input generation and processing.
Note
The maximum number of tokens per item of each modality returned from this function should respect the model's maximum sequence length and the maximum number of items of each modality allowed, and agree with dummy inputs (images/videos) at maximum possible sizes.
get_supported_mm_limits()
¶
Return the maximum supported number of items for each modality.
A value of None means unlimited number of items.
Omitting a modality from the returned dictionary means that it is not supported at all.
get_supported_mm_processor_kwargs()
¶
Return supported kwarg names for each HF processor kwargs scope.
get_video_frame_limits()
¶
The max_frames/min_frames of the HF video processor, which the
video loader samples to; empty for models without one.
parse_mm_data(mm_data, *, validate=True)
¶
Normalize MultiModalDataDict
to MultiModalDataItems
before passing them to
_get_hf_mm_inputs.
validate_num_input_items(modality, num_items, *, is_embedding)
¶
Validate a modality count with its input representation available.
validate_num_items(modality, num_items)
¶
Raise ValueError if the number of input items for the given modality
is invalid.
InputProcessingContext
dataclass
¶
Contains information about the model which may be used to modify the inputs.
Methods:
-
call_hf_processor–Call
hf_processoron the promptdata -
get_hf_config–Get the HuggingFace configuration
-
get_hf_image_processor_config–Get the HuggingFace image processor configuration of the model.
-
get_hf_processor–Get the HuggingFace processor
-
get_hf_processor_kwargs–Resolve the kwargs the Hugging Face processor passes to a modality.
-
get_merged_mm_kwargs–Merge configured and request
mm_processor_kwargs. -
get_mm_config–Get the multimodal config of the model.
-
init_processor–Initialize a HuggingFace-like processor class, merging the
Attributes:
-
model_config(ModelConfig) –The configuration of the model.
-
tokenizer(TokenizerLike | None) –The tokenizer used to tokenize the inputs.
model_config
instance-attribute
¶
The configuration of the model.
tokenizer
instance-attribute
¶
The tokenizer used to tokenize the inputs.
call_hf_processor(hf_processor, data, kwargs={})
¶
Call hf_processor on the prompt data
(text, image, audio...) with configurable options kwargs.
get_hf_config(typ=None)
¶
Get the HuggingFace configuration
(transformers.PreTrainedConfig) of the model,
additionally checking its type.
Raises:
-
TypeError–If the configuration is not of the specified type.
get_hf_image_processor_config()
¶
Get the HuggingFace image processor configuration of the model.
get_hf_processor(typ=None, /, **kwargs)
¶
Get the HuggingFace processor
(transformers.ProcessorMixin) of the model,
additionally checking its type.
Raises:
-
TypeError–If the processor is not of the specified type.
get_hf_processor_kwargs(hf_processor, kwargs, *, scope)
¶
Resolve the kwargs the Hugging Face processor passes to a modality.
get_merged_mm_kwargs(kwargs, *, supported_mm_processor_kwargs=None)
¶
Merge configured and request mm_processor_kwargs.
When supported_mm_processor_kwargs is provided, flat keys are matched
against the keys supported by each HuggingFace processor kwarg scope.
Matching flat keys are routed to every scope that supports them and
removed from the shared flat namespace; keys not supported by any scope
remain flat.
Without supported_mm_processor_kwargs, flat keys already represented
in at least one existing mapping-valued scope are removed from the shared
flat namespace; all other flat keys are left unchanged because there is
no information to determine which scopes should receive them.
get_mm_config()
¶
Get the multimodal config of the model.
Raises:
-
RuntimeError–If the model is not a multimodal model.
init_processor(typ, /, **kwargs)
¶
Initialize a HuggingFace-like processor class, merging the keyword arguments with those in the model's configuration.
TimingContext
dataclass
¶
Helper class to record execution times during multi-modal processing.
Methods:
-
record–Record the execution time for a processing stage.
Attributes:
-
enabled(bool) –If disabled,
TimingContext.recordbecomes a no-op. -
stage_secs(dict[str, float]) –The execution time (in seconds) for each processing stage.
enabled = True
class-attribute
instance-attribute
¶
If disabled, TimingContext.record becomes a no-op.
stage_secs = field(default_factory=dict)
class-attribute
instance-attribute
¶
The execution time (in seconds) for each processing stage.
record(stage)
¶
Record the execution time for a processing stage.
_merge_scoped_mm_processor_value(flat_value, scoped_value)
¶
Merge a flat value with an existing, more specific scoped value.
Mappings are merged recursively; otherwise the scoped value replaces the flat value.
_resolve_mm_processor_kwargs(kwargs, supported_mm_processor_kwargs=None)
¶
Resolve flat processor kwargs into HuggingFace processor kwarg scopes.
With supported_mm_processor_kwargs, each scope lists the flat keys it
supports. Matching flat keys are routed to every scope that supports them,
existing scoped values take precedence, and keys not supported by any scope
remain flat.
Without supported_mm_processor_kwargs, flat keys already represented in
at least one existing mapping-valued scope are removed from the shared flat
namespace; all other flat keys are left unchanged because there is no
information to determine which scopes should receive them.
profiling_media()
¶
Exclude internally generated profiling inputs from request limits.