vllm.multimodal.processing.context ¶
BaseProcessingInfo ¶
Base class to provide the information necessary for data processing.
Source code in vllm/multimodal/processing/context.py
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 | |
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.
_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_default_tok_params ¶
get_default_tok_params() -> TokenizeParams
Construct the default parameters for tokenization.
Source code in vllm/multimodal/processing/context.py
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
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
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 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 | |
tokenizer instance-attribute ¶
The tokenizer used to tokenize the inputs.
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
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
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
TimingContext dataclass ¶
Helper class to record execution times during multi-modal processing.
Source code in vllm/multimodal/processing/context.py
enabled class-attribute instance-attribute ¶
enabled: bool = True
If disabled, TimingContext.record becomes a no-op.
stage_secs class-attribute instance-attribute ¶
The execution time (in seconds) for each processing stage.
record ¶
record(stage: str)
Record the execution time for a processing stage.