vllm.multimodal.media
¶
Modules:
Classes:
-
AudioEmbeddingMediaIO–Configuration values can be user-provided either by --media-io-kwargs or
-
AudioMediaIO–Configuration values can be user-provided either by --media-io-kwargs or
-
DecodeSpec–Canonical snapshot of the decode settings included in a media key.
-
ImageEmbeddingMediaIO–Image embedding MediaIO implementation.
-
ImageMediaIO–Configuration values can be user-provided either by --media-io-kwargs or
-
MediaConnector–Fetches media URLs down to their encoded bytes.
-
MediaIO–Configuration values can be user-provided either by --media-io-kwargs or
-
MediaRef–A reference to one piece of fetched media.
-
VideoMediaIO–Configuration values can be user-provided either by --media-io-kwargs or
AudioEmbeddingMediaIO
¶
Configuration values can be user-provided either by --media-io-kwargs or by the runtime API field "media_io_kwargs". Ensure proper validation and error handling.
Source code in vllm/multimodal/media/audio.py
AudioMediaIO
¶
Bases: MediaIO[tuple[NDArray, float]]
Configuration values can be user-provided either by --media-io-kwargs or by the runtime API field "media_io_kwargs". Ensure proper validation and error handling.
Source code in vllm/multimodal/media/audio.py
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 | |
DecodeSpec
dataclass
¶
Canonical snapshot of the decode settings included in a media key.
Methods:
-
canonical_bytes–Return the canonical JSON bytes used for key derivation.
-
extend–Return a copy with
settingsmerged over the current ones.
Attributes:
Source code in vllm/multimodal/media/base.py
ImageEmbeddingMediaIO
¶
Image embedding MediaIO implementation.
Configuration values can be user-provided either by --media-io-kwargs or by the runtime API field "media_io_kwargs". Ensure proper validation and error handling.
Source code in vllm/multimodal/media/image.py
ImageMediaIO
¶
Bases: MediaIO[Image]
Configuration values can be user-provided either by --media-io-kwargs or by the runtime API field "media_io_kwargs". Ensure proper validation and error handling.
Methods:
-
load_bytes_ref–Eager header parse + lazy pixel decode.
-
open_header–Open only the image header, leaving the pixels undecoded.
Source code in vllm/multimodal/media/image.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 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 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
_convert_image_mode(image)
¶
Convert image mode with custom background color.
Source code in vllm/multimodal/media/image.py
_decode_pixels(image)
¶
Rasterize a header-opened image, then normalize and convert it.
Source code in vllm/multimodal/media/image.py
_exif_key(header_image)
¶
The EXIF ImageID cache key of a header-opened image, if it has one.
Key derivation must never rasterize pixels: PngImageFile.getexif()
calls .load() to scan for a trailing eXIf chunk when info has
none, and on Pillow >= 12 getexif() loads unconditionally. Per the
PNG spec eXIf must precede IDAT, so compliant PNGs carry their EXIF in
info at open time; a non-compliant trailing-eXIf PNG with an
ImageID is not recognized here and keys off its bytes instead.
Source code in vllm/multimodal/media/image.py
load_bytes_ref(data)
¶
Eager header parse + lazy pixel decode.
The header is parsed eagerly so oversized images still fail at fetch
time and so the cache key can carry the EXIF ImageID without
decoding. Unparsable headers and pixel decoding are deferred to first
access, where decode errors surface.
Source code in vllm/multimodal/media/image.py
open_header(data)
¶
Open only the image header, leaving the pixels undecoded.
Mode, size and EXIF are readable from the header alone, so this is also where the max-pixels guard and the cache key's EXIF probe run.
Source code in vllm/multimodal/media/image.py
MediaConnector
¶
Fetches media URLs down to their encoded bytes.
Transport only: scheme dispatch (data: / http(s): / file:), the
domain allow-list, the encoded-size cap, the on-disk download cache, the
redirect policy and error normalization. How bytes decode -- and therefore
what identifies the resulting item in the processor cache -- is decided by
the caller-supplied MediaIO, which
the multi-modal processor's info resolves from the model config.
Methods:
-
__init__–Args:
-
fetch_audio–Fetch audio and pair it with a caller-supplied decoder.
-
fetch_audio_async–Asynchronously fetch audio and pair it with a caller-supplied decoder.
-
fetch_audio_embedding–Load audio embedding from a URL.
-
fetch_audio_embedding_async–Asynchronously load audio embedding from a URL.
-
fetch_image–Fetch an image and pair it with a caller-supplied decoder.
-
fetch_image_async–Asynchronously fetch an image and pair it with a supplied decoder.
-
fetch_image_embedding–Load image embedding from a URL.
-
fetch_image_embedding_async–Asynchronously load image embedding from a URL.
-
fetch_video–Fetch a video and pair it with a caller-supplied decoder.
-
fetch_video_and_audio–Fetch
video_urlonce and decode it as both video and audio. -
fetch_video_and_audio_async–Asynchronous
fetch_video_and_audio. -
fetch_video_async–Asynchronously fetch a video and pair it with a supplied decoder.
-
fetch_video_embedding–Load video embedding from a URL.
-
fetch_video_embedding_async–Asynchronously load video embedding from a URL.
-
load_from_url–Fetch
urland pair it with a caller-supplied decoder. -
load_from_url_async–Asynchronously fetch
urland pair it with a caller-supplied decoder.
Source code in vllm/multimodal/media/connector.py
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 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 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 | |
__init__(connection=global_http_connection, *, allowed_local_media_path='', allowed_media_domains=None)
¶
Args: connection: HTTP connection client to download media contents. allowed_local_media_path: A local directory to load media files from. allowed_media_domains: If set, only media URLs that belong to this domain can be used for multi-modal inputs.
Source code in vllm/multimodal/media/connector.py
_fetch_url_bytes(url, url_spec, *, max_bytes=None, fetch_timeout=None)
¶
Download an HTTP(S) URL down to its encoded bytes.
Source code in vllm/multimodal/media/connector.py
_fetch_url_bytes_async(url, url_spec, *, max_bytes=None, fetch_timeout=None)
async
¶
Asynchronous _fetch_url_bytes.
Source code in vllm/multimodal/media/connector.py
_get_cached_bytes(url)
¶
Return cached bytes for a URL, or None if not cached/expired.
Source code in vllm/multimodal/media/connector.py
_load_refs(url, media_ios, *, fetch_timeout=None)
¶
Fetch url once and pair the payload with each of media_ios.
One payload can legitimately feed several decoders -- reading the audio track out of a video file needs the same bytes as its frames -- and fetching once per decoder would repeat the download.
Source code in vllm/multimodal/media/connector.py
_load_refs_async(url, media_ios, *, fetch_timeout=None)
async
¶
Asynchronous _load_refs.
Source code in vllm/multimodal/media/connector.py
_maybe_evict(exclude=None)
¶
Evict expired entries first, then LRU until under size limit.
Source code in vllm/multimodal/media/connector.py
_put_cached_bytes(url, data)
¶
Store downloaded bytes and evict if over budget.
Source code in vllm/multimodal/media/connector.py
_resolve_allowed_file(url_spec)
¶
Resolve a file: URL, checking it against the allowed media path.
Source code in vllm/multimodal/media/connector.py
fetch_audio(audio_url, media_io)
¶
Fetch audio and pair it with a caller-supplied decoder.
Returns a lazy handle: decoding happens on first access (inside the multi-modal processor), so decode errors surface there rather than at the fetch site.
Source code in vllm/multimodal/media/connector.py
fetch_audio_async(audio_url, media_io)
async
¶
Asynchronously fetch audio and pair it with a caller-supplied decoder.
Source code in vllm/multimodal/media/connector.py
fetch_audio_embedding(data)
¶
Load audio embedding from a URL.
fetch_audio_embedding_async(data)
async
¶
Asynchronously load audio embedding from a URL.
Source code in vllm/multimodal/media/connector.py
fetch_image(image_url, media_io)
¶
Fetch an image and pair it with a caller-supplied decoder.
Returns a lazy handle: decoding happens on first access (inside the multi-modal processor), so decode errors surface there rather than at the fetch site.
Source code in vllm/multimodal/media/connector.py
fetch_image_async(image_url, media_io)
async
¶
Asynchronously fetch an image and pair it with a supplied decoder.
Source code in vllm/multimodal/media/connector.py
fetch_image_embedding(data)
¶
Load image embedding from a URL.
fetch_image_embedding_async(data)
async
¶
Asynchronously load image embedding from a URL.
Source code in vllm/multimodal/media/connector.py
fetch_video(video_url, media_io)
¶
Fetch a video and pair it with a caller-supplied decoder.
Returns a lazy handle: decoding happens on first access (inside the multi-modal processor), so decode errors surface there rather than at the fetch site.
Source code in vllm/multimodal/media/connector.py
fetch_video_and_audio(video_url, video_io, audio_io)
¶
Fetch video_url once and decode it as both video and audio.
use_audio_in_video reads the audio track out of the video payload, so
both refs are built from one download instead of two.
Source code in vllm/multimodal/media/connector.py
fetch_video_and_audio_async(video_url, video_io, audio_io)
async
¶
Asynchronous fetch_video_and_audio.
Source code in vllm/multimodal/media/connector.py
fetch_video_async(video_url, media_io)
async
¶
Asynchronously fetch a video and pair it with a supplied decoder.
Source code in vllm/multimodal/media/connector.py
fetch_video_embedding(data)
¶
Load video embedding from a URL.
fetch_video_embedding_async(data)
async
¶
Asynchronously load video embedding from a URL.
Source code in vllm/multimodal/media/connector.py
load_from_url(url, media_io, *, fetch_timeout=None)
¶
Fetch url and pair it with a caller-supplied decoder.
Returns a lazy handle: decoding happens on first access (inside the multi-modal processor), so decode errors surface there rather than at the fetch site.
Source code in vllm/multimodal/media/connector.py
load_from_url_async(url, media_io, *, fetch_timeout=None)
async
¶
Asynchronously fetch url and pair it with a caller-supplied decoder.
Source code in vllm/multimodal/media/connector.py
MediaIO
¶
Configuration values can be user-provided either by --media-io-kwargs or by the runtime API field "media_io_kwargs". Ensure proper validation and error handling.
Methods:
-
get_decode_spec–Return the decode configuration to fold into a ref's cache key.
-
get_max_bytes–Return the maximum encoded payload size accepted by this media IO.
-
load_base64–List of media types:
-
load_base64_ref–Ref variant of
load_base64; the base64 decoding stays eager. -
load_bytes_ref–Return a reference that decodes
dataon first access. -
load_file_ref–Ref variant of
load_file; the file read stays eager. -
merge_kwargs–Merge config-level kwargs and request-level kwargs.
Source code in vllm/multimodal/media/base.py
get_decode_spec()
¶
Return the decode configuration to fold into a ref's cache key.
None when this IO has no settings that affect the decoded media.
get_max_bytes()
¶
load_base64(media_type, data)
abstractmethod
¶
List of media types: https://www.iana.org/assignments/media-types/media-types.xhtml
load_base64_ref(media_type, data)
¶
Ref variant of load_base64; the base64 decoding stays eager.
load_bytes_ref(data)
¶
Return a reference that decodes data on first access.
Decoding errors surface at the use site (e.g. inside the multi-modal processor) instead of at the fetch site.
Source code in vllm/multimodal/media/base.py
load_file_ref(filepath)
¶
merge_kwargs(default_kwargs, runtime_kwargs)
classmethod
¶
Merge config-level kwargs and request-level kwargs.
By default this performs a shallow merge where runtime kwargs override keys in default kwargs. Subclasses may override to apply modality- specific behavior.
Source code in vllm/multimodal/media/base.py
MediaRef
¶
Bases: Generic[_T]
A reference to one piece of fetched media.
This is the single value type for media that vLLM fetched and has not (yet) decoded. It carries three things:
key: the cache identity, derived from the encoded bytes andspecwithout decoding, so hashing never pays a decode cost.spec: the decode configuration that parameterized or mutated the media, already folded intokey.decode(): the decoded media, produced at most once and thread-safely.
Methods:
-
decode–Return the decoded media, decoding at most once.
-
fork–Borrow this ref through an independently releasable wrapper.
-
map–Return a ref decoding to
transform(self.decode()). -
release–Drop this ref's encoded bytes and decode closure.
Attributes:
Source code in vllm/multimodal/media/base.py
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 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 | |
data
property
¶
The encoded bytes; b"" once release() has run.
decode()
¶
Return the decoded media, decoding at most once.
Thread-safe. Exceptions from the decoder propagate unchanged; wrapping them is the caller's job.
Raises:
-
RuntimeError–If the ref was released before being decoded.
Source code in vllm/multimodal/media/base.py
fork()
¶
map(transform, **settings)
¶
Return a ref decoding to transform(self.decode()).
Shares this ref's bytes (no copy) so the parse layer can stack
transforms (e.g. audio resampling) onto the decode step. settings
extend the spec -- and therefore the key -- so the transform's own
parameters stay part of the cache identity. The new key is derived
from this ref's key rather than by re-digesting the payload.
With no settings, the key is preserved: use this only for transforms that preserve cache identity. Output-changing transforms must supply settings identifying the transform and every output-affecting parameter.
Source code in vllm/multimodal/media/base.py
release()
¶
Drop this ref's encoded bytes and decode closure.
Call once hashing is done and the item is either decoded or known to be a cache hit, after any in-flight decode has finished. Decoded media remains readable; an undecoded ref cannot decode after release.
Other owners can retain the payload: a mapped ref does not release a separately retained parent, and decoded media may contain encoded bytes.
Source code in vllm/multimodal/media/base.py
VideoMediaIO
¶
Bases: MediaIO[tuple[DecodedFrames, dict[str, Any]]]
Configuration values can be user-provided either by --media-io-kwargs or by the runtime API field "media_io_kwargs". Ensure proper validation and error handling.
Use --media-io-kwargs '{"video": {"backend": "torchcodec", "device": "cuda"}}' to decode with NVDEC and keep frames on the GPU, which pairs with a device-side multi-modal processor (--mm-processor-device, EPD encode-only instances).
Source code in vllm/multimodal/media/video.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 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 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 | |
_prepare_jpeg_sequence(data)
¶
Split a base64 jpeg frame sequence and validate its arguments.
Splitting and argument validation (num_frames/frames_indices/ total_num_frames/duration) run eagerly; the per-frame decode and np.stack are deferred into the returned callable.