vllm.multimodal.processing.context ¶
_request_id_context module-attribute ¶
_request_id_context: ContextVar[str | None] = ContextVar(
"_request_id_context", default=None
)
BaseProcessingInfo ¶
Base class to provide the information necessary for data processing.
Source code in vllm/multimodal/processing/context.py
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 | |
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.
__init__ ¶
__init__(ctx: InputProcessingContext) -> None
_get_expected_hidden_size ¶
_get_expected_hidden_size() -> int | None
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
get_data_parser ¶
get_data_parser() -> MultiModalDataParser
Constructs a parser to preprocess multi-modal data items before passing them to _get_hf_mm_data.
You can support additional modalities by creating a subclass of MultiModalDataParser that has additional subparsers.
Source code in vllm/multimodal/processing/context.py
get_hf_config ¶
get_hf_processor ¶
get_hf_processor(**kwargs: object) -> ProcessorMixin
Subclasses can override this method to handle specific kwargs from model config or user inputs.
get_mm_max_tokens_per_item ¶
get_mm_max_tokens_per_item(
seq_len: int, mm_counts: Mapping[str, int]
) -> Mapping[str, int] | None
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 abstractmethod ¶
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_tokenizer ¶
get_tokenizer() -> TokenizerLike
parse_mm_data ¶
parse_mm_data(
mm_data: MultiModalDataDict, *, validate: bool = True
) -> MultiModalDataItems
Normalize MultiModalDataDict to MultiModalDataItems before passing them to _get_hf_mm_data.
Source code in vllm/multimodal/processing/context.py
validate_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.
Source code in vllm/multimodal/processing/context.py
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 448 449 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 | |
_timing_stats_registry_lock class-attribute instance-attribute ¶
Lock for thread-safe access to timing_stats_registry.
observability_config class-attribute instance-attribute ¶
observability_config: ObservabilityConfig | None = field(
default=None, compare=False, repr=False
)
Configuration for observability features.
timing_stats_registry class-attribute instance-attribute ¶
timing_stats_registry: dict[
str, MultiModalProcessorTimingStats
] = field(default_factory=dict, compare=False, repr=False)
Registry for storing timing stats keyed by request_id.
tokenizer instance-attribute ¶
tokenizer: TokenizerLike | None
The tokenizer used to tokenize the inputs.
__init__ ¶
__init__(
model_config: ModelConfig,
tokenizer: TokenizerLike | None,
observability_config: ObservabilityConfig | None = None,
timing_stats_registry: dict[
str, MultiModalProcessorTimingStats
] = dict(),
_timing_stats_registry_lock: Lock = Lock(),
) -> None
_postprocess_output ¶
Source code in vllm/multimodal/processing/context.py
call_hf_processor ¶
call_hf_processor(
hf_processor: ProcessorMixin,
data: Mapping[str, object],
kwargs: Mapping[str, object] = {},
*,
num_tries: int = 1,
max_tries: int = 5,
) -> BatchFeature | JSONTree
Call hf_processor on the prompt data (text, image, audio...) with configurable options kwargs.
Source code in vllm/multimodal/processing/context.py
clear_timing_stats_registry ¶
clear_timing_stats_registry() -> int
Clear all stats from the registry. Returns the number of stats cleared.
Source code in vllm/multimodal/processing/context.py
create_timing_stats ¶
create_timing_stats(
request_id: str,
) -> MultiModalProcessorTimingStats
Create and store timing stats in the registry for a request.
This should be called at the start of processing for a request. The stats object is created immediately and stored in the registry.
Source code in vllm/multimodal/processing/context.py
get_all_timing_stats ¶
Get all timing stats as a dictionary for API endpoints.
Source code in vllm/multimodal/processing/context.py
get_hf_config ¶
Get the HuggingFace configuration (transformers.PretrainedConfig) of the model, additionally checking its type.
Raises:
| Type | Description |
|---|---|
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 ¶
get_hf_processor(**kwargs: object) -> ProcessorMixin
get_hf_processor(
typ: type[Any] | tuple[type[Any], ...] | None = None,
/,
**kwargs: object,
) -> Any
Get the HuggingFace processor (transformers.ProcessorMixin) of the model, additionally checking its type.
Raises:
| Type | Description |
|---|---|
TypeError | If the processor is not of the specified type. |
Source code in vllm/multimodal/processing/context.py
get_mm_config ¶
Get the multimodal config of the model.
Raises:
| Type | Description |
|---|---|
RuntimeError | If the model is not a multimodal model. |
Source code in vllm/multimodal/processing/context.py
get_timing_stats ¶
get_timing_stats(
request_id: str,
) -> MultiModalProcessorTimingStats | None
Get timing stats for a request.
Source code in vllm/multimodal/processing/context.py
get_tokenizer ¶
get_tokenizer() -> TokenizerLike
init_processor ¶
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
MultiModalProcessorTimingStats dataclass ¶
Per-request timing statistics for multimodal processor stages.
Source code in vllm/multimodal/processing/context.py
cache_lookup_time class-attribute instance-attribute ¶
cache_lookup_time: float = 0.0
Time spent in cache lookups and merges (seconds).
hashing_time class-attribute instance-attribute ¶
hashing_time: float = 0.0
Time spent computing multimodal item hashes (seconds).
hf_processor_time class-attribute instance-attribute ¶
hf_processor_time: float = 0.0
Time spent in HuggingFace processor calls (seconds).
preprocessor_total_time class-attribute instance-attribute ¶
preprocessor_total_time: float = 0.0
Total preprocessing time (seconds).
prompt_update_time class-attribute instance-attribute ¶
prompt_update_time: float = 0.0
Time spent applying prompt updates and finding placeholders (seconds).
__init__ ¶
__init__(
hf_processor_time: float = 0.0,
hashing_time: float = 0.0,
cache_lookup_time: float = 0.0,
prompt_update_time: float = 0.0,
preprocessor_total_time: float = 0.0,
) -> None
to_dict ¶
Convert stats to a dictionary for JSON serialization.
Source code in vllm/multimodal/processing/context.py
get_timing_stats_from_engine_client ¶
Get all multimodal timing stats from the engine client.
Collects both preprocessing stats (HF processor, hashing, cache lookup, prompt update) and encoder forward pass timing, merged by request_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine_client | Any | The engine client (has input_processor and workers). | required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, float]] | Dictionary mapping request_id to merged stats dict containing |
dict[str, dict[str, float]] | both preprocessing and encoder timing metrics. |
Example
{ 'request-123': { 'hf_processor_time': 0.45, 'hashing_time': 0.02, 'cache_lookup_time': 0.01, 'prompt_update_time': 0.03, 'preprocessor_total_time': 0.51, 'encoder_forward_time': 0.23, 'num_encoder_calls': 1 } }
Source code in vllm/multimodal/processing/context.py
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 | |
set_request_id ¶
Context manager to set the request_id for the current context.
Source code in vllm/multimodal/processing/context.py
timed_preprocessor_operation ¶
timed_preprocessor_operation(
ctx: InputProcessingContext, stage_name: str
)
Context manager to time an operation using the context's timing stats.
The request_id is automatically retrieved from the context variable, so it doesn't need to be passed as a parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx | InputProcessingContext | The InputProcessingContext containing the timing stats registry. | required |
stage_name | str | Name of the stage being timed. | required |