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.
BaseProcessingInfo
¶
Base class to provide the information necessary for data processing.
Methods:
-
get_data_parser–Constructs a parser to preprocess multi-modal data items
-
get_default_tok_params–Construct the default parameters for tokenization.
-
get_hf_processor–Subclasses can override this method to handle
-
get_mm_max_tokens_per_item–Return the maximum number of tokens per item of for each modality.
-
get_supported_mm_limits–Return the maximum supported number of items for each modality.
-
get_supported_mm_processor_kwargs–Return supported kwarg names for each HF processor kwargs scope.
-
parse_mm_data–Normalize
MultiModalDataDict -
validate_num_items–Raise
ValueErrorif the number of input items for the given modality
Attributes:
-
allow_missing_mm_embeddings(bool) –Whether pre-computed embedding tensors may be omitted.
-
allowed_mm_limits(Mapping[str, int]) –The maximum allowed number of items for each modality.
-
supported_mm_limits(Mapping[str, int | None]) –The maximum supported number of items for each modality.
-
supported_mm_processor_kwargs(dict[str, set[str]]) –Supported kwarg names for each HF processor kwargs scope.
Source code in vllm/multimodal/processing/context.py
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 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 | |
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.
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.
Source code in vllm/multimodal/processing/context.py
_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.
Source code in vllm/multimodal/processing/context.py
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.
Source code in vllm/multimodal/processing/context.py
get_default_tok_params()
¶
Construct the default parameters for tokenization.
Source code in vllm/multimodal/processing/context.py
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.
Source code in vllm/multimodal/processing/context.py
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.
Source code in vllm/multimodal/processing/context.py
get_supported_mm_processor_kwargs()
¶
Return supported kwarg names for each HF processor kwargs scope.
Source code in vllm/multimodal/processing/context.py
parse_mm_data(mm_data, *, validate=True)
¶
Normalize MultiModalDataDict
to MultiModalDataItems
before passing them to
_get_hf_mm_inputs.
Source code in vllm/multimodal/processing/context.py
validate_num_items(modality, num_items)
¶
Raise ValueError if the number of input items for the given modality
is invalid.
Source code in vllm/multimodal/processing/context.py
InputProcessingContext
dataclass
¶
Contains information about the model which may be used to modify the inputs.
Methods:
-
call_hf_processor–Call
hf_processoron the promptdata -
get_hf_config–Get the HuggingFace configuration
-
get_hf_image_processor_config–Get the HuggingFace image processor configuration of the model.
-
get_hf_processor–Get the HuggingFace processor
-
get_merged_mm_kwargs–Merge configured and request
mm_processor_kwargs. -
get_mm_config–Get the multimodal config of the model.
-
init_processor–Initialize a HuggingFace-like processor class, merging the
Attributes:
-
model_config(ModelConfig) –The configuration of the model.
-
tokenizer(TokenizerLike | None) –The tokenizer used to tokenize the inputs.
Source code in vllm/multimodal/processing/context.py
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 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 | |
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.
Source code in vllm/multimodal/processing/context.py
get_hf_config(typ=None)
¶
Get the HuggingFace configuration
(transformers.PreTrainedConfig) of the model,
additionally checking its type.
Raises:
-
TypeError–If the configuration is not of the specified type.
Source code in vllm/multimodal/processing/context.py
get_hf_image_processor_config()
¶
Get the HuggingFace image processor configuration of the model.
get_hf_processor(typ=None, /, **kwargs)
¶
Get the HuggingFace processor
(transformers.ProcessorMixin) of the model,
additionally checking its type.
Raises:
-
TypeError–If the processor is not of the specified type.
Source code in vllm/multimodal/processing/context.py
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.
Source code in vllm/multimodal/processing/context.py
get_mm_config()
¶
Get the multimodal config of the model.
Raises:
-
RuntimeError–If the model is not a multimodal model.
Source code in vllm/multimodal/processing/context.py
init_processor(typ, /, **kwargs)
¶
Initialize a HuggingFace-like processor class, merging the keyword arguments with those in the model's configuration.
Source code in vllm/multimodal/processing/context.py
TimingContext
dataclass
¶
Helper class to record execution times during multi-modal processing.
Methods:
-
record–Record the execution time for a processing stage.
Attributes:
-
enabled(bool) –If disabled,
TimingContext.recordbecomes a no-op. -
stage_secs(dict[str, float]) –The execution time (in seconds) for each processing stage.
Source code in vllm/multimodal/processing/context.py
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.
Source code in vllm/multimodal/processing/context.py
_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.
Source code in vllm/multimodal/processing/context.py
_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.
Source code in vllm/multimodal/processing/context.py
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 | |