vllm.multimodal.parse ¶
Classes:
-
DictEmbeddingItems–Base class for data items that are expressed as a dictionary of tensors.
-
EmbeddingItems–Base class for data items that are expressed as a batched embedding tensor,
-
ModalityDataItems–Represents data items for a modality in
-
MultiModalDataItems–A normalized
MultiModalDataDict -
MultiModalDataParser–Parses
MultiModalDataDict -
ProcessorBatchItems–Base class for data items that are arranged in a list.
-
VisionChunkProcessorItems–Processor items for vision chunks (unified image and video chunks).
Functions:
-
validate_embedding_ndim–Validate tensor ndim for multimodal embeddings.
Attributes:
-
EmbeddingFieldRole(TypeAlias) –What a field of a pre-computed-embedding input carries.
-
MultiModalUUIDItems(TypeAlias) –A normalized
MultiModalUUIDDict
EmbeddingFieldRole = Literal['values', 'metadata'] module-attribute ¶
What a field of a pre-computed-embedding input carries.
"values" is the embedding tensor itself; "metadata" is a key that sizes the prompt's placeholder range. The distinction is what lets one declaration serve both an ordinary request (everything present) and an EC consumer (embeddings arrive through the connector, metadata still in the request).
MultiModalUUIDItems = dict[str, Sequence[str | None]] module-attribute ¶
A normalized MultiModalUUIDDict such that each entry corresponds to a list.
DictEmbeddingItems ¶
Bases: ModalityDataItems[Mapping[str, Tensor], Mapping[str, Tensor]]
Base class for data items that are expressed as a dictionary of tensors.
Usually, the dictionary keys correspond to the outputs of HF processor.
Methods:
-
__init__–Args:
Source code in vllm/multimodal/parse.py
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 | |
__init__(data, modality, required_fields, fields_factory, optional_fields=frozenset()) ¶
Parameters:
-
(data¶Mapping[str, Tensor]) –The dictionary of tensors for this modality.
-
(modality¶str) –The modality these items belong to.
-
(required_fields¶Set[str]) –Fields
datamust contain. -
(fields_factory¶Callable[[Mapping[str, Tensor]], Mapping[str, MultiModalFieldConfig]]) –Builds the field config from the data.
-
(optional_fields¶Set[str], default:frozenset()) –Fields
datamay omit. Which fields these are is the caller's decision -- seeMultiModalDataParser.embedding_field_sets, where a deployment that receives embeddings through an EC connector makes the embeddings optional. They still need a field config, since they are used whenever they are supplied.
Source code in vllm/multimodal/parse.py
EmbeddingItems ¶
Bases: ModalityDataItems[Tensor | list[Tensor], Tensor]
Base class for data items that are expressed as a batched embedding tensor, or a list of embedding tensors (one per item).
Source code in vllm/multimodal/parse.py
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 | |
_unwrap(item) ¶
_validate_hidden_size(expected_hidden_size) ¶
Validate that embedding hidden dimension matches expected size.
This validates hidden dimensions to prevent vulnerabilities: Embeddings with correct ndim but wrong hidden dimension could bypass initial checks and cause crashes during model inference when dimensions don't match.
Source code in vllm/multimodal/parse.py
_validate_ndim() ¶
Validate that embedding tensors have correct ndim (2D or 3D).
Source code in vllm/multimodal/parse.py
ModalityDataItems ¶
Represents data items for a modality in MultiModalDataItems.
Methods:
-
get–Get a data item by its index.
-
get_all–Get all data items.
-
get_count–Get the number of data items.
-
get_passthrough_data–Get the data to pass directly to the model.
-
get_processor_data–Get the data to pass to the HF processor.
Source code in vllm/multimodal/parse.py
MultiModalDataItems ¶
Bases: UserDict[str, ModalityDataItems[Any, Any]]
A normalized MultiModalDataDict such that each entry corresponds to a list.
Methods:
-
get_all_counts–Get the number of items belonging to each modality.
-
get_count–Get the number of data items belonging to a modality.
-
get_items–Get the data items belonging to a modality,
-
select–Construct a new
MultiModalDataItemsinstance containing only the
Source code in vllm/multimodal/parse.py
get_all_counts() ¶
get_count(modality, *, strict=True) ¶
Get the number of data items belonging to a modality.
If strict=False, return 0 instead of raising KeyError even if the modality is not found.
Source code in vllm/multimodal/parse.py
get_items(modality, typ) ¶
Get the data items belonging to a modality, requiring that they belong to a certain type.
Source code in vllm/multimodal/parse.py
select(modalities) ¶
Construct a new MultiModalDataItems instance containing only the selected modalities.
MultiModalDataParser ¶
Parses MultiModalDataDict into MultiModalDataItems.
Parameters:
-
(target_sr¶float, default:None) –Enables automatic resampling of audio items to the model's expected sampling rate.
-
(target_channels¶int, default:None) –Target number of audio channels. If provided, normalizes audio to this many channels (e.g., 1 for mono). If None, audio channels are passed through unchanged.
-
(expected_hidden_size¶int, default:None) –Expected hidden dimension for embedding inputs. If provided, validates that user-supplied embeddings have the correct hidden size to prevent crashes during model inference.
-
(allow_missing_mm_embeddings¶bool, default:False) –Whether pre-computed embedding tensors may be absent from the request on a disaggregated consumer. Derived by
BaseProcessingInfo.allow_missing_mm_embeddings.
Methods:
-
embedding_field_sets–modality's (required, optional) fields for this deployment. -
placeholder_metadata_fields–The keys that size
modality's placeholder range.
Attributes:
-
embedding_fields(Mapping[str, Mapping[str, EmbeddingFieldRole]]) –Per-modality field roles for pre-computed-embedding inputs.
Source code in vllm/multimodal/parse.py
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 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 | |
embedding_fields = {} class-attribute instance-attribute ¶
Per-modality field roles for pre-computed-embedding inputs.
Declared here rather than inside _parse_*_data so an EC producer can read it too: on a producer the request carries real media, so the branch that builds DictEmbeddingItems never runs, yet the producer still has to know which processed keys to publish. One declaration, both sides, no drift.
A modality absent from this mapping can only be sent whole in the request.
_parse_vision_chunk_data(data) ¶
Parse vision chunk data (unified image and video chunks).
Source code in vllm/multimodal/parse.py
embedding_field_sets(modality) ¶
modality's (required, optional) fields for this deployment.
Resolves the static roles in embedding_fields against where the embeddings actually come from: on an EC consumer they arrive through the connector, so the request may omit them; anywhere else a request that claims to carry pre-computed embeddings has to actually carry them.
Source code in vllm/multimodal/parse.py
placeholder_metadata_fields(modality) classmethod ¶
The keys that size modality's placeholder range.
What an EC producer publishes alongside the embedding, and what a consumer keeps requiring once the embedding itself is gone.
Source code in vllm/multimodal/parse.py
ProcessorBatchItems ¶
Bases: ModalityDataItems[Sequence[_T], _T]
Base class for data items that are arranged in a list.
Source code in vllm/multimodal/parse.py
VisionChunkProcessorItems ¶
Bases: ProcessorBatchItems[Any]
Processor items for vision chunks (unified image and video chunks).
Source code in vllm/multimodal/parse.py
validate_embedding_ndim(tensor, modality, index=None) ¶
Validate tensor ndim for multimodal embeddings.
Single embeddings should be 2D (seq_len, hidden_size). Batched embeddings should be 3D (batch, seq_len, hidden_size).
Parameters:
-
(tensor¶Tensor) –The tensor to validate.
-
(modality¶str) –The modality name for error messages (e.g., "image", "audio").
-
(index¶int | None, default:None) –Optional index for list items, included in error messages.