Multi-Modality

vLLM provides experimental support for multi-modal models through the vllm.multimodal package.

Multi-modal inputs can be passed alongside text and token prompts to supported models via the multi_modal_data field in vllm.inputs.PromptInputs.

Currently, vLLM only has built-in support for image data. You can extend vLLM to process additional modalities by following this guide.

Looking to add your own multi-modal model? Please follow the instructions listed here.

Guides

Module Contents

Registry

vllm.multimodal.MULTIMODAL_REGISTRY = <vllm.multimodal.registry.MultiModalRegistry object>

The global MultiModalRegistry is used by model runners to dispatch data processing according to its modality and the target model.

See also

Input Processing Pipeline

class vllm.multimodal.MultiModalRegistry(*, plugins: Sequence[MultiModalPlugin] = DEFAULT_PLUGINS)[source]

A registry that dispatches data processing to the MultiModalPlugin for each modality.

Base Classes

vllm.multimodal.NestedTensors

The central part of internal API.

This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.

alias of Union[Sequence[Tensor], Tensor]

vllm.multimodal.BatchedTensors

The central part of internal API.

This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.

alias of Union[Dict[str, JSONTree[T]], List[JSONTree[T]], Tuple[JSONTree[T], …], Tensor]

vllm.multimodal.BatchedTensorInputs

The central part of internal API.

This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.

alias of Dict[str, Union[Dict[str, JSONTree[T]], List[JSONTree[T]], Tuple[JSONTree[T], …], Tensor]]

final class vllm.multimodal.MultiModalDataBuiltins(*args, **kwargs)[source]

Bases: dict

Modality types that are predefined by vLLM.

vllm.multimodal.MultiModalDataDict

The central part of internal API.

This represents a generic version of type ‘origin’ with type arguments ‘params’. There are two kind of these aliases: user defined and special. The special ones are wrappers around builtin collections and ABCs in collections.abc. These must have ‘name’ always set. If ‘inst’ is False, then the alias can’t be instantiated, this is used by e.g. typing.List and typing.Dict.

alias of Union[MultiModalDataBuiltins, Mapping[str, Union[object, List[object]]]]

class vllm.multimodal.MultiModalInputs(dict=None, /, **kwargs)[source]

Bases: _MultiModalInputsBase

A dictionary that represents the keyword arguments to forward().

  • static batch(inputs_list: List[MultiModalInputs]) → Dict[str, Dict[str, JSONTree[T]] | List[JSONTree[T]] | Tuple[JSONTree[T], …] | torch.Tensor][source]

    Batch multiple inputs together into a dictionary.

    The resulting dictionary has the same keys as the inputs. If the corresponding value from each input is a tensor and they all share the same shape, the output value is a single batched tensor; otherwise, the output value is a list containing the original value from each input.

class vllm.multimodal.MultiModalPlugin[source]

Bases: ABC

Base class that defines data processing logic for a specific modality.

In particular, we adopt a registry pattern to dispatch data processing according to the model being used (considering that different models may process the same data differently). This registry is in turn used by MultiModalRegistry which acts at a higher level (i.e., the modality of the data).

See also

Adding a Multimodal Plugin

Image Classes

class vllm.multimodal.image.ImagePlugin[source]

Bases: MultiModalPlugin

Plugin for image data.

  • get_data_key() → str[source]

    Get the data key corresponding to the modality.