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
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 | |
__init__ ¶
__init__(ctx: InputProcessingContext) -> None
get_allowed_mm_limits ¶
Return the maximum allowed number of items for each modality.
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
InputProcessingContext dataclass ¶
Contains information about the model which may be used to modify the inputs.
Source code in vllm/multimodal/processing/context.py
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 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 | |
_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).
prompt_update_time class-attribute instance-attribute ¶
prompt_update_time: float = 0.0
Time spent applying prompt updates and finding placeholders (seconds).
total_time class-attribute instance-attribute ¶
total_time: float = 0.0
Total processing time (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,
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 timing stats from the context associated with the engine client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
engine_client | Any | The engine client that has input_processor. | required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, float]] | A dictionary mapping request_id to stats dict. |
Source code in vllm/multimodal/processing/context.py
set_request_id ¶
Context manager to set the request_id for the current context.
Source code in vllm/multimodal/processing/context.py
timed_operation ¶
timed_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 |