vllm.multimodal
Modules:
Name | Description |
---|---|
audio | |
base | |
cache | |
hasher | |
image | |
inputs | |
parse | |
processing | |
profiling | |
registry | |
utils | |
video | |
BatchedTensorInputs module-attribute
¶
BatchedTensorInputs: TypeAlias = Mapping[str, NestedTensors]
A dictionary containing nested tensors which have been batched via MultiModalKwargs.batch
.
MULTIMODAL_REGISTRY module-attribute
¶
MULTIMODAL_REGISTRY = MultiModalRegistry()
The global MultiModalRegistry
is used by model runners to dispatch data processing according to the target model.
Info
ModalityData module-attribute
¶
Either a single data item, or a list of data items.
The number of data items allowed per modality is restricted by --limit-mm-per-prompt
.
MultiModalDataDict module-attribute
¶
MultiModalDataDict: TypeAlias = Mapping[
str, ModalityData[Any]
]
A dictionary containing an entry for each modality type to input.
The built-in modalities are defined by MultiModalDataBuiltins
.
MultiModalHashDict module-attribute
¶
A dictionary containing hashes for items in each modality.
MultiModalPlaceholderDict module-attribute
¶
MultiModalPlaceholderDict: TypeAlias = Mapping[
str, Sequence[PlaceholderRange]
]
A dictionary containing placeholder ranges for each modality.
NestedTensors module-attribute
¶
NestedTensors: TypeAlias = Union[
list["NestedTensors"],
list["torch.Tensor"],
"torch.Tensor",
tuple["torch.Tensor", ...],
]
Uses a list instead of a tensor if the dimensions of each element do not match.
__all__ module-attribute
¶
__all__ = [
"BatchedTensorInputs",
"ModalityData",
"MultiModalDataBuiltins",
"MultiModalDataDict",
"MultiModalHashDict",
"MultiModalHasher",
"MultiModalKwargs",
"MultiModalKwargsItems",
"MultiModalPlaceholderDict",
"MultiModalPlaceholderMap",
"NestedTensors",
"MULTIMODAL_REGISTRY",
"MultiModalRegistry",
]
MultiModalDataBuiltins ¶
Bases: TypedDict
Type annotations for modality types predefined by vLLM.
Source code in vllm/multimodal/inputs.py
MultiModalHasher ¶
Source code in vllm/multimodal/hasher.py
hash_kwargs classmethod
¶
Source code in vllm/multimodal/hasher.py
item_to_bytes classmethod
¶
iter_item_to_bytes classmethod
¶
Source code in vllm/multimodal/hasher.py
serialize_item classmethod
¶
serialize_item(obj: object) -> Union[bytes, memoryview]
Source code in vllm/multimodal/hasher.py
MultiModalKwargs ¶
Bases: UserDict[str, NestedTensors]
A dictionary that represents the keyword arguments to torch.nn.Module.forward
.
Source code in vllm/multimodal/inputs.py
738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 |
|
__eq__ ¶
_try_stack staticmethod
¶
_try_stack(
nested_tensors: NestedTensors, pin_memory: bool = False
) -> NestedTensors
Stack the inner dimensions that have the same shape in a nested list of tensors.
Thus, a dimension represented by a list means that the inner dimensions are different for each element along that dimension.
Source code in vllm/multimodal/inputs.py
as_kwargs staticmethod
¶
as_kwargs(
batched_inputs: BatchedTensorInputs, *, device: Device
) -> BatchedTensorInputs
Source code in vllm/multimodal/inputs.py
batch staticmethod
¶
batch(
inputs_list: list[MultiModalKwargs],
pin_memory: bool = False,
) -> BatchedTensorInputs
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.
Source code in vllm/multimodal/inputs.py
from_hf_inputs staticmethod
¶
from_hf_inputs(
hf_inputs: BatchFeature,
config_by_key: Mapping[str, MultiModalFieldConfig],
)
Source code in vllm/multimodal/inputs.py
from_items staticmethod
¶
from_items(
items: Sequence[MultiModalKwargsItem],
*,
pin_memory: bool = False,
)
Source code in vllm/multimodal/inputs.py
MultiModalKwargsItems ¶
Bases: UserDict[str, Sequence[MultiModalKwargsItem]]
A dictionary of MultiModalKwargsItem
s by modality.
Source code in vllm/multimodal/inputs.py
from_hf_inputs staticmethod
¶
from_hf_inputs(
hf_inputs: BatchFeature,
config_by_key: Mapping[str, MultiModalFieldConfig],
)
Source code in vllm/multimodal/inputs.py
from_seq staticmethod
¶
from_seq(items: Sequence[MultiModalKwargsItem])
get_data ¶
get_data(*, pin_memory: bool = False) -> MultiModalKwargs
Source code in vllm/multimodal/inputs.py
MultiModalPlaceholderMap ¶
Relates multi-modal embeddings to their corresponding placeholders.
Note: This is only used in V0.
Source code in vllm/multimodal/base.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
|
dest_len instance-attribute
¶
dest_len: int = 0
The total number of embeddings in the destination tensor.
dest_ranges instance-attribute
¶
The indices of the placeholder embeddings that will be replaced by the multimodal embeddings.
src_ranges instance-attribute
¶
The indices of the multi-modal embeddings that will replace the corresponding placeholder embeddings pointed to by dest_ranges
.
IndexMap ¶
__init__ ¶
append_items_from_seq_group ¶
append_items_from_seq_group(
positions: range,
multi_modal_items: list[_T],
multi_modal_placeholders: Sequence[PlaceholderRange],
) -> list[_T]
Adds the multi-modal items that intersect `positions
to this placeholder map and returns the intersecting items.
Source code in vllm/multimodal/base.py
extend ¶
extend(other: MultiModalPlaceholderMap)
Adds the placeholders from another MultiModalPlaceholderMap
to this instance based on the source and destination tensors being concatenated.
Source code in vllm/multimodal/base.py
from_seq_group classmethod
¶
from_seq_group(
seq_group: SequenceGroupMetadata, positions: range
) -> tuple[
MultiModalKwargs, dict[str, MultiModalPlaceholderMap]
]
Returns the multi-modal items that intersect with the portion of a prompt (seq_group
) represented by positions
, as well as a MultiModalPlaceholderMap
that relates the multi-modal embedding vectors to their corresponding placeholders.
Examples:
Prompt: |AAAA BBBB What's in these images?|
Positions: |.................................|
images = [A, B]
src_ranges = [(0, 4), (4, 8)]
dest_ranges = [(0, 4), (5, 9)]
Prompt: |AAAA BBBB What's in these images?|
Positions: | ..... |
images = [A, B]
src_ranges = [(2, 4), (4, 6)]
dest_ranges = [(0, 2), (3, 5)]
Prompt: |AAAA BBBB What's in these images?|
Positions: | ......... |
images = [B]
src_ranges = [(0, 4)]
dest_ranges = [(0, 4)]
Prompt: |AAAA BBBB What's in these images?|
Positions: | .......................|
images = []
src_ranges = []
dest_ranges = []
Source code in vllm/multimodal/base.py
index_map ¶
index_map() -> IndexMap
Finalizes the placeholder map into lists of indices that can be used to index the source and destination tensors.
Source code in vllm/multimodal/base.py
MultiModalRegistry ¶
A registry that dispatches data processing according to the model.
Source code in vllm/multimodal/registry.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
|
_processor_factories instance-attribute
¶
_processor_factories = ClassRegistry[
Module, _ProcessorFactories
]()
__init__ ¶
_create_processing_ctx ¶
_create_processing_ctx(
model_config: ModelConfig,
tokenizer: Optional[AnyTokenizer] = None,
) -> InputProcessingContext
Source code in vllm/multimodal/registry.py
_create_processing_info ¶
_create_processing_info(
model_config: ModelConfig,
*,
tokenizer: Optional[AnyTokenizer] = None,
) -> BaseProcessingInfo
Source code in vllm/multimodal/registry.py
_get_model_cls ¶
_get_model_cls(model_config: ModelConfig)
_get_processor_cache ¶
_get_processor_cache(model_config: ModelConfig)
create_processor ¶
create_processor(
model_config: ModelConfig,
*,
tokenizer: Optional[AnyTokenizer] = None,
disable_cache: Optional[bool] = None,
) -> BaseMultiModalProcessor[BaseProcessingInfo]
Create a multi-modal processor for a specific model and tokenizer.
Source code in vllm/multimodal/registry.py
enable_mm_input_cache ¶
enable_mm_input_cache(model_config: ModelConfig) -> bool
Whether the multi-modal input cache should be enabled. NOTE: This is put under MultiModalRegistry on purpose to respect text-only mode for multimodal models.
Source code in vllm/multimodal/registry.py
get_decoder_dummy_data ¶
get_decoder_dummy_data(
model_config: ModelConfig,
seq_len: int,
mm_counts: Optional[Mapping[str, int]] = None,
) -> DummyDecoderData
Create dummy data for profiling the memory usage of a model.
The model is identified by model_config
.
Source code in vllm/multimodal/registry.py
get_encoder_dummy_data ¶
get_encoder_dummy_data(
model_config: ModelConfig,
seq_len: int,
mm_counts: Optional[Mapping[str, int]] = None,
) -> DummyEncoderData
Create dummy data for profiling the memory usage of a model.
The model is identified by model_config
.
Source code in vllm/multimodal/registry.py
get_max_multimodal_tokens ¶
get_max_multimodal_tokens(model_config: ModelConfig) -> int
Get the maximum number of multi-modal tokens for profiling the memory usage of a model.
Source code in vllm/multimodal/registry.py
get_max_tokens_by_modality ¶
get_max_tokens_by_modality(
model_config: ModelConfig,
) -> Mapping[str, int]
Get the maximum number of tokens from each modality for profiling the memory usage of a model.
Source code in vllm/multimodal/registry.py
get_max_tokens_per_item_by_modality ¶
get_max_tokens_per_item_by_modality(
model_config: ModelConfig,
) -> Mapping[str, int]
Get the maximum number of tokens per data item from each modality based on underlying model configuration.
Source code in vllm/multimodal/registry.py
get_max_tokens_per_item_by_nonzero_modality ¶
get_max_tokens_per_item_by_nonzero_modality(
model_config: ModelConfig,
) -> Mapping[str, int]
Get the maximum number of tokens per data item from each modality based on underlying model configuration, excluding modalities that user explicitly disabled via limit_mm_per_prompt
.
Note
This is currently directly used only in V1 for profiling the memory usage of a model.
Source code in vllm/multimodal/registry.py
get_mm_limits_per_prompt ¶
get_mm_limits_per_prompt(
model_config: ModelConfig,
) -> Mapping[str, int]
Get the maximum number of multi-modal input instances for each modality that are allowed per prompt for a model class.
Source code in vllm/multimodal/registry.py
register_processor ¶
register_processor(
processor: MultiModalProcessorFactory[_I],
*,
info: ProcessingInfoFactory[_I],
dummy_inputs: DummyInputsBuilderFactory[_I],
)
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.
Source code in vllm/multimodal/registry.py
reset_processor_cache ¶
reset_processor_cache(model_config: ModelConfig) -> bool
Reset the multi-modal processing cache.
supports_multimodal_inputs ¶
supports_multimodal_inputs(
model_config: ModelConfig,
) -> bool
Checks if the model supports multimodal inputs. Returns True if the model is multimodal with any non-zero supported modalities, otherwise returns False, effectively running in text-only mode.