Skip to content

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:

Attributes:

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:

Attributes:

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_hf_config() -> PreTrainedConfig
get_hf_config(typ: type[_C] | tuple[type[_C], ...]) -> _C

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_hf_processor(**kwargs: object) -> ProcessorMixin
get_hf_processor(
    typ: type[_P] | tuple[type[_P], ...],
    /,
    **kwargs: object,
) -> _P

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:

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 = 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.