Skip to content

vllm.multimodal

Modules:

Classes:

Attributes:

BatchedTensorInputs = dict[str, NestedTensors] module-attribute

A dictionary containing nested tensors which have been batched via MultiModalKwargsItems.get_data.

MULTIMODAL_REGISTRY = MultiModalRegistry() module-attribute

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

Info

mm_processing

NestedTensors = Union[list['NestedTensors'], list['torch.Tensor'], 'torch.Tensor', tuple['torch.Tensor', ...]] module-attribute

Uses a list instead of a tensor if the dimensions of each element do not match.

MultiModalHasher

Derives multi-modal cache keys.

Every method here yields framed chunks: each chunk is preceded by its length and each container by its kind, so that the concatenation fed to the digest is uniquely decodable and distinct inputs cannot share a key.

Methods:

iter_item_to_bytes(key, obj) classmethod

Yield the digest input for a single key/obj pair.

iter_value_to_bytes(obj) classmethod

Yield the digest input for a value, tagged by its container kind.

Containers carry their kind and length so that a nested structure can never serialize to the same bytes as a differently shaped one (a list and a mapping keyed by stringified indices, for example).

MultiModalKwargsItems

Bases: UserDict[str, Sequence[_I]]

A dictionary of processed multi-modal inputs by modality.

For example, given a processor that processes images into pixel_values and image_grid_thw, and audios into input_audio_features, a prompt with 2 images and 1 audio will be processed into a MultiModalKwargsItems with the following structure:

MultiModalKwargsItems(
    {
        "image": [
            # For the first image
            MultiModalKwargsItem({"pixel_values": ..., "image_grid_thw": ...}),
            # For the second imgae
            MultiModalKwargsItem({"pixel_values": ..., "image_grid_thw": ...}),
        ],
        "audio": [
            # For the first audio
            MultiModalKwargsItem({"input_audio_features": ...}),
        ],
    }
)

Unlike HF processing which returns all items in a single dictionary with batched keyword arguments, we split up the items because some of them may already be cached. Also, items from multiple requests may be batched together to improve throughput, using the logic defined by the BaseMultiModalField for each keyword argument.

Methods:

  • get_data –

    Construct a dictionary of keyword arguments to pass to the model.

get_data(*, device=None, pin_memory=False)

Construct a dictionary of keyword arguments to pass to the model.

MultiModalRegistry

A registry that dispatches data processing according to the model.

Methods:

  • create_processor –

    Create a multi-modal processor for a specific model and tokenizer.

  • register_processor –

    Register a multi-modal processor to a model class. The processor

create_processor(model_config, *, tokenizer=None)

Create a multi-modal processor for a specific model and tokenizer.

register_processor(processor, *, info, dummy_inputs)

Register a multi-modal processor to a model class. The processor is constructed lazily, hence a factory method should be passed.

When the model receives multi-modal data, the provided function is invoked to transform the data into a dictionary of model inputs.